Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 55 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 56 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 57 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 58 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 60 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 62 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 63 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 64 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 65 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 66 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 75 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 76 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 77 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 79 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 80 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 81 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 82 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 83 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 84 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 85 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 86 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 87 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 88 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 91 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | if (err >= -1000) |
| 94 | return err; |
| 95 | switch (err) { |
| 96 | case -NFS4ERR_RESOURCE: |
| 97 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 98 | case -NFS4ERR_WRONGSEC: |
| 99 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 100 | case -NFS4ERR_BADOWNER: |
| 101 | case -NFS4ERR_BADNAME: |
| 102 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 103 | case -NFS4ERR_SHARE_DENIED: |
| 104 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 105 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 106 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 107 | case -NFS4ERR_ACCESS: |
| 108 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 111 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 114 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * This is our standard bitmap for GETATTR requests. |
| 119 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 120 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | FATTR4_WORD0_TYPE |
| 122 | | FATTR4_WORD0_CHANGE |
| 123 | | FATTR4_WORD0_SIZE |
| 124 | | FATTR4_WORD0_FSID |
| 125 | | FATTR4_WORD0_FILEID, |
| 126 | FATTR4_WORD1_MODE |
| 127 | | FATTR4_WORD1_NUMLINKS |
| 128 | | FATTR4_WORD1_OWNER |
| 129 | | FATTR4_WORD1_OWNER_GROUP |
| 130 | | FATTR4_WORD1_RAWDEV |
| 131 | | FATTR4_WORD1_SPACE_USED |
| 132 | | FATTR4_WORD1_TIME_ACCESS |
| 133 | | FATTR4_WORD1_TIME_METADATA |
| 134 | | FATTR4_WORD1_TIME_MODIFY |
| 135 | }; |
| 136 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 137 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 138 | FATTR4_WORD0_TYPE |
| 139 | | FATTR4_WORD0_CHANGE |
| 140 | | FATTR4_WORD0_SIZE |
| 141 | | FATTR4_WORD0_FSID |
| 142 | | FATTR4_WORD0_FILEID, |
| 143 | FATTR4_WORD1_MODE |
| 144 | | FATTR4_WORD1_NUMLINKS |
| 145 | | FATTR4_WORD1_OWNER |
| 146 | | FATTR4_WORD1_OWNER_GROUP |
| 147 | | FATTR4_WORD1_RAWDEV |
| 148 | | FATTR4_WORD1_SPACE_USED |
| 149 | | FATTR4_WORD1_TIME_ACCESS |
| 150 | | FATTR4_WORD1_TIME_METADATA |
| 151 | | FATTR4_WORD1_TIME_MODIFY, |
| 152 | FATTR4_WORD2_MDSTHRESHOLD |
| 153 | }; |
| 154 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 155 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 156 | FATTR4_WORD0_TYPE |
| 157 | | FATTR4_WORD0_CHANGE |
| 158 | | FATTR4_WORD0_FILEID, |
| 159 | }; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | const u32 nfs4_statfs_bitmap[2] = { |
| 162 | FATTR4_WORD0_FILES_AVAIL |
| 163 | | FATTR4_WORD0_FILES_FREE |
| 164 | | FATTR4_WORD0_FILES_TOTAL, |
| 165 | FATTR4_WORD1_SPACE_AVAIL |
| 166 | | FATTR4_WORD1_SPACE_FREE |
| 167 | | FATTR4_WORD1_SPACE_TOTAL |
| 168 | }; |
| 169 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 170 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | FATTR4_WORD0_MAXLINK |
| 172 | | FATTR4_WORD0_MAXNAME, |
| 173 | 0 |
| 174 | }; |
| 175 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 176 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | | FATTR4_WORD0_MAXREAD |
| 178 | | FATTR4_WORD0_MAXWRITE |
| 179 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 180 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 181 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 182 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 185 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID |
| 191 | | FATTR4_WORD0_FS_LOCATIONS, |
| 192 | FATTR4_WORD1_MODE |
| 193 | | FATTR4_WORD1_NUMLINKS |
| 194 | | FATTR4_WORD1_OWNER |
| 195 | | FATTR4_WORD1_OWNER_GROUP |
| 196 | | FATTR4_WORD1_RAWDEV |
| 197 | | FATTR4_WORD1_SPACE_USED |
| 198 | | FATTR4_WORD1_TIME_ACCESS |
| 199 | | FATTR4_WORD1_TIME_METADATA |
| 200 | | FATTR4_WORD1_TIME_MODIFY |
| 201 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 202 | }; |
| 203 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 204 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | struct nfs4_readdir_arg *readdir) |
| 206 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 207 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 210 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | readdir->cookie = 0; |
| 216 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 217 | if (cookie == 2) |
| 218 | return; |
| 219 | |
| 220 | /* |
| 221 | * NFSv4 servers do not return entries for '.' and '..' |
| 222 | * Therefore, we fake these entries here. We let '.' |
| 223 | * have cookie 0 and '..' have cookie 1. Note that |
| 224 | * when talking to the server, we always send cookie 0 |
| 225 | * instead of 1 or 2. |
| 226 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 227 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | if (cookie == 0) { |
| 230 | *p++ = xdr_one; /* next */ |
| 231 | *p++ = xdr_zero; /* cookie, first word */ |
| 232 | *p++ = xdr_one; /* cookie, second word */ |
| 233 | *p++ = xdr_one; /* entry len */ |
| 234 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 235 | p++; |
| 236 | *p++ = xdr_one; /* bitmap length */ |
| 237 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 238 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 239 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | *p++ = xdr_one; /* next */ |
| 243 | *p++ = xdr_zero; /* cookie, first word */ |
| 244 | *p++ = xdr_two; /* cookie, second word */ |
| 245 | *p++ = xdr_two; /* entry len */ |
| 246 | memcpy(p, "..\0\0", 4); /* entry */ |
| 247 | p++; |
| 248 | *p++ = xdr_one; /* bitmap length */ |
| 249 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 250 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 251 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | readdir->pgbase = (char *)p - (char *)start; |
| 254 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 255 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 258 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 259 | { |
| 260 | int res; |
| 261 | |
| 262 | might_sleep(); |
| 263 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 264 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 265 | nfs_wait_bit_killable, TASK_KILLABLE); |
Chuck Lever | 46a87b8 | 2012-07-11 16:30:41 -0400 | [diff] [blame] | 266 | if (res) |
| 267 | return res; |
| 268 | |
| 269 | if (clp->cl_cons_state < 0) |
| 270 | return clp->cl_cons_state; |
| 271 | return 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 275 | { |
| 276 | int res = 0; |
| 277 | |
| 278 | might_sleep(); |
| 279 | |
| 280 | if (*timeout <= 0) |
| 281 | *timeout = NFS4_POLL_RETRY_MIN; |
| 282 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 283 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 284 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 285 | if (fatal_signal_pending(current)) |
| 286 | res = -ERESTARTSYS; |
| 287 | *timeout <<= 1; |
| 288 | return res; |
| 289 | } |
| 290 | |
| 291 | /* This is the error handling routine for processes that are allowed |
| 292 | * to sleep. |
| 293 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 294 | 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] | 295 | { |
| 296 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 297 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 298 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 299 | int ret = errorcode; |
| 300 | |
| 301 | exception->retry = 0; |
| 302 | switch(errorcode) { |
| 303 | case 0: |
| 304 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 305 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 306 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 307 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 308 | exception->retry = 1; |
| 309 | return 0; |
| 310 | } |
| 311 | if (state == NULL) |
| 312 | break; |
| 313 | nfs4_schedule_stateid_recovery(server, state); |
| 314 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 315 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 316 | case -NFS4ERR_ADMIN_REVOKED: |
| 317 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 318 | if (state == NULL) |
| 319 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 320 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 321 | nfs4_schedule_stateid_recovery(server, state); |
| 322 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 323 | case -NFS4ERR_EXPIRED: |
| 324 | if (state != NULL) |
| 325 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 327 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 328 | nfs4_schedule_lease_recovery(clp); |
| 329 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 330 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 331 | case -NFS4ERR_BADSESSION: |
| 332 | case -NFS4ERR_BADSLOT: |
| 333 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 334 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 335 | case -NFS4ERR_DEADSESSION: |
| 336 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 337 | case -NFS4ERR_SEQ_MISORDERED: |
| 338 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 339 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 340 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 341 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 342 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 343 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 344 | if (exception->timeout > HZ) { |
| 345 | /* We have retried a decent amount, time to |
| 346 | * fail |
| 347 | */ |
| 348 | ret = -EBUSY; |
| 349 | break; |
| 350 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 351 | case -NFS4ERR_GRACE: |
| 352 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 353 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 354 | ret = nfs4_delay(server->client, &exception->timeout); |
| 355 | if (ret != 0) |
| 356 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 357 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 358 | case -NFS4ERR_OLD_STATEID: |
| 359 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 360 | break; |
| 361 | case -NFS4ERR_BADOWNER: |
| 362 | /* The following works around a Linux server bug! */ |
| 363 | case -NFS4ERR_BADNAME: |
| 364 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 365 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 366 | exception->retry = 1; |
| 367 | printk(KERN_WARNING "NFS: v4 server %s " |
| 368 | "does not accept raw " |
| 369 | "uid/gids. " |
| 370 | "Reenabling the idmapper.\n", |
| 371 | server->nfs_client->cl_hostname); |
| 372 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 373 | } |
| 374 | /* We failed to handle the error */ |
| 375 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 376 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 377 | ret = nfs4_wait_clnt_recover(clp); |
| 378 | if (ret == 0) |
| 379 | exception->retry = 1; |
| 380 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 384 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | spin_lock(&clp->cl_lock); |
| 387 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 388 | clp->cl_last_renewal = timestamp; |
| 389 | spin_unlock(&clp->cl_lock); |
| 390 | } |
| 391 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 392 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 393 | { |
| 394 | do_renew_lease(server->nfs_client, timestamp); |
| 395 | } |
| 396 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 397 | #if defined(CONFIG_NFS_V4_1) |
| 398 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 399 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 400 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 401 | * |
| 402 | * freeing a slot is trivially done by clearing its respective bit |
| 403 | * in the bitmap. |
| 404 | * If the freed slotid equals highest_used_slotid we want to update it |
| 405 | * so that the server would be able to size down the slot table if needed, |
| 406 | * otherwise we know that the highest_used_slotid is still in use. |
| 407 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 408 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 409 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 410 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 411 | * |
| 412 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 413 | */ |
| 414 | static void |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 415 | nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 416 | { |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 417 | u32 slotid = slot->slot_nr; |
| 418 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 419 | /* clear used bit in bitmap */ |
| 420 | __clear_bit(slotid, tbl->used_slots); |
| 421 | |
| 422 | /* update highest_used_slotid when it is freed */ |
| 423 | if (slotid == tbl->highest_used_slotid) { |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 424 | u32 new_max = find_last_bit(tbl->used_slots, slotid); |
| 425 | if (new_max < slotid) |
| 426 | tbl->highest_used_slotid = new_max; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 427 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 428 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 429 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 430 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 431 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 432 | } |
| 433 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 434 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 435 | { |
| 436 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 437 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 440 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 441 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 442 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 443 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 444 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 445 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 446 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 447 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 448 | return; |
| 449 | } |
| 450 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 451 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 452 | return; |
| 453 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 454 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 455 | complete(&ses->fc_slot_table.complete); |
| 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Signal state manager thread if session back channel is drained |
| 460 | */ |
| 461 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 462 | { |
| 463 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 464 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 465 | return; |
| 466 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 467 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 470 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 471 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 472 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 473 | struct nfs4_slot_table *tbl; |
| 474 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 475 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 476 | /* just wake up the next guy waiting since |
| 477 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 478 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 479 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 480 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 481 | tbl = res->sr_slot->table; |
| 482 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 483 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 484 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 485 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 486 | nfs4_check_drain_fc_complete(session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 487 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 488 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame^] | 491 | /* Update the client's idea of target_highest_slotid */ |
| 492 | static void nfs41_set_target_slotid_locked(struct nfs4_slot_table *tbl, |
| 493 | u32 target_highest_slotid) |
| 494 | { |
| 495 | if (tbl->target_highest_slotid == target_highest_slotid) |
| 496 | return; |
| 497 | tbl->target_highest_slotid = target_highest_slotid; |
| 498 | tbl->generation++; |
| 499 | } |
| 500 | |
| 501 | static void nfs41_update_target_slotid(struct nfs4_slot_table *tbl, |
| 502 | struct nfs4_slot *slot, |
| 503 | struct nfs4_sequence_res *res) |
| 504 | { |
| 505 | spin_lock(&tbl->slot_tbl_lock); |
| 506 | if (tbl->generation != slot->generation) |
| 507 | goto out; |
| 508 | nfs41_set_target_slotid_locked(tbl, res->sr_target_highest_slotid); |
| 509 | out: |
| 510 | spin_unlock(&tbl->slot_tbl_lock); |
| 511 | } |
| 512 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | 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] | 514 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 515 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 516 | struct nfs4_slot *slot; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 517 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 518 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 519 | |
| 520 | /* |
| 521 | * sr_status remains 1 if an RPC level error occurred. The server |
| 522 | * may or may not have processed the sequence operation.. |
| 523 | * Proceed as if the server received and processed the sequence |
| 524 | * operation. |
| 525 | */ |
| 526 | if (res->sr_status == 1) |
| 527 | res->sr_status = NFS_OK; |
| 528 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 529 | /* don't increment the sequence number if the task wasn't sent */ |
| 530 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 531 | goto out; |
| 532 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 533 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 534 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 535 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 536 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 537 | switch (res->sr_status) { |
| 538 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 539 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 540 | ++slot->seq_nr; |
| 541 | timestamp = slot->renewal_time; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 542 | clp = session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 543 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 544 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 545 | if (res->sr_status_flags != 0) |
| 546 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame^] | 547 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 548 | break; |
| 549 | case -NFS4ERR_DELAY: |
| 550 | /* The server detected a resend of the RPC call and |
| 551 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 552 | * of RFC5661. |
| 553 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 554 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 555 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 556 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 557 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 558 | goto out_retry; |
| 559 | default: |
| 560 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 561 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 562 | } |
| 563 | out: |
| 564 | /* The session may be reset by one of the error handlers. */ |
| 565 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 566 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 567 | return 1; |
| 568 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 569 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 570 | goto out; |
| 571 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 572 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 575 | static int nfs4_sequence_done(struct rpc_task *task, |
| 576 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 577 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 578 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 579 | return 1; |
| 580 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 581 | } |
| 582 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 583 | /* |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 584 | * nfs4_alloc_slot - efficiently look for a free slot |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 585 | * |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 586 | * nfs4_alloc_slot looks for an unset bit in the used_slots bitmap. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 587 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 588 | * and respectively set up the sequence operation args. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 589 | * |
| 590 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 591 | */ |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 592 | static struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 593 | { |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 594 | struct nfs4_slot *ret = NULL; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 595 | u32 slotid; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 596 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 597 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 598 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 599 | tbl->max_slots); |
| 600 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 601 | if (slotid >= tbl->max_slots) |
| 602 | goto out; |
| 603 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 604 | if (slotid > tbl->highest_used_slotid || |
| 605 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 606 | tbl->highest_used_slotid = slotid; |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 607 | ret = &tbl->slots[slotid]; |
| 608 | ret->renewal_time = jiffies; |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame^] | 609 | ret->generation = tbl->generation; |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 610 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 611 | out: |
| 612 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 613 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 614 | ret ? ret->slot_nr : -1); |
| 615 | return ret; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 616 | } |
| 617 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 618 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 619 | struct nfs4_sequence_res *res, int cache_reply) |
| 620 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 621 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 622 | args->sa_cache_this = 0; |
| 623 | if (cache_reply) |
| 624 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 625 | res->sr_slot = NULL; |
| 626 | } |
| 627 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 628 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 629 | struct nfs4_sequence_args *args, |
| 630 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 631 | struct rpc_task *task) |
| 632 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 633 | struct nfs4_slot *slot; |
| 634 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 635 | |
| 636 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 637 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 638 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 639 | return 0; |
| 640 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 641 | tbl = &session->fc_slot_table; |
| 642 | |
| 643 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 644 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 645 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 646 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 647 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 648 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 649 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 650 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 651 | } |
| 652 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 653 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 654 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 655 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 656 | spin_unlock(&tbl->slot_tbl_lock); |
| 657 | dprintk("%s enforce FIFO order\n", __func__); |
| 658 | return -EAGAIN; |
| 659 | } |
| 660 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 661 | slot = nfs4_alloc_slot(tbl); |
| 662 | if (slot == NULL) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 663 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 664 | spin_unlock(&tbl->slot_tbl_lock); |
| 665 | dprintk("<-- %s: no free slots\n", __func__); |
| 666 | return -EAGAIN; |
| 667 | } |
| 668 | spin_unlock(&tbl->slot_tbl_lock); |
| 669 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 670 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 671 | |
| 672 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 673 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 674 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 675 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 676 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 677 | res->sr_slot = slot; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 678 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 679 | /* |
| 680 | * sr_status is only set in decode_sequence, and so will remain |
| 681 | * set to 1 if an rpc level failure occurs. |
| 682 | */ |
| 683 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 684 | return 0; |
| 685 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 686 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 687 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 688 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 689 | struct nfs4_sequence_args *args, |
| 690 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 691 | struct rpc_task *task) |
| 692 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 693 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 694 | int ret = 0; |
| 695 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 696 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 697 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 698 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 699 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 700 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 701 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 702 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 703 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 704 | out: |
| 705 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 706 | return ret; |
| 707 | } |
| 708 | |
| 709 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 710 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 711 | struct nfs4_sequence_args *seq_args; |
| 712 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 713 | }; |
| 714 | |
| 715 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 716 | { |
| 717 | struct nfs41_call_sync_data *data = calldata; |
| 718 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 719 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 720 | |
| 721 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 722 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 723 | return; |
| 724 | rpc_call_start(task); |
| 725 | } |
| 726 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 727 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 728 | { |
| 729 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 730 | nfs41_call_sync_prepare(task, calldata); |
| 731 | } |
| 732 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 733 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 734 | { |
| 735 | struct nfs41_call_sync_data *data = calldata; |
| 736 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 737 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 738 | } |
| 739 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 740 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 741 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 742 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 743 | }; |
| 744 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 745 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 746 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 747 | .rpc_call_done = nfs41_call_sync_done, |
| 748 | }; |
| 749 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 750 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 751 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 752 | struct rpc_message *msg, |
| 753 | struct nfs4_sequence_args *args, |
| 754 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 755 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 756 | { |
| 757 | int ret; |
| 758 | struct rpc_task *task; |
| 759 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 760 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 761 | .seq_args = args, |
| 762 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 763 | }; |
| 764 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 765 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 766 | .rpc_message = msg, |
| 767 | .callback_ops = &nfs41_call_sync_ops, |
| 768 | .callback_data = &data |
| 769 | }; |
| 770 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 771 | if (privileged) |
| 772 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 773 | task = rpc_run_task(&task_setup); |
| 774 | if (IS_ERR(task)) |
| 775 | ret = PTR_ERR(task); |
| 776 | else { |
| 777 | ret = task->tk_status; |
| 778 | rpc_put_task(task); |
| 779 | } |
| 780 | return ret; |
| 781 | } |
| 782 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 783 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 784 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 785 | struct rpc_message *msg, |
| 786 | struct nfs4_sequence_args *args, |
| 787 | struct nfs4_sequence_res *res, |
| 788 | int cache_reply) |
| 789 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 790 | nfs41_init_sequence(args, res, cache_reply); |
| 791 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 792 | } |
| 793 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 794 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 795 | static inline |
| 796 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 797 | struct nfs4_sequence_res *res, int cache_reply) |
| 798 | { |
| 799 | } |
| 800 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 801 | static int nfs4_sequence_done(struct rpc_task *task, |
| 802 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 803 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 804 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 805 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 806 | #endif /* CONFIG_NFS_V4_1 */ |
| 807 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 808 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 809 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 810 | struct rpc_message *msg, |
| 811 | struct nfs4_sequence_args *args, |
| 812 | struct nfs4_sequence_res *res, |
| 813 | int cache_reply) |
| 814 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 815 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 816 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 817 | } |
| 818 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 819 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 820 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 821 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 822 | struct rpc_message *msg, |
| 823 | struct nfs4_sequence_args *args, |
| 824 | struct nfs4_sequence_res *res, |
| 825 | int cache_reply) |
| 826 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 827 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 828 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 829 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 830 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 831 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 833 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 835 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 836 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 837 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 838 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 839 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 840 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 843 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 844 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 845 | struct nfs_openargs o_arg; |
| 846 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 847 | struct nfs_open_confirmargs c_arg; |
| 848 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 849 | struct nfs4_string owner_name; |
| 850 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 851 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 853 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 854 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 855 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 856 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 857 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 858 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 859 | int rpc_status; |
| 860 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 861 | }; |
| 862 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 863 | |
| 864 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 865 | { |
| 866 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 867 | p->o_res.seqid = p->o_arg.seqid; |
| 868 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 869 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 870 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 871 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 872 | 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] | 873 | } |
| 874 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 875 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 876 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 877 | const struct iattr *attrs, |
| 878 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 879 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 880 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 881 | struct inode *dir = parent->d_inode; |
| 882 | struct nfs_server *server = NFS_SERVER(dir); |
| 883 | struct nfs4_opendata *p; |
| 884 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 885 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 886 | if (p == NULL) |
| 887 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 888 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 889 | if (p->o_arg.seqid == NULL) |
| 890 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 891 | nfs_sb_active(dentry->d_sb); |
| 892 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 893 | p->dir = parent; |
| 894 | p->owner = sp; |
| 895 | atomic_inc(&sp->so_count); |
| 896 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 897 | p->o_arg.open_flags = flags; |
| 898 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 899 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 900 | * will return permission denied for all bits until close */ |
| 901 | if (!(flags & O_EXCL)) { |
| 902 | /* ask server to check for all possible rights as results |
| 903 | * are cached */ |
| 904 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 905 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 906 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 907 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 908 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 909 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 910 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 911 | p->o_arg.server = server; |
| 912 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 913 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 914 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 915 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 916 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 917 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 918 | p->o_arg.u.attrs = &p->attrs; |
| 919 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 920 | |
| 921 | verf[0] = jiffies; |
| 922 | verf[1] = current->pid; |
| 923 | memcpy(p->o_arg.u.verifier.data, verf, |
| 924 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 925 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 926 | p->c_arg.fh = &p->o_res.fh; |
| 927 | p->c_arg.stateid = &p->o_res.stateid; |
| 928 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 929 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 930 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 931 | return p; |
| 932 | err_free: |
| 933 | kfree(p); |
| 934 | err: |
| 935 | dput(parent); |
| 936 | return NULL; |
| 937 | } |
| 938 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 939 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 940 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 941 | struct nfs4_opendata *p = container_of(kref, |
| 942 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 943 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 944 | |
| 945 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 946 | if (p->state != NULL) |
| 947 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 948 | nfs4_put_state_owner(p->owner); |
| 949 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 950 | dput(p->dentry); |
| 951 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 952 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 953 | kfree(p); |
| 954 | } |
| 955 | |
| 956 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 957 | { |
| 958 | if (p != NULL) |
| 959 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 960 | } |
| 961 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 962 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 963 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 964 | int ret; |
| 965 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 966 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 967 | return ret; |
| 968 | } |
| 969 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | 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] | 971 | { |
| 972 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 974 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 975 | goto out; |
| 976 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 977 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 978 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 979 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 980 | break; |
| 981 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 982 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 983 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 984 | break; |
| 985 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 986 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 987 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 988 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 990 | return ret; |
| 991 | } |
| 992 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 993 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 994 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 995 | if (delegation == NULL) |
| 996 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 997 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 998 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 999 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1000 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1001 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1002 | return 1; |
| 1003 | } |
| 1004 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1006 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1007 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1008 | case FMODE_WRITE: |
| 1009 | state->n_wronly++; |
| 1010 | break; |
| 1011 | case FMODE_READ: |
| 1012 | state->n_rdonly++; |
| 1013 | break; |
| 1014 | case FMODE_READ|FMODE_WRITE: |
| 1015 | state->n_rdwr++; |
| 1016 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1018 | } |
| 1019 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | 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] | 1021 | { |
| 1022 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1023 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1024 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1026 | case FMODE_READ: |
| 1027 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1028 | break; |
| 1029 | case FMODE_WRITE: |
| 1030 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1031 | break; |
| 1032 | case FMODE_READ|FMODE_WRITE: |
| 1033 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1034 | } |
| 1035 | } |
| 1036 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1037 | 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] | 1038 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1039 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1041 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1044 | 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] | 1045 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1046 | /* |
| 1047 | * Protect the call to nfs4_state_set_mode_locked and |
| 1048 | * serialise the stateid update |
| 1049 | */ |
| 1050 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1051 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1052 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1053 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1054 | } |
| 1055 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1057 | write_sequnlock(&state->seqlock); |
| 1058 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1059 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1060 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1063 | 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] | 1064 | { |
| 1065 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1066 | struct nfs_delegation *deleg_cur; |
| 1067 | int ret = 0; |
| 1068 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1069 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1070 | |
| 1071 | rcu_read_lock(); |
| 1072 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1073 | if (deleg_cur == NULL) |
| 1074 | goto no_delegation; |
| 1075 | |
| 1076 | spin_lock(&deleg_cur->lock); |
| 1077 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1078 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1079 | goto no_delegation_unlock; |
| 1080 | |
| 1081 | if (delegation == NULL) |
| 1082 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1083 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1084 | goto no_delegation_unlock; |
| 1085 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1086 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1087 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1088 | ret = 1; |
| 1089 | no_delegation_unlock: |
| 1090 | spin_unlock(&deleg_cur->lock); |
| 1091 | no_delegation: |
| 1092 | rcu_read_unlock(); |
| 1093 | |
| 1094 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1095 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1096 | ret = 1; |
| 1097 | } |
| 1098 | |
| 1099 | return ret; |
| 1100 | } |
| 1101 | |
| 1102 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1103 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1104 | { |
| 1105 | struct nfs_delegation *delegation; |
| 1106 | |
| 1107 | rcu_read_lock(); |
| 1108 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1109 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1110 | rcu_read_unlock(); |
| 1111 | return; |
| 1112 | } |
| 1113 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1114 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1115 | } |
| 1116 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1117 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1118 | { |
| 1119 | struct nfs4_state *state = opendata->state; |
| 1120 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1121 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1122 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1123 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1124 | nfs4_stateid stateid; |
| 1125 | int ret = -EAGAIN; |
| 1126 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1127 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1128 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1129 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1130 | if (can_open_cached(state, fmode, open_mode)) { |
| 1131 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1132 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1133 | goto out_return_state; |
| 1134 | } |
| 1135 | spin_unlock(&state->owner->so_lock); |
| 1136 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1137 | rcu_read_lock(); |
| 1138 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1139 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1140 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1141 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1142 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1143 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1144 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1145 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1146 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1147 | if (ret != 0) |
| 1148 | goto out; |
| 1149 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1150 | |
| 1151 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1152 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1153 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1154 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1155 | out: |
| 1156 | return ERR_PTR(ret); |
| 1157 | out_return_state: |
| 1158 | atomic_inc(&state->count); |
| 1159 | return state; |
| 1160 | } |
| 1161 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1162 | static void |
| 1163 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1164 | { |
| 1165 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1166 | struct nfs_delegation *delegation; |
| 1167 | int delegation_flags = 0; |
| 1168 | |
| 1169 | rcu_read_lock(); |
| 1170 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1171 | if (delegation) |
| 1172 | delegation_flags = delegation->flags; |
| 1173 | rcu_read_unlock(); |
| 1174 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1175 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1176 | "returning a delegation for " |
| 1177 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1178 | clp->cl_hostname); |
| 1179 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1180 | nfs_inode_set_delegation(state->inode, |
| 1181 | data->owner->so_cred, |
| 1182 | &data->o_res); |
| 1183 | else |
| 1184 | nfs_inode_reclaim_delegation(state->inode, |
| 1185 | data->owner->so_cred, |
| 1186 | &data->o_res); |
| 1187 | } |
| 1188 | |
| 1189 | /* |
| 1190 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1191 | * and update the nfs4_state. |
| 1192 | */ |
| 1193 | static struct nfs4_state * |
| 1194 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1195 | { |
| 1196 | struct inode *inode = data->state->inode; |
| 1197 | struct nfs4_state *state = data->state; |
| 1198 | int ret; |
| 1199 | |
| 1200 | if (!data->rpc_done) { |
| 1201 | ret = data->rpc_status; |
| 1202 | goto err; |
| 1203 | } |
| 1204 | |
| 1205 | ret = -ESTALE; |
| 1206 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1207 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1208 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1209 | goto err; |
| 1210 | |
| 1211 | ret = -ENOMEM; |
| 1212 | state = nfs4_get_open_state(inode, data->owner); |
| 1213 | if (state == NULL) |
| 1214 | goto err; |
| 1215 | |
| 1216 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1217 | if (ret) |
| 1218 | goto err; |
| 1219 | |
| 1220 | if (data->o_res.delegation_type != 0) |
| 1221 | nfs4_opendata_check_deleg(data, state); |
| 1222 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1223 | data->o_arg.fmode); |
| 1224 | |
| 1225 | return state; |
| 1226 | err: |
| 1227 | return ERR_PTR(ret); |
| 1228 | |
| 1229 | } |
| 1230 | |
| 1231 | static struct nfs4_state * |
| 1232 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1233 | { |
| 1234 | struct inode *inode; |
| 1235 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1236 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1237 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1238 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1239 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1240 | goto out; |
| 1241 | } |
| 1242 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1243 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1244 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1245 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1246 | 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] | 1247 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1248 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1249 | goto err; |
| 1250 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1251 | state = nfs4_get_open_state(inode, data->owner); |
| 1252 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1253 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1254 | if (data->o_res.delegation_type != 0) |
| 1255 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1256 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1257 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1258 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1259 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1260 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1261 | err_put_inode: |
| 1262 | iput(inode); |
| 1263 | err: |
| 1264 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1265 | } |
| 1266 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1267 | static struct nfs4_state * |
| 1268 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1269 | { |
| 1270 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1271 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1272 | return _nfs4_opendata_to_nfs4_state(data); |
| 1273 | } |
| 1274 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1275 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1276 | { |
| 1277 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1278 | struct nfs_open_context *ctx; |
| 1279 | |
| 1280 | spin_lock(&state->inode->i_lock); |
| 1281 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1282 | if (ctx->state != state) |
| 1283 | continue; |
| 1284 | get_nfs_open_context(ctx); |
| 1285 | spin_unlock(&state->inode->i_lock); |
| 1286 | return ctx; |
| 1287 | } |
| 1288 | spin_unlock(&state->inode->i_lock); |
| 1289 | return ERR_PTR(-ENOENT); |
| 1290 | } |
| 1291 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1292 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1293 | { |
| 1294 | struct nfs4_opendata *opendata; |
| 1295 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1296 | 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] | 1297 | if (opendata == NULL) |
| 1298 | return ERR_PTR(-ENOMEM); |
| 1299 | opendata->state = state; |
| 1300 | atomic_inc(&state->count); |
| 1301 | return opendata; |
| 1302 | } |
| 1303 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1304 | 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] | 1305 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1306 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1307 | int ret; |
| 1308 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1309 | opendata->o_arg.open_flags = 0; |
| 1310 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1311 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1312 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1313 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1314 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1315 | if (ret != 0) |
| 1316 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1317 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1318 | if (IS_ERR(newstate)) |
| 1319 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1320 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1321 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1326 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1327 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1328 | int ret; |
| 1329 | |
| 1330 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1331 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1332 | smp_rmb(); |
| 1333 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1334 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1335 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1336 | if (ret != 0) |
| 1337 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1338 | if (newstate != state) |
| 1339 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1340 | } |
| 1341 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1342 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1343 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1344 | if (ret != 0) |
| 1345 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1346 | if (newstate != state) |
| 1347 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1348 | } |
| 1349 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1350 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1351 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1352 | if (ret != 0) |
| 1353 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1354 | if (newstate != state) |
| 1355 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1356 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1357 | /* |
| 1358 | * We may have performed cached opens for all three recoveries. |
| 1359 | * Check if we need to update the current stateid. |
| 1360 | */ |
| 1361 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1362 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1363 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1364 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1365 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1366 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1367 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1368 | return 0; |
| 1369 | } |
| 1370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | /* |
| 1372 | * OPEN_RECLAIM: |
| 1373 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1375 | 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] | 1376 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1377 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1378 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1379 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | int status; |
| 1381 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1382 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1383 | if (IS_ERR(opendata)) |
| 1384 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1385 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1386 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1387 | rcu_read_lock(); |
| 1388 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1389 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1390 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1391 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1392 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1393 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1394 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | return status; |
| 1396 | } |
| 1397 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1398 | 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] | 1399 | { |
| 1400 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1401 | struct nfs4_exception exception = { }; |
| 1402 | int err; |
| 1403 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1404 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1405 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1406 | break; |
| 1407 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | } while (exception.retry); |
| 1409 | return err; |
| 1410 | } |
| 1411 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1412 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1413 | { |
| 1414 | struct nfs_open_context *ctx; |
| 1415 | int ret; |
| 1416 | |
| 1417 | ctx = nfs4_state_find_open_context(state); |
| 1418 | if (IS_ERR(ctx)) |
| 1419 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1420 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1421 | put_nfs_open_context(ctx); |
| 1422 | return ret; |
| 1423 | } |
| 1424 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1425 | 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] | 1426 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1427 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1428 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1430 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1431 | if (IS_ERR(opendata)) |
| 1432 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1433 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1434 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1435 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1436 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1437 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1440 | 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] | 1441 | { |
| 1442 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1443 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | int err; |
| 1445 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1446 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | switch (err) { |
| 1448 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1449 | case -ENOENT: |
| 1450 | case -ESTALE: |
| 1451 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1452 | case -NFS4ERR_BADSESSION: |
| 1453 | case -NFS4ERR_BADSLOT: |
| 1454 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1455 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1456 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1457 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1458 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | case -NFS4ERR_STALE_CLIENTID: |
| 1460 | case -NFS4ERR_STALE_STATEID: |
| 1461 | case -NFS4ERR_EXPIRED: |
| 1462 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1463 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1464 | goto out; |
| 1465 | case -ERESTARTSYS: |
| 1466 | /* |
| 1467 | * The show must go on: exit, but mark the |
| 1468 | * stateid as needing recovery. |
| 1469 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1470 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1471 | case -NFS4ERR_ADMIN_REVOKED: |
| 1472 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1473 | nfs_inode_find_state_and_recover(state->inode, |
| 1474 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1475 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1476 | case -EKEYEXPIRED: |
| 1477 | /* |
| 1478 | * User RPCSEC_GSS context has expired. |
| 1479 | * We cannot recover this stateid now, so |
| 1480 | * skip it and allow recovery thread to |
| 1481 | * proceed. |
| 1482 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1483 | case -ENOMEM: |
| 1484 | err = 0; |
| 1485 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | } |
| 1487 | err = nfs4_handle_exception(server, err, &exception); |
| 1488 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1489 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | return err; |
| 1491 | } |
| 1492 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1493 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1494 | { |
| 1495 | struct nfs4_opendata *data = calldata; |
| 1496 | |
| 1497 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1498 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1499 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1500 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1501 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1502 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1503 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | static void nfs4_open_confirm_release(void *calldata) |
| 1507 | { |
| 1508 | struct nfs4_opendata *data = calldata; |
| 1509 | struct nfs4_state *state = NULL; |
| 1510 | |
| 1511 | /* If this request hasn't been cancelled, do nothing */ |
| 1512 | if (data->cancelled == 0) |
| 1513 | goto out_free; |
| 1514 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1515 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1516 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1517 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1518 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1519 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1520 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1521 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1525 | .rpc_call_done = nfs4_open_confirm_done, |
| 1526 | .rpc_release = nfs4_open_confirm_release, |
| 1527 | }; |
| 1528 | |
| 1529 | /* |
| 1530 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1531 | */ |
| 1532 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1533 | { |
| 1534 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1535 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1536 | struct rpc_message msg = { |
| 1537 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1538 | .rpc_argp = &data->c_arg, |
| 1539 | .rpc_resp = &data->c_res, |
| 1540 | .rpc_cred = data->owner->so_cred, |
| 1541 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1542 | struct rpc_task_setup task_setup_data = { |
| 1543 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1544 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1545 | .callback_ops = &nfs4_open_confirm_ops, |
| 1546 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1547 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1548 | .flags = RPC_TASK_ASYNC, |
| 1549 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | int status; |
| 1551 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1552 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1553 | data->rpc_done = 0; |
| 1554 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1555 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1556 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1557 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1558 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1559 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1560 | if (status != 0) { |
| 1561 | data->cancelled = 1; |
| 1562 | smp_wmb(); |
| 1563 | } else |
| 1564 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1565 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | return status; |
| 1567 | } |
| 1568 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1569 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1571 | struct nfs4_opendata *data = calldata; |
| 1572 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1573 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1574 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1575 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1576 | /* |
| 1577 | * Check if we still need to send an OPEN call, or if we can use |
| 1578 | * a delegation instead. |
| 1579 | */ |
| 1580 | if (data->state != NULL) { |
| 1581 | struct nfs_delegation *delegation; |
| 1582 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1583 | 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] | 1584 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1585 | rcu_read_lock(); |
| 1586 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1587 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1588 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1589 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1590 | rcu_read_unlock(); |
| 1591 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1592 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1593 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1594 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1595 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1596 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1597 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1598 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1599 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1600 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1601 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1602 | &data->o_res.seq_res, |
| 1603 | task) != 0) |
| 1604 | nfs_release_seqid(data->o_arg.seqid); |
| 1605 | else |
| 1606 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1607 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1608 | unlock_no_action: |
| 1609 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1610 | out_no_action: |
| 1611 | task->tk_action = NULL; |
| 1612 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1613 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1615 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1616 | { |
| 1617 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1618 | nfs4_open_prepare(task, calldata); |
| 1619 | } |
| 1620 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1621 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1622 | { |
| 1623 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1625 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1626 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1627 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1628 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1629 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1630 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1631 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1632 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1633 | case S_IFREG: |
| 1634 | break; |
| 1635 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1636 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1637 | break; |
| 1638 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1639 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1640 | break; |
| 1641 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1642 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1643 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1644 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1645 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1646 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1647 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1648 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1649 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1650 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1651 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1652 | static void nfs4_open_release(void *calldata) |
| 1653 | { |
| 1654 | struct nfs4_opendata *data = calldata; |
| 1655 | struct nfs4_state *state = NULL; |
| 1656 | |
| 1657 | /* If this request hasn't been cancelled, do nothing */ |
| 1658 | if (data->cancelled == 0) |
| 1659 | goto out_free; |
| 1660 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1661 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1662 | goto out_free; |
| 1663 | /* In case we need an open_confirm, no cleanup! */ |
| 1664 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1665 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1666 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1667 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1668 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1669 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1670 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1674 | .rpc_call_prepare = nfs4_open_prepare, |
| 1675 | .rpc_call_done = nfs4_open_done, |
| 1676 | .rpc_release = nfs4_open_release, |
| 1677 | }; |
| 1678 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1679 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1680 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1681 | .rpc_call_done = nfs4_open_done, |
| 1682 | .rpc_release = nfs4_open_release, |
| 1683 | }; |
| 1684 | |
| 1685 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | { |
| 1687 | struct inode *dir = data->dir->d_inode; |
| 1688 | struct nfs_server *server = NFS_SERVER(dir); |
| 1689 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1690 | struct nfs_openres *o_res = &data->o_res; |
| 1691 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1692 | struct rpc_message msg = { |
| 1693 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1694 | .rpc_argp = o_arg, |
| 1695 | .rpc_resp = o_res, |
| 1696 | .rpc_cred = data->owner->so_cred, |
| 1697 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1698 | struct rpc_task_setup task_setup_data = { |
| 1699 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1700 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1701 | .callback_ops = &nfs4_open_ops, |
| 1702 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1703 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1704 | .flags = RPC_TASK_ASYNC, |
| 1705 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1706 | int status; |
| 1707 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1708 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1709 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1710 | data->rpc_done = 0; |
| 1711 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1712 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1713 | if (isrecover) |
| 1714 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1715 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1716 | if (IS_ERR(task)) |
| 1717 | return PTR_ERR(task); |
| 1718 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1719 | if (status != 0) { |
| 1720 | data->cancelled = 1; |
| 1721 | smp_wmb(); |
| 1722 | } else |
| 1723 | status = data->rpc_status; |
| 1724 | rpc_put_task(task); |
| 1725 | |
| 1726 | return status; |
| 1727 | } |
| 1728 | |
| 1729 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1730 | { |
| 1731 | struct inode *dir = data->dir->d_inode; |
| 1732 | struct nfs_openres *o_res = &data->o_res; |
| 1733 | int status; |
| 1734 | |
| 1735 | status = nfs4_run_open_task(data, 1); |
| 1736 | if (status != 0 || !data->rpc_done) |
| 1737 | return status; |
| 1738 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1739 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1740 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1741 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1742 | status = _nfs4_proc_open_confirm(data); |
| 1743 | if (status != 0) |
| 1744 | return status; |
| 1745 | } |
| 1746 | |
| 1747 | return status; |
| 1748 | } |
| 1749 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1750 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1751 | struct nfs4_opendata *opendata, |
| 1752 | struct nfs4_state *state, fmode_t fmode) |
| 1753 | { |
| 1754 | struct nfs_access_entry cache; |
| 1755 | u32 mask; |
| 1756 | |
| 1757 | /* access call failed or for some reason the server doesn't |
| 1758 | * support any access modes -- defer access call until later */ |
| 1759 | if (opendata->o_res.access_supported == 0) |
| 1760 | return 0; |
| 1761 | |
| 1762 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1763 | /* don't check MAY_WRITE - a newly created file may not have |
| 1764 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1765 | if (fmode & FMODE_READ) |
| 1766 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1767 | if (fmode & FMODE_EXEC) |
| 1768 | mask |= MAY_EXEC; |
| 1769 | |
| 1770 | cache.cred = cred; |
| 1771 | cache.jiffies = jiffies; |
| 1772 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1773 | nfs_access_add_cache(state->inode, &cache); |
| 1774 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1775 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1776 | return 0; |
| 1777 | |
| 1778 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1779 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1780 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1781 | } |
| 1782 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1783 | /* |
| 1784 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1785 | */ |
| 1786 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1787 | { |
| 1788 | struct inode *dir = data->dir->d_inode; |
| 1789 | struct nfs_server *server = NFS_SERVER(dir); |
| 1790 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1791 | struct nfs_openres *o_res = &data->o_res; |
| 1792 | int status; |
| 1793 | |
| 1794 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1795 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1796 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1797 | if (status != 0) { |
| 1798 | if (status == -NFS4ERR_BADNAME && |
| 1799 | !(o_arg->open_flags & O_CREAT)) |
| 1800 | return -ENOENT; |
| 1801 | return status; |
| 1802 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1803 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1804 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1805 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1806 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1807 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1808 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1809 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1811 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1813 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | } |
| 1815 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1816 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1817 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1820 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1821 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1822 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1823 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1824 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1825 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1826 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1827 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1828 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1829 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1830 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1831 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1832 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1833 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1834 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1835 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1836 | } |
| 1837 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1838 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1839 | { |
| 1840 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1841 | } |
| 1842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | /* |
| 1844 | * OPEN_EXPIRED: |
| 1845 | * reclaim state on the server after a network partition. |
| 1846 | * Assumes caller holds the appropriate lock |
| 1847 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1848 | 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] | 1849 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1850 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1851 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1853 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1854 | if (IS_ERR(opendata)) |
| 1855 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1856 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1857 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1858 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1859 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1860 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1863 | 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] | 1864 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1865 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1866 | struct nfs4_exception exception = { }; |
| 1867 | int err; |
| 1868 | |
| 1869 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1870 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1871 | switch (err) { |
| 1872 | default: |
| 1873 | goto out; |
| 1874 | case -NFS4ERR_GRACE: |
| 1875 | case -NFS4ERR_DELAY: |
| 1876 | nfs4_handle_exception(server, err, &exception); |
| 1877 | err = 0; |
| 1878 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1879 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1880 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1881 | return err; |
| 1882 | } |
| 1883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1885 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1887 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1889 | ctx = nfs4_state_find_open_context(state); |
| 1890 | if (IS_ERR(ctx)) |
| 1891 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1892 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1893 | put_nfs_open_context(ctx); |
| 1894 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1897 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1898 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1899 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1900 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1901 | nfs4_stateid *stateid = &state->stateid; |
| 1902 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1903 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1904 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1905 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1906 | return; |
| 1907 | |
| 1908 | status = nfs41_test_stateid(server, stateid); |
| 1909 | if (status != NFS_OK) { |
| 1910 | /* Free the stateid unless the server explicitly |
| 1911 | * informs us the stateid is unrecognized. */ |
| 1912 | if (status != -NFS4ERR_BAD_STATEID) |
| 1913 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1914 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1915 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1916 | write_seqlock(&state->seqlock); |
| 1917 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1918 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1919 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | /** |
| 1924 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1925 | * |
| 1926 | * @state: NFSv4 state for an inode |
| 1927 | * |
| 1928 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1929 | * Otherwise a negative NFS4ERR value is returned. |
| 1930 | */ |
| 1931 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1932 | { |
| 1933 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1934 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1935 | int status; |
| 1936 | |
| 1937 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1938 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1939 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1940 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1941 | return -NFS4ERR_BAD_STATEID; |
| 1942 | |
| 1943 | status = nfs41_test_stateid(server, stateid); |
| 1944 | if (status != NFS_OK) { |
| 1945 | /* Free the stateid unless the server explicitly |
| 1946 | * informs us the stateid is unrecognized. */ |
| 1947 | if (status != -NFS4ERR_BAD_STATEID) |
| 1948 | nfs41_free_stateid(server, stateid); |
| 1949 | |
| 1950 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1951 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1952 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1953 | } |
| 1954 | return status; |
| 1955 | } |
| 1956 | |
| 1957 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1958 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1959 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1960 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1961 | nfs41_clear_delegation_stateid(state); |
| 1962 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1963 | if (status != NFS_OK) |
| 1964 | status = nfs4_open_expired(sp, state); |
| 1965 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1966 | } |
| 1967 | #endif |
| 1968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1970 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1971 | * fields corresponding to attributes that were used to store the verifier. |
| 1972 | * Make sure we clobber those fields in the later setattr call |
| 1973 | */ |
| 1974 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1975 | { |
| 1976 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1977 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1978 | sattr->ia_valid |= ATTR_ATIME; |
| 1979 | |
| 1980 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1981 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1982 | sattr->ia_valid |= ATTR_MTIME; |
| 1983 | } |
| 1984 | |
| 1985 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1986 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1988 | static int _nfs4_do_open(struct inode *dir, |
| 1989 | struct dentry *dentry, |
| 1990 | fmode_t fmode, |
| 1991 | int flags, |
| 1992 | struct iattr *sattr, |
| 1993 | struct rpc_cred *cred, |
| 1994 | struct nfs4_state **res, |
| 1995 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | { |
| 1997 | struct nfs4_state_owner *sp; |
| 1998 | struct nfs4_state *state = NULL; |
| 1999 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2000 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2001 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | |
| 2003 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2005 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2006 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2008 | goto out_err; |
| 2009 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2010 | status = nfs4_recover_expired_lease(server); |
| 2011 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2012 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2013 | if (dentry->d_inode != NULL) |
| 2014 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2015 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2016 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2017 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2018 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2020 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2021 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2022 | if (!opendata->f_attr.mdsthreshold) |
| 2023 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2024 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2025 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2026 | if (dentry->d_inode != NULL) |
| 2027 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2028 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2029 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2031 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2033 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2034 | status = PTR_ERR(state); |
| 2035 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2036 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2037 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 2038 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2039 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2040 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 2041 | if (status != 0) |
| 2042 | goto err_opendata_put; |
| 2043 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2044 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 2045 | nfs4_exclusive_attrset(opendata, sattr); |
| 2046 | |
| 2047 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2048 | status = nfs4_do_setattr(state->inode, cred, |
| 2049 | opendata->o_res.f_attr, sattr, |
| 2050 | state); |
| 2051 | if (status == 0) |
| 2052 | nfs_setattr_update_inode(state->inode, sattr); |
| 2053 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2054 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2055 | |
| 2056 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2057 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2058 | else |
| 2059 | kfree(opendata->f_attr.mdsthreshold); |
| 2060 | opendata->f_attr.mdsthreshold = NULL; |
| 2061 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2062 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | *res = state; |
| 2065 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2066 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2067 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2068 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2069 | err_put_state_owner: |
| 2070 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | *res = NULL; |
| 2073 | return status; |
| 2074 | } |
| 2075 | |
| 2076 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2077 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2078 | struct dentry *dentry, |
| 2079 | fmode_t fmode, |
| 2080 | int flags, |
| 2081 | struct iattr *sattr, |
| 2082 | struct rpc_cred *cred, |
| 2083 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | { |
| 2085 | struct nfs4_exception exception = { }; |
| 2086 | struct nfs4_state *res; |
| 2087 | int status; |
| 2088 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2089 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2091 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2092 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | if (status == 0) |
| 2094 | break; |
| 2095 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2096 | * book-keeping w.r.t. state-changing operations |
| 2097 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2098 | * It is actually a sign of a bug on the client or on the server. |
| 2099 | * |
| 2100 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2101 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | * have unhashed the old state_owner for us, and that we can |
| 2103 | * therefore safely retry using a new one. We should still warn |
| 2104 | * the user though... |
| 2105 | */ |
| 2106 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2107 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2108 | " returned a bad sequence-id error!\n", |
| 2109 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | exception.retry = 1; |
| 2111 | continue; |
| 2112 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2113 | /* |
| 2114 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2115 | * state before it received the OPEN_CONFIRM. |
| 2116 | * Recover by retrying the request as per the discussion |
| 2117 | * on Page 181 of RFC3530. |
| 2118 | */ |
| 2119 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2120 | exception.retry = 1; |
| 2121 | continue; |
| 2122 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2123 | if (status == -EAGAIN) { |
| 2124 | /* We must have found a delegation */ |
| 2125 | exception.retry = 1; |
| 2126 | continue; |
| 2127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2129 | status, &exception)); |
| 2130 | } while (exception.retry); |
| 2131 | return res; |
| 2132 | } |
| 2133 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2134 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2135 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2136 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2138 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2140 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | .iap = sattr, |
| 2142 | .server = server, |
| 2143 | .bitmask = server->attr_bitmask, |
| 2144 | }; |
| 2145 | struct nfs_setattrres res = { |
| 2146 | .fattr = fattr, |
| 2147 | .server = server, |
| 2148 | }; |
| 2149 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2150 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2151 | .rpc_argp = &arg, |
| 2152 | .rpc_resp = &res, |
| 2153 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2155 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2156 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2158 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2160 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2161 | struct nfs_lockowner lockowner = { |
| 2162 | .l_owner = current->files, |
| 2163 | .l_pid = current->tgid, |
| 2164 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2165 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2166 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2167 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2168 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2169 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2170 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2171 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2173 | 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] | 2174 | if (status == 0 && state != NULL) |
| 2175 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2176 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2179 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2180 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2181 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2183 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2184 | struct nfs4_exception exception = { |
| 2185 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2186 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2187 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | int err; |
| 2189 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2190 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2191 | switch (err) { |
| 2192 | case -NFS4ERR_OPENMODE: |
| 2193 | if (state && !(state->state & FMODE_WRITE)) { |
| 2194 | err = -EBADF; |
| 2195 | if (sattr->ia_valid & ATTR_OPEN) |
| 2196 | err = -EACCES; |
| 2197 | goto out; |
| 2198 | } |
| 2199 | } |
| 2200 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2202 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | return err; |
| 2204 | } |
| 2205 | |
| 2206 | struct nfs4_closedata { |
| 2207 | struct inode *inode; |
| 2208 | struct nfs4_state *state; |
| 2209 | struct nfs_closeargs arg; |
| 2210 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2211 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2212 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2213 | bool roc; |
| 2214 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | }; |
| 2216 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2217 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2218 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2219 | struct nfs4_closedata *calldata = data; |
| 2220 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2221 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2222 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2223 | if (calldata->roc) |
| 2224 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2225 | nfs4_put_open_state(calldata->state); |
| 2226 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2227 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2228 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2229 | kfree(calldata); |
| 2230 | } |
| 2231 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2232 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2233 | fmode_t fmode) |
| 2234 | { |
| 2235 | spin_lock(&state->owner->so_lock); |
| 2236 | if (!(fmode & FMODE_READ)) |
| 2237 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2238 | if (!(fmode & FMODE_WRITE)) |
| 2239 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2240 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2241 | spin_unlock(&state->owner->so_lock); |
| 2242 | } |
| 2243 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2244 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2246 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2249 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2250 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2251 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2252 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | /* hmm. we are done with the inode, and in the process of freeing |
| 2254 | * the state_owner. we keep this around to process errors |
| 2255 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | switch (task->tk_status) { |
| 2257 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2258 | if (calldata->roc) |
| 2259 | pnfs_roc_set_barrier(state->inode, |
| 2260 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2261 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2262 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2263 | nfs4_close_clear_stateid_flags(state, |
| 2264 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | break; |
| 2266 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2267 | case -NFS4ERR_OLD_STATEID: |
| 2268 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2270 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2271 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2273 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2274 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2276 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2277 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2278 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2281 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2283 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2284 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2285 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2286 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2287 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2288 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2289 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2290 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2291 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2292 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2293 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2294 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2295 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2296 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2297 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2298 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2299 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2300 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2301 | } |
| 2302 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2303 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2304 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2305 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2306 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2307 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2308 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2309 | |
| 2310 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2311 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2312 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2313 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2314 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2315 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2316 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2317 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2318 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2319 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2320 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2321 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2322 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2323 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2324 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2325 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2326 | &calldata->arg.seq_args, |
| 2327 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2328 | task) != 0) |
| 2329 | nfs_release_seqid(calldata->arg.seqid); |
| 2330 | else |
| 2331 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2332 | out: |
| 2333 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2336 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2337 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2338 | .rpc_call_done = nfs4_close_done, |
| 2339 | .rpc_release = nfs4_free_closedata, |
| 2340 | }; |
| 2341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | /* |
| 2343 | * It is possible for data to be read/written from a mem-mapped file |
| 2344 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2345 | * This means that we can't safely call nfsv4 close on a file until |
| 2346 | * the inode is cleared. This in turn means that we are not good |
| 2347 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2348 | * share state even when we are done with one of the three share |
| 2349 | * stateid's in the inode. |
| 2350 | * |
| 2351 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2352 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2353 | 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] | 2354 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2355 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2357 | struct nfs4_state_owner *sp = state->owner; |
| 2358 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2359 | struct rpc_message msg = { |
| 2360 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2361 | .rpc_cred = state->owner->so_cred, |
| 2362 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2363 | struct rpc_task_setup task_setup_data = { |
| 2364 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2365 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2366 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2367 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2368 | .flags = RPC_TASK_ASYNC, |
| 2369 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2370 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2372 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2374 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2375 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2376 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2378 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2379 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2381 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2382 | if (calldata->arg.seqid == NULL) |
| 2383 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2384 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2385 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2386 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2387 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2388 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2389 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2390 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2391 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2392 | msg.rpc_argp = &calldata->arg; |
| 2393 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2394 | task_setup_data.callback_data = calldata; |
| 2395 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2396 | if (IS_ERR(task)) |
| 2397 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2398 | status = 0; |
| 2399 | if (wait) |
| 2400 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2401 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2402 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2403 | out_free_calldata: |
| 2404 | kfree(calldata); |
| 2405 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2406 | nfs4_put_open_state(state); |
| 2407 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2408 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2411 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2412 | 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] | 2413 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | struct nfs4_state *state; |
| 2415 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2416 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2417 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2418 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2419 | if (IS_ERR(state)) |
| 2420 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2421 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2422 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2425 | 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] | 2426 | { |
| 2427 | if (ctx->state == NULL) |
| 2428 | return; |
| 2429 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2430 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2431 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2432 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | |
| 2435 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2436 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2437 | struct nfs4_server_caps_arg args = { |
| 2438 | .fhandle = fhandle, |
| 2439 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | struct nfs4_server_caps_res res = {}; |
| 2441 | struct rpc_message msg = { |
| 2442 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2443 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | .rpc_resp = &res, |
| 2445 | }; |
| 2446 | int status; |
| 2447 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2448 | 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] | 2449 | if (status == 0) { |
| 2450 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2451 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2452 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2453 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2454 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2455 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2457 | server->caps |= NFS_CAP_ACLS; |
| 2458 | if (res.has_links != 0) |
| 2459 | server->caps |= NFS_CAP_HARDLINKS; |
| 2460 | if (res.has_symlinks != 0) |
| 2461 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2462 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2463 | server->caps |= NFS_CAP_FILEID; |
| 2464 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2465 | server->caps |= NFS_CAP_MODE; |
| 2466 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2467 | server->caps |= NFS_CAP_NLINK; |
| 2468 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2469 | server->caps |= NFS_CAP_OWNER; |
| 2470 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2471 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2472 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2473 | server->caps |= NFS_CAP_ATIME; |
| 2474 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2475 | server->caps |= NFS_CAP_CTIME; |
| 2476 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2477 | server->caps |= NFS_CAP_MTIME; |
| 2478 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2479 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2480 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2481 | 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] | 2482 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2483 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | return status; |
| 2487 | } |
| 2488 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2489 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | { |
| 2491 | struct nfs4_exception exception = { }; |
| 2492 | int err; |
| 2493 | do { |
| 2494 | err = nfs4_handle_exception(server, |
| 2495 | _nfs4_server_capabilities(server, fhandle), |
| 2496 | &exception); |
| 2497 | } while (exception.retry); |
| 2498 | return err; |
| 2499 | } |
| 2500 | |
| 2501 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2502 | struct nfs_fsinfo *info) |
| 2503 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | struct nfs4_lookup_root_arg args = { |
| 2505 | .bitmask = nfs4_fattr_bitmap, |
| 2506 | }; |
| 2507 | struct nfs4_lookup_res res = { |
| 2508 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2509 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | .fh = fhandle, |
| 2511 | }; |
| 2512 | struct rpc_message msg = { |
| 2513 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2514 | .rpc_argp = &args, |
| 2515 | .rpc_resp = &res, |
| 2516 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2517 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2518 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2519 | 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] | 2520 | } |
| 2521 | |
| 2522 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2523 | struct nfs_fsinfo *info) |
| 2524 | { |
| 2525 | struct nfs4_exception exception = { }; |
| 2526 | int err; |
| 2527 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2528 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2529 | switch (err) { |
| 2530 | case 0: |
| 2531 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2532 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2533 | default: |
| 2534 | err = nfs4_handle_exception(server, err, &exception); |
| 2535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2537 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | return err; |
| 2539 | } |
| 2540 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2541 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2542 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2543 | { |
| 2544 | struct rpc_auth *auth; |
| 2545 | int ret; |
| 2546 | |
| 2547 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2548 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2549 | ret = -EIO; |
| 2550 | goto out; |
| 2551 | } |
| 2552 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2553 | out: |
| 2554 | return ret; |
| 2555 | } |
| 2556 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2557 | 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] | 2558 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2560 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2561 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2563 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2564 | if (len < 0) |
| 2565 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2566 | |
| 2567 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2568 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2569 | * thus has already been tried. */ |
| 2570 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2571 | continue; |
| 2572 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2573 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2574 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2575 | continue; |
| 2576 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2577 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2578 | /* |
| 2579 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2580 | * to access the mount. It could also mean that we tried to mount |
| 2581 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2582 | * existing mount programs don't handle -EACCES very well so it should |
| 2583 | * be mapped to -EPERM instead. |
| 2584 | */ |
| 2585 | if (status == -EACCES) |
| 2586 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2587 | return status; |
| 2588 | } |
| 2589 | |
| 2590 | /* |
| 2591 | * get the file handle for the "/" directory on the server |
| 2592 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2593 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2594 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2595 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2596 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2597 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2598 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2599 | /* |
| 2600 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2601 | * by nfs4_map_errors() as this function exits. |
| 2602 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2603 | 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] | 2604 | if (status == 0) |
| 2605 | status = nfs4_server_capabilities(server, fhandle); |
| 2606 | if (status == 0) |
| 2607 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2608 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2611 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2612 | struct nfs_fsinfo *info) |
| 2613 | { |
| 2614 | int error; |
| 2615 | struct nfs_fattr *fattr = info->fattr; |
| 2616 | |
| 2617 | error = nfs4_server_capabilities(server, mntfh); |
| 2618 | if (error < 0) { |
| 2619 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2620 | return error; |
| 2621 | } |
| 2622 | |
| 2623 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2624 | if (error < 0) { |
| 2625 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2626 | return error; |
| 2627 | } |
| 2628 | |
| 2629 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2630 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2631 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2632 | |
| 2633 | return error; |
| 2634 | } |
| 2635 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2636 | /* |
| 2637 | * Get locations and (maybe) other attributes of a referral. |
| 2638 | * Note that we'll actually follow the referral later when |
| 2639 | * we detect fsid mismatch in inode revalidation |
| 2640 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2641 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2642 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2643 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2644 | { |
| 2645 | int status = -ENOMEM; |
| 2646 | struct page *page = NULL; |
| 2647 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2648 | |
| 2649 | page = alloc_page(GFP_KERNEL); |
| 2650 | if (page == NULL) |
| 2651 | goto out; |
| 2652 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2653 | if (locations == NULL) |
| 2654 | goto out; |
| 2655 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2656 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2657 | if (status != 0) |
| 2658 | goto out; |
| 2659 | /* Make sure server returned a different fsid for the referral */ |
| 2660 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2661 | dprintk("%s: server did not return a different fsid for" |
| 2662 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2663 | status = -EIO; |
| 2664 | goto out; |
| 2665 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2666 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2667 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2668 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2669 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2670 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2671 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2672 | out: |
| 2673 | if (page) |
| 2674 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2675 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2676 | return status; |
| 2677 | } |
| 2678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2680 | { |
| 2681 | struct nfs4_getattr_arg args = { |
| 2682 | .fh = fhandle, |
| 2683 | .bitmask = server->attr_bitmask, |
| 2684 | }; |
| 2685 | struct nfs4_getattr_res res = { |
| 2686 | .fattr = fattr, |
| 2687 | .server = server, |
| 2688 | }; |
| 2689 | struct rpc_message msg = { |
| 2690 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2691 | .rpc_argp = &args, |
| 2692 | .rpc_resp = &res, |
| 2693 | }; |
| 2694 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2695 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2696 | 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] | 2697 | } |
| 2698 | |
| 2699 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2700 | { |
| 2701 | struct nfs4_exception exception = { }; |
| 2702 | int err; |
| 2703 | do { |
| 2704 | err = nfs4_handle_exception(server, |
| 2705 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2706 | &exception); |
| 2707 | } while (exception.retry); |
| 2708 | return err; |
| 2709 | } |
| 2710 | |
| 2711 | /* |
| 2712 | * The file is not closed if it is opened due to the a request to change |
| 2713 | * the size of the file. The open call will not be needed once the |
| 2714 | * VFS layer lookup-intents are implemented. |
| 2715 | * |
| 2716 | * Close is called when the inode is destroyed. |
| 2717 | * If we haven't opened the file for O_WRONLY, we |
| 2718 | * need to in the size_change case to obtain a stateid. |
| 2719 | * |
| 2720 | * Got race? |
| 2721 | * Because OPEN is always done by name in nfsv4, it is |
| 2722 | * possible that we opened a different file by the same |
| 2723 | * name. We can recognize this race condition, but we |
| 2724 | * can't do anything about it besides returning an error. |
| 2725 | * |
| 2726 | * This will be fixed with VFS changes (lookup-intent). |
| 2727 | */ |
| 2728 | static int |
| 2729 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2730 | struct iattr *sattr) |
| 2731 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2732 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2733 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2734 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | int status; |
| 2736 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2737 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2738 | pnfs_return_layout(inode); |
| 2739 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2740 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2742 | /* Deal with open(O_TRUNC) */ |
| 2743 | if (sattr->ia_valid & ATTR_OPEN) |
| 2744 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2745 | |
| 2746 | /* Optimization: if the end result is no change, don't RPC */ |
| 2747 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2748 | return 0; |
| 2749 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2750 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2751 | if (sattr->ia_valid & ATTR_FILE) { |
| 2752 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2753 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2754 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2755 | if (ctx) { |
| 2756 | cred = ctx->cred; |
| 2757 | state = ctx->state; |
| 2758 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2762 | if (status == 0) |
| 2763 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | return status; |
| 2765 | } |
| 2766 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2767 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2768 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2769 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2770 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2771 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2772 | int status; |
| 2773 | struct nfs4_lookup_arg args = { |
| 2774 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2775 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2776 | .name = name, |
| 2777 | }; |
| 2778 | struct nfs4_lookup_res res = { |
| 2779 | .server = server, |
| 2780 | .fattr = fattr, |
| 2781 | .fh = fhandle, |
| 2782 | }; |
| 2783 | struct rpc_message msg = { |
| 2784 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2785 | .rpc_argp = &args, |
| 2786 | .rpc_resp = &res, |
| 2787 | }; |
| 2788 | |
| 2789 | nfs_fattr_init(fattr); |
| 2790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2792 | 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] | 2793 | dprintk("NFS reply lookup: %d\n", status); |
| 2794 | return status; |
| 2795 | } |
| 2796 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2797 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2798 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2799 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2800 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2801 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2802 | fattr->nlink = 2; |
| 2803 | } |
| 2804 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2805 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2806 | struct qstr *name, struct nfs_fh *fhandle, |
| 2807 | struct nfs_fattr *fattr) |
| 2808 | { |
| 2809 | struct nfs4_exception exception = { }; |
| 2810 | struct rpc_clnt *client = *clnt; |
| 2811 | int err; |
| 2812 | do { |
| 2813 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2814 | switch (err) { |
| 2815 | case -NFS4ERR_BADNAME: |
| 2816 | err = -ENOENT; |
| 2817 | goto out; |
| 2818 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2819 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2820 | goto out; |
| 2821 | case -NFS4ERR_WRONGSEC: |
| 2822 | err = -EPERM; |
| 2823 | if (client != *clnt) |
| 2824 | goto out; |
| 2825 | |
| 2826 | client = nfs4_create_sec_client(client, dir, name); |
| 2827 | if (IS_ERR(client)) |
| 2828 | return PTR_ERR(client); |
| 2829 | |
| 2830 | exception.retry = 1; |
| 2831 | break; |
| 2832 | default: |
| 2833 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2834 | } |
| 2835 | } while (exception.retry); |
| 2836 | |
| 2837 | out: |
| 2838 | if (err == 0) |
| 2839 | *clnt = client; |
| 2840 | else if (client != *clnt) |
| 2841 | rpc_shutdown_client(client); |
| 2842 | |
| 2843 | return err; |
| 2844 | } |
| 2845 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2846 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2847 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2849 | int status; |
| 2850 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2851 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2852 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2853 | if (client != NFS_CLIENT(dir)) { |
| 2854 | rpc_shutdown_client(client); |
| 2855 | nfs_fixup_secinfo_attributes(fattr); |
| 2856 | } |
| 2857 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2860 | struct rpc_clnt * |
| 2861 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2862 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2863 | { |
| 2864 | int status; |
| 2865 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2866 | |
| 2867 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2868 | if (status < 0) { |
| 2869 | rpc_shutdown_client(client); |
| 2870 | return ERR_PTR(status); |
| 2871 | } |
| 2872 | return client; |
| 2873 | } |
| 2874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2876 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2877 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | struct nfs4_accessargs args = { |
| 2879 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2880 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2882 | struct nfs4_accessres res = { |
| 2883 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2884 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | struct rpc_message msg = { |
| 2886 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2887 | .rpc_argp = &args, |
| 2888 | .rpc_resp = &res, |
| 2889 | .rpc_cred = entry->cred, |
| 2890 | }; |
| 2891 | int mode = entry->mask; |
| 2892 | int status; |
| 2893 | |
| 2894 | /* |
| 2895 | * Determine which access bits we want to ask for... |
| 2896 | */ |
| 2897 | if (mode & MAY_READ) |
| 2898 | args.access |= NFS4_ACCESS_READ; |
| 2899 | if (S_ISDIR(inode->i_mode)) { |
| 2900 | if (mode & MAY_WRITE) |
| 2901 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2902 | if (mode & MAY_EXEC) |
| 2903 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2904 | } else { |
| 2905 | if (mode & MAY_WRITE) |
| 2906 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2907 | if (mode & MAY_EXEC) |
| 2908 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2909 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2910 | |
| 2911 | res.fattr = nfs_alloc_fattr(); |
| 2912 | if (res.fattr == NULL) |
| 2913 | return -ENOMEM; |
| 2914 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2915 | 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] | 2916 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2917 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2918 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2920 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | return status; |
| 2922 | } |
| 2923 | |
| 2924 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2925 | { |
| 2926 | struct nfs4_exception exception = { }; |
| 2927 | int err; |
| 2928 | do { |
| 2929 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2930 | _nfs4_proc_access(inode, entry), |
| 2931 | &exception); |
| 2932 | } while (exception.retry); |
| 2933 | return err; |
| 2934 | } |
| 2935 | |
| 2936 | /* |
| 2937 | * TODO: For the time being, we don't try to get any attributes |
| 2938 | * along with any of the zero-copy operations READ, READDIR, |
| 2939 | * READLINK, WRITE. |
| 2940 | * |
| 2941 | * In the case of the first three, we want to put the GETATTR |
| 2942 | * after the read-type operation -- this is because it is hard |
| 2943 | * to predict the length of a GETATTR response in v4, and thus |
| 2944 | * align the READ data correctly. This means that the GETATTR |
| 2945 | * may end up partially falling into the page cache, and we should |
| 2946 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2947 | * To do this efficiently, we need to know the total length |
| 2948 | * of data received, which doesn't seem to be available outside |
| 2949 | * of the RPC layer. |
| 2950 | * |
| 2951 | * In the case of WRITE, we also want to put the GETATTR after |
| 2952 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2953 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | * |
| 2955 | * Both of these changes to the XDR layer would in fact be quite |
| 2956 | * minor, but I decided to leave them for a subsequent patch. |
| 2957 | */ |
| 2958 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2959 | unsigned int pgbase, unsigned int pglen) |
| 2960 | { |
| 2961 | struct nfs4_readlink args = { |
| 2962 | .fh = NFS_FH(inode), |
| 2963 | .pgbase = pgbase, |
| 2964 | .pglen = pglen, |
| 2965 | .pages = &page, |
| 2966 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2967 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | struct rpc_message msg = { |
| 2969 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2970 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2971 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | }; |
| 2973 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2974 | 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] | 2975 | } |
| 2976 | |
| 2977 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2978 | unsigned int pgbase, unsigned int pglen) |
| 2979 | { |
| 2980 | struct nfs4_exception exception = { }; |
| 2981 | int err; |
| 2982 | do { |
| 2983 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2984 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2985 | &exception); |
| 2986 | } while (exception.retry); |
| 2987 | return err; |
| 2988 | } |
| 2989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2991 | * 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] | 2992 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | static int |
| 2994 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2995 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2997 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | int status = 0; |
| 3000 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3001 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3002 | if (IS_ERR(ctx)) |
| 3003 | return PTR_ERR(ctx); |
| 3004 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3005 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 3006 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 3007 | flags, sattr, ctx->cred, |
| 3008 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 3009 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | if (IS_ERR(state)) { |
| 3011 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3012 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 3014 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 3015 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3016 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3018 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | return status; |
| 3020 | } |
| 3021 | |
| 3022 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3023 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3024 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3025 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3027 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3029 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3030 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3031 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3033 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3034 | .rpc_argp = &args, |
| 3035 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3037 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3038 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3039 | 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] | 3040 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3041 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | return status; |
| 3043 | } |
| 3044 | |
| 3045 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3046 | { |
| 3047 | struct nfs4_exception exception = { }; |
| 3048 | int err; |
| 3049 | do { |
| 3050 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3051 | _nfs4_proc_remove(dir, name), |
| 3052 | &exception); |
| 3053 | } while (exception.retry); |
| 3054 | return err; |
| 3055 | } |
| 3056 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3057 | 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] | 3058 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3059 | struct nfs_server *server = NFS_SERVER(dir); |
| 3060 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3061 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3063 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3065 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3068 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3069 | { |
| 3070 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3071 | &data->args.seq_args, |
| 3072 | &data->res.seq_res, |
| 3073 | task)) |
| 3074 | return; |
| 3075 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3078 | 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] | 3079 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3080 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3081 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3082 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3083 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3084 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3085 | return 0; |
| 3086 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3087 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3090 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3091 | { |
| 3092 | struct nfs_server *server = NFS_SERVER(dir); |
| 3093 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3094 | struct nfs_renameres *res = msg->rpc_resp; |
| 3095 | |
| 3096 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3097 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3098 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3099 | } |
| 3100 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3101 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3102 | { |
| 3103 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3104 | &data->args.seq_args, |
| 3105 | &data->res.seq_res, |
| 3106 | task)) |
| 3107 | return; |
| 3108 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3112 | struct inode *new_dir) |
| 3113 | { |
| 3114 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3115 | |
| 3116 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3117 | return 0; |
| 3118 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3119 | return 0; |
| 3120 | |
| 3121 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3122 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3123 | return 1; |
| 3124 | } |
| 3125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3127 | struct inode *new_dir, struct qstr *new_name) |
| 3128 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3129 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3130 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | .old_dir = NFS_FH(old_dir), |
| 3132 | .new_dir = NFS_FH(new_dir), |
| 3133 | .old_name = old_name, |
| 3134 | .new_name = new_name, |
| 3135 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3136 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3137 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3138 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | struct rpc_message msg = { |
| 3140 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3141 | .rpc_argp = &arg, |
| 3142 | .rpc_resp = &res, |
| 3143 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3144 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3146 | 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] | 3147 | if (!status) { |
| 3148 | update_changeattr(old_dir, &res.old_cinfo); |
| 3149 | update_changeattr(new_dir, &res.new_cinfo); |
| 3150 | } |
| 3151 | return status; |
| 3152 | } |
| 3153 | |
| 3154 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3155 | struct inode *new_dir, struct qstr *new_name) |
| 3156 | { |
| 3157 | struct nfs4_exception exception = { }; |
| 3158 | int err; |
| 3159 | do { |
| 3160 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3161 | _nfs4_proc_rename(old_dir, old_name, |
| 3162 | new_dir, new_name), |
| 3163 | &exception); |
| 3164 | } while (exception.retry); |
| 3165 | return err; |
| 3166 | } |
| 3167 | |
| 3168 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3169 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3170 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | struct nfs4_link_arg arg = { |
| 3172 | .fh = NFS_FH(inode), |
| 3173 | .dir_fh = NFS_FH(dir), |
| 3174 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3175 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3177 | struct nfs4_link_res res = { |
| 3178 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3179 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | struct rpc_message msg = { |
| 3181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3182 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3183 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3185 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3187 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3188 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3189 | goto out; |
| 3190 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3191 | 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] | 3192 | if (!status) { |
| 3193 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3194 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3195 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3196 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3197 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | return status; |
| 3199 | } |
| 3200 | |
| 3201 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3202 | { |
| 3203 | struct nfs4_exception exception = { }; |
| 3204 | int err; |
| 3205 | do { |
| 3206 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3207 | _nfs4_proc_link(inode, dir, name), |
| 3208 | &exception); |
| 3209 | } while (exception.retry); |
| 3210 | return err; |
| 3211 | } |
| 3212 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3213 | struct nfs4_createdata { |
| 3214 | struct rpc_message msg; |
| 3215 | struct nfs4_create_arg arg; |
| 3216 | struct nfs4_create_res res; |
| 3217 | struct nfs_fh fh; |
| 3218 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3219 | }; |
| 3220 | |
| 3221 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3222 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3223 | { |
| 3224 | struct nfs4_createdata *data; |
| 3225 | |
| 3226 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3227 | if (data != NULL) { |
| 3228 | struct nfs_server *server = NFS_SERVER(dir); |
| 3229 | |
| 3230 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3231 | data->msg.rpc_argp = &data->arg; |
| 3232 | data->msg.rpc_resp = &data->res; |
| 3233 | data->arg.dir_fh = NFS_FH(dir); |
| 3234 | data->arg.server = server; |
| 3235 | data->arg.name = name; |
| 3236 | data->arg.attrs = sattr; |
| 3237 | data->arg.ftype = ftype; |
| 3238 | data->arg.bitmask = server->attr_bitmask; |
| 3239 | data->res.server = server; |
| 3240 | data->res.fh = &data->fh; |
| 3241 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3242 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3243 | } |
| 3244 | return data; |
| 3245 | } |
| 3246 | |
| 3247 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3248 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3249 | 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] | 3250 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3251 | if (status == 0) { |
| 3252 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3253 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3254 | } |
| 3255 | return status; |
| 3256 | } |
| 3257 | |
| 3258 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3259 | { |
| 3260 | kfree(data); |
| 3261 | } |
| 3262 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3263 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3264 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3266 | struct nfs4_createdata *data; |
| 3267 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3269 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3270 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3271 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3272 | status = -ENOMEM; |
| 3273 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3274 | if (data == NULL) |
| 3275 | goto out; |
| 3276 | |
| 3277 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3278 | data->arg.u.symlink.pages = &page; |
| 3279 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3281 | status = nfs4_do_create(dir, dentry, data); |
| 3282 | |
| 3283 | nfs4_free_createdata(data); |
| 3284 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | return status; |
| 3286 | } |
| 3287 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3288 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3289 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | { |
| 3291 | struct nfs4_exception exception = { }; |
| 3292 | int err; |
| 3293 | do { |
| 3294 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3295 | _nfs4_proc_symlink(dir, dentry, page, |
| 3296 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | &exception); |
| 3298 | } while (exception.retry); |
| 3299 | return err; |
| 3300 | } |
| 3301 | |
| 3302 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3303 | struct iattr *sattr) |
| 3304 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3305 | struct nfs4_createdata *data; |
| 3306 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3308 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3309 | if (data == NULL) |
| 3310 | goto out; |
| 3311 | |
| 3312 | status = nfs4_do_create(dir, dentry, data); |
| 3313 | |
| 3314 | nfs4_free_createdata(data); |
| 3315 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | return status; |
| 3317 | } |
| 3318 | |
| 3319 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3320 | struct iattr *sattr) |
| 3321 | { |
| 3322 | struct nfs4_exception exception = { }; |
| 3323 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3324 | |
| 3325 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | do { |
| 3327 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3328 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3329 | &exception); |
| 3330 | } while (exception.retry); |
| 3331 | return err; |
| 3332 | } |
| 3333 | |
| 3334 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3335 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | { |
| 3337 | struct inode *dir = dentry->d_inode; |
| 3338 | struct nfs4_readdir_arg args = { |
| 3339 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3340 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | .pgbase = 0, |
| 3342 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3343 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3344 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | }; |
| 3346 | struct nfs4_readdir_res res; |
| 3347 | struct rpc_message msg = { |
| 3348 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3349 | .rpc_argp = &args, |
| 3350 | .rpc_resp = &res, |
| 3351 | .rpc_cred = cred, |
| 3352 | }; |
| 3353 | int status; |
| 3354 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3355 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3356 | dentry->d_parent->d_name.name, |
| 3357 | dentry->d_name.name, |
| 3358 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3359 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3361 | 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] | 3362 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3363 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3364 | status += args.pgbase; |
| 3365 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3366 | |
| 3367 | nfs_invalidate_atime(dir); |
| 3368 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3369 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | return status; |
| 3371 | } |
| 3372 | |
| 3373 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3374 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | { |
| 3376 | struct nfs4_exception exception = { }; |
| 3377 | int err; |
| 3378 | do { |
| 3379 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3380 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3381 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | &exception); |
| 3383 | } while (exception.retry); |
| 3384 | return err; |
| 3385 | } |
| 3386 | |
| 3387 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3388 | struct iattr *sattr, dev_t rdev) |
| 3389 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3390 | struct nfs4_createdata *data; |
| 3391 | int mode = sattr->ia_mode; |
| 3392 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3394 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3395 | if (data == NULL) |
| 3396 | goto out; |
| 3397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3399 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3401 | data->arg.ftype = NF4BLK; |
| 3402 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3403 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | } |
| 3405 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3406 | data->arg.ftype = NF4CHR; |
| 3407 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3408 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3409 | } else if (!S_ISSOCK(mode)) { |
| 3410 | status = -EINVAL; |
| 3411 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3414 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3415 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3416 | nfs4_free_createdata(data); |
| 3417 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | return status; |
| 3419 | } |
| 3420 | |
| 3421 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3422 | struct iattr *sattr, dev_t rdev) |
| 3423 | { |
| 3424 | struct nfs4_exception exception = { }; |
| 3425 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3426 | |
| 3427 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | do { |
| 3429 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3430 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3431 | &exception); |
| 3432 | } while (exception.retry); |
| 3433 | return err; |
| 3434 | } |
| 3435 | |
| 3436 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3437 | struct nfs_fsstat *fsstat) |
| 3438 | { |
| 3439 | struct nfs4_statfs_arg args = { |
| 3440 | .fh = fhandle, |
| 3441 | .bitmask = server->attr_bitmask, |
| 3442 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3443 | struct nfs4_statfs_res res = { |
| 3444 | .fsstat = fsstat, |
| 3445 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | struct rpc_message msg = { |
| 3447 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3448 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3449 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | }; |
| 3451 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3452 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3453 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3457 | { |
| 3458 | struct nfs4_exception exception = { }; |
| 3459 | int err; |
| 3460 | do { |
| 3461 | err = nfs4_handle_exception(server, |
| 3462 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3463 | &exception); |
| 3464 | } while (exception.retry); |
| 3465 | return err; |
| 3466 | } |
| 3467 | |
| 3468 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3469 | struct nfs_fsinfo *fsinfo) |
| 3470 | { |
| 3471 | struct nfs4_fsinfo_arg args = { |
| 3472 | .fh = fhandle, |
| 3473 | .bitmask = server->attr_bitmask, |
| 3474 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3475 | struct nfs4_fsinfo_res res = { |
| 3476 | .fsinfo = fsinfo, |
| 3477 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | struct rpc_message msg = { |
| 3479 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3480 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3481 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | }; |
| 3483 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3484 | 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] | 3485 | } |
| 3486 | |
| 3487 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3488 | { |
| 3489 | struct nfs4_exception exception = { }; |
| 3490 | int err; |
| 3491 | |
| 3492 | do { |
| 3493 | err = nfs4_handle_exception(server, |
| 3494 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3495 | &exception); |
| 3496 | } while (exception.retry); |
| 3497 | return err; |
| 3498 | } |
| 3499 | |
| 3500 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3501 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3502 | int error; |
| 3503 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3504 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3505 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3506 | if (error == 0) { |
| 3507 | /* block layout checks this! */ |
| 3508 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3509 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3510 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3511 | |
| 3512 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3516 | struct nfs_pathconf *pathconf) |
| 3517 | { |
| 3518 | struct nfs4_pathconf_arg args = { |
| 3519 | .fh = fhandle, |
| 3520 | .bitmask = server->attr_bitmask, |
| 3521 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3522 | struct nfs4_pathconf_res res = { |
| 3523 | .pathconf = pathconf, |
| 3524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | struct rpc_message msg = { |
| 3526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3527 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3528 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | }; |
| 3530 | |
| 3531 | /* None of the pathconf attributes are mandatory to implement */ |
| 3532 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3533 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3534 | return 0; |
| 3535 | } |
| 3536 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3537 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3538 | 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] | 3539 | } |
| 3540 | |
| 3541 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3542 | struct nfs_pathconf *pathconf) |
| 3543 | { |
| 3544 | struct nfs4_exception exception = { }; |
| 3545 | int err; |
| 3546 | |
| 3547 | do { |
| 3548 | err = nfs4_handle_exception(server, |
| 3549 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3550 | &exception); |
| 3551 | } while (exception.retry); |
| 3552 | return err; |
| 3553 | } |
| 3554 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3555 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3556 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3557 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3558 | } |
| 3559 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3560 | 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] | 3561 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3562 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3564 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3565 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3566 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3568 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3569 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3571 | renew_lease(server, data->timestamp); |
| 3572 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | } |
| 3574 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3575 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3576 | { |
| 3577 | |
| 3578 | dprintk("--> %s\n", __func__); |
| 3579 | |
| 3580 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3581 | return -EAGAIN; |
| 3582 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3583 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3584 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3585 | } |
| 3586 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3587 | 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] | 3588 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3590 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3591 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3592 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3595 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3596 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3597 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3598 | &data->args.seq_args, |
| 3599 | &data->res.seq_res, |
| 3600 | task)) |
| 3601 | return; |
| 3602 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3605 | 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] | 3606 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3607 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3609 | 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] | 3610 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3611 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3613 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3615 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3616 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3617 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3620 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3621 | { |
| 3622 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3623 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3624 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3625 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3626 | } |
| 3627 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3628 | static |
| 3629 | 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] | 3630 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3631 | const struct nfs_pgio_header *hdr = data->header; |
| 3632 | |
| 3633 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3634 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3635 | return false; |
| 3636 | /* Otherwise, request attributes if and only if we don't hold |
| 3637 | * a delegation |
| 3638 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3639 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3640 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3641 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3642 | 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] | 3643 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3644 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3645 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3646 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3647 | data->args.bitmask = NULL; |
| 3648 | data->res.fattr = NULL; |
| 3649 | } else |
| 3650 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3651 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3652 | if (!data->write_done_cb) |
| 3653 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3654 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | data->timestamp = jiffies; |
| 3656 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3657 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3658 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3661 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3662 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3663 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3664 | &data->args.seq_args, |
| 3665 | &data->res.seq_res, |
| 3666 | task)) |
| 3667 | return; |
| 3668 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3671 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3672 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3674 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3675 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | return; |
| 3678 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3679 | } |
| 3680 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3681 | 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] | 3682 | { |
| 3683 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3684 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3685 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3686 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3687 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3689 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3692 | 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] | 3693 | { |
| 3694 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3695 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3696 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3697 | } |
| 3698 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3699 | 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] | 3700 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3701 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3702 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3703 | if (data->commit_done_cb == NULL) |
| 3704 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3705 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3706 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3707 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | } |
| 3709 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3710 | struct nfs4_renewdata { |
| 3711 | struct nfs_client *client; |
| 3712 | unsigned long timestamp; |
| 3713 | }; |
| 3714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | /* |
| 3716 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3717 | * standalone procedure for queueing an asynchronous RENEW. |
| 3718 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3719 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3720 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3721 | struct nfs4_renewdata *data = calldata; |
| 3722 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3723 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3724 | if (atomic_read(&clp->cl_count) > 1) |
| 3725 | nfs4_schedule_state_renewal(clp); |
| 3726 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3727 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3728 | } |
| 3729 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3730 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3732 | struct nfs4_renewdata *data = calldata; |
| 3733 | struct nfs_client *clp = data->client; |
| 3734 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
| 3736 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3737 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3738 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3739 | return; |
| 3740 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3741 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3742 | return; |
| 3743 | } |
| 3744 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3746 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3749 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3750 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3751 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3752 | }; |
| 3753 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3754 | 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] | 3755 | { |
| 3756 | struct rpc_message msg = { |
| 3757 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3758 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3759 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3761 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3763 | if (renew_flags == 0) |
| 3764 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3765 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3766 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3767 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3768 | if (data == NULL) |
| 3769 | return -ENOMEM; |
| 3770 | data->client = clp; |
| 3771 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3773 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3776 | 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] | 3777 | { |
| 3778 | struct rpc_message msg = { |
| 3779 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3780 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3781 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | }; |
| 3783 | unsigned long now = jiffies; |
| 3784 | int status; |
| 3785 | |
| 3786 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3787 | if (status < 0) |
| 3788 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3789 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | return 0; |
| 3791 | } |
| 3792 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3793 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3794 | { |
| 3795 | return (server->caps & NFS_CAP_ACLS) |
| 3796 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3797 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3798 | } |
| 3799 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3800 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3801 | * 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] | 3802 | * the stack. |
| 3803 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3804 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3805 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3806 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3807 | struct page **pages, unsigned int *pgbase) |
| 3808 | { |
| 3809 | struct page *newpage, **spages; |
| 3810 | int rc = 0; |
| 3811 | size_t len; |
| 3812 | spages = pages; |
| 3813 | |
| 3814 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3815 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3816 | newpage = alloc_page(GFP_KERNEL); |
| 3817 | |
| 3818 | if (newpage == NULL) |
| 3819 | goto unwind; |
| 3820 | memcpy(page_address(newpage), buf, len); |
| 3821 | buf += len; |
| 3822 | buflen -= len; |
| 3823 | *pages++ = newpage; |
| 3824 | rc++; |
| 3825 | } while (buflen != 0); |
| 3826 | |
| 3827 | return rc; |
| 3828 | |
| 3829 | unwind: |
| 3830 | for(; rc > 0; rc--) |
| 3831 | __free_page(spages[rc-1]); |
| 3832 | return -ENOMEM; |
| 3833 | } |
| 3834 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3835 | struct nfs4_cached_acl { |
| 3836 | int cached; |
| 3837 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3838 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3839 | }; |
| 3840 | |
| 3841 | 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] | 3842 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3843 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3844 | |
| 3845 | spin_lock(&inode->i_lock); |
| 3846 | kfree(nfsi->nfs4_acl); |
| 3847 | nfsi->nfs4_acl = acl; |
| 3848 | spin_unlock(&inode->i_lock); |
| 3849 | } |
| 3850 | |
| 3851 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3852 | { |
| 3853 | nfs4_set_cached_acl(inode, NULL); |
| 3854 | } |
| 3855 | |
| 3856 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3857 | { |
| 3858 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3859 | struct nfs4_cached_acl *acl; |
| 3860 | int ret = -ENOENT; |
| 3861 | |
| 3862 | spin_lock(&inode->i_lock); |
| 3863 | acl = nfsi->nfs4_acl; |
| 3864 | if (acl == NULL) |
| 3865 | goto out; |
| 3866 | if (buf == NULL) /* user is just asking for length */ |
| 3867 | goto out_len; |
| 3868 | if (acl->cached == 0) |
| 3869 | goto out; |
| 3870 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3871 | if (acl->len > buflen) |
| 3872 | goto out; |
| 3873 | memcpy(buf, acl->data, acl->len); |
| 3874 | out_len: |
| 3875 | ret = acl->len; |
| 3876 | out: |
| 3877 | spin_unlock(&inode->i_lock); |
| 3878 | return ret; |
| 3879 | } |
| 3880 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3881 | 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] | 3882 | { |
| 3883 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3884 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3885 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3886 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3887 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3888 | if (acl == NULL) |
| 3889 | goto out; |
| 3890 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3891 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3892 | } else { |
| 3893 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3894 | if (acl == NULL) |
| 3895 | goto out; |
| 3896 | acl->cached = 0; |
| 3897 | } |
| 3898 | acl->len = acl_len; |
| 3899 | out: |
| 3900 | nfs4_set_cached_acl(inode, acl); |
| 3901 | } |
| 3902 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3903 | /* |
| 3904 | * The getxattr API returns the required buffer length when called with a |
| 3905 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3906 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3907 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3908 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3909 | * the cache. If not so, we throw away the page, and cache the required |
| 3910 | * length. The next getxattr call will then produce another round trip to |
| 3911 | * the server, this time with the input buf of the required size. |
| 3912 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3913 | 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] | 3914 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3915 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3916 | struct nfs_getaclargs args = { |
| 3917 | .fh = NFS_FH(inode), |
| 3918 | .acl_pages = pages, |
| 3919 | .acl_len = buflen, |
| 3920 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3921 | struct nfs_getaclres res = { |
| 3922 | .acl_len = buflen, |
| 3923 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3924 | struct rpc_message msg = { |
| 3925 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3926 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3927 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3928 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3929 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3930 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3931 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3932 | /* As long as we're doing a round trip to the server anyway, |
| 3933 | * let's be prepared for a page of acl data. */ |
| 3934 | if (npages == 0) |
| 3935 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3936 | if (npages > ARRAY_SIZE(pages)) |
| 3937 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3938 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3939 | for (i = 0; i < npages; i++) { |
| 3940 | pages[i] = alloc_page(GFP_KERNEL); |
| 3941 | if (!pages[i]) |
| 3942 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3943 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3944 | |
| 3945 | /* for decoding across pages */ |
| 3946 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3947 | if (!res.acl_scratch) |
| 3948 | goto out_free; |
| 3949 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3950 | args.acl_len = npages * PAGE_SIZE; |
| 3951 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3952 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3953 | 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] | 3954 | __func__, buf, buflen, npages, args.acl_len); |
| 3955 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3956 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3957 | if (ret) |
| 3958 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3959 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3960 | /* Handle the case where the passed-in buffer is too short */ |
| 3961 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3962 | /* Did the user only issue a request for the acl length? */ |
| 3963 | if (buf == NULL) |
| 3964 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3965 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3966 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3967 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3968 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3969 | if (buf) |
| 3970 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3971 | out_ok: |
| 3972 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3973 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3974 | for (i = 0; i < npages; i++) |
| 3975 | if (pages[i]) |
| 3976 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3977 | if (res.acl_scratch) |
| 3978 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3979 | return ret; |
| 3980 | } |
| 3981 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3982 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3983 | { |
| 3984 | struct nfs4_exception exception = { }; |
| 3985 | ssize_t ret; |
| 3986 | do { |
| 3987 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3988 | if (ret >= 0) |
| 3989 | break; |
| 3990 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3991 | } while (exception.retry); |
| 3992 | return ret; |
| 3993 | } |
| 3994 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3995 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3996 | { |
| 3997 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3998 | int ret; |
| 3999 | |
| 4000 | if (!nfs4_server_supports_acls(server)) |
| 4001 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4002 | ret = nfs_revalidate_inode(server, inode); |
| 4003 | if (ret < 0) |
| 4004 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4005 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4006 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4007 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4008 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4009 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4010 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4011 | return ret; |
| 4012 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4013 | } |
| 4014 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4015 | 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] | 4016 | { |
| 4017 | struct nfs_server *server = NFS_SERVER(inode); |
| 4018 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4019 | struct nfs_setaclargs arg = { |
| 4020 | .fh = NFS_FH(inode), |
| 4021 | .acl_pages = pages, |
| 4022 | .acl_len = buflen, |
| 4023 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4024 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4025 | struct rpc_message msg = { |
| 4026 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4027 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4028 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4029 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4030 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4031 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4032 | |
| 4033 | if (!nfs4_server_supports_acls(server)) |
| 4034 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4035 | if (npages > ARRAY_SIZE(pages)) |
| 4036 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4037 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4038 | if (i < 0) |
| 4039 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4040 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4041 | 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] | 4042 | |
| 4043 | /* |
| 4044 | * Free each page after tx, so the only ref left is |
| 4045 | * held by the network stack |
| 4046 | */ |
| 4047 | for (; i > 0; i--) |
| 4048 | put_page(pages[i-1]); |
| 4049 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4050 | /* |
| 4051 | * Acl update can result in inode attribute update. |
| 4052 | * so mark the attribute cache invalid. |
| 4053 | */ |
| 4054 | spin_lock(&inode->i_lock); |
| 4055 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4056 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4057 | nfs_access_zap_cache(inode); |
| 4058 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4059 | return ret; |
| 4060 | } |
| 4061 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4062 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4063 | { |
| 4064 | struct nfs4_exception exception = { }; |
| 4065 | int err; |
| 4066 | do { |
| 4067 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4068 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4069 | &exception); |
| 4070 | } while (exception.retry); |
| 4071 | return err; |
| 4072 | } |
| 4073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4075 | 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] | 4076 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4077 | struct nfs_client *clp = server->nfs_client; |
| 4078 | |
| 4079 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | return 0; |
| 4081 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4082 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4083 | case -NFS4ERR_ADMIN_REVOKED: |
| 4084 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4085 | if (state == NULL) |
| 4086 | break; |
| 4087 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4088 | case -NFS4ERR_OPENMODE: |
| 4089 | if (state == NULL) |
| 4090 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4091 | nfs4_schedule_stateid_recovery(server, state); |
| 4092 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4093 | case -NFS4ERR_EXPIRED: |
| 4094 | if (state != NULL) |
| 4095 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4097 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4098 | nfs4_schedule_lease_recovery(clp); |
| 4099 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4100 | #if defined(CONFIG_NFS_V4_1) |
| 4101 | case -NFS4ERR_BADSESSION: |
| 4102 | case -NFS4ERR_BADSLOT: |
| 4103 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4104 | case -NFS4ERR_DEADSESSION: |
| 4105 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4106 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4107 | case -NFS4ERR_SEQ_MISORDERED: |
| 4108 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4109 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4110 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4111 | task->tk_status = 0; |
| 4112 | return -EAGAIN; |
| 4113 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4115 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4116 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4117 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4119 | task->tk_status = 0; |
| 4120 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4121 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | case -NFS4ERR_OLD_STATEID: |
| 4123 | task->tk_status = 0; |
| 4124 | return -EAGAIN; |
| 4125 | } |
| 4126 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4127 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4128 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4129 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4130 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4131 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4132 | task->tk_status = 0; |
| 4133 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | } |
| 4135 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4136 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4137 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4138 | { |
| 4139 | __be32 verf[2]; |
| 4140 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4141 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4142 | /* An impossible timestamp guarantees this value |
| 4143 | * will never match a generated boot time. */ |
| 4144 | verf[0] = 0; |
| 4145 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4146 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4147 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4148 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4149 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4150 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4151 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4152 | } |
| 4153 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4154 | static unsigned int |
| 4155 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4156 | char *buf, size_t len) |
| 4157 | { |
| 4158 | unsigned int result; |
| 4159 | |
| 4160 | rcu_read_lock(); |
| 4161 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4162 | clp->cl_ipaddr, |
| 4163 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4164 | RPC_DISPLAY_ADDR), |
| 4165 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4166 | RPC_DISPLAY_PROTO)); |
| 4167 | rcu_read_unlock(); |
| 4168 | return result; |
| 4169 | } |
| 4170 | |
| 4171 | static unsigned int |
| 4172 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4173 | char *buf, size_t len) |
| 4174 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4175 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4176 | |
| 4177 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4178 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4179 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4180 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4181 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4182 | } |
| 4183 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4184 | /** |
| 4185 | * nfs4_proc_setclientid - Negotiate client ID |
| 4186 | * @clp: state data structure |
| 4187 | * @program: RPC program for NFSv4 callback service |
| 4188 | * @port: IP port number for NFS4 callback service |
| 4189 | * @cred: RPC credential to use for this call |
| 4190 | * @res: where to place the result |
| 4191 | * |
| 4192 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4193 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4194 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4195 | unsigned short port, struct rpc_cred *cred, |
| 4196 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | { |
| 4198 | nfs4_verifier sc_verifier; |
| 4199 | struct nfs4_setclientid setclientid = { |
| 4200 | .sc_verifier = &sc_verifier, |
| 4201 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4202 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | }; |
| 4204 | struct rpc_message msg = { |
| 4205 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4206 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4207 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4208 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4210 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4212 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4213 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4214 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4215 | setclientid.sc_name_len = |
| 4216 | nfs4_init_uniform_client_string(clp, |
| 4217 | setclientid.sc_name, |
| 4218 | sizeof(setclientid.sc_name)); |
| 4219 | else |
| 4220 | setclientid.sc_name_len = |
| 4221 | nfs4_init_nonuniform_client_string(clp, |
| 4222 | setclientid.sc_name, |
| 4223 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4224 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4225 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4226 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4227 | sizeof(setclientid.sc_netid), |
| 4228 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4229 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4230 | rcu_read_unlock(); |
| 4231 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4232 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4234 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4235 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4236 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4237 | setclientid.sc_name_len, setclientid.sc_name); |
| 4238 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4239 | dprintk("NFS reply setclientid: %d\n", status); |
| 4240 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | } |
| 4242 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4243 | /** |
| 4244 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4245 | * @clp: state data structure |
| 4246 | * @res: result of a previous SETCLIENTID |
| 4247 | * @cred: RPC credential to use for this call |
| 4248 | * |
| 4249 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4250 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4251 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4252 | struct nfs4_setclientid_res *arg, |
| 4253 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | { |
| 4255 | struct nfs_fsinfo fsinfo; |
| 4256 | struct rpc_message msg = { |
| 4257 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4258 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4260 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | }; |
| 4262 | unsigned long now; |
| 4263 | int status; |
| 4264 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4265 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4266 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4267 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4269 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | if (status == 0) { |
| 4271 | spin_lock(&clp->cl_lock); |
| 4272 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4273 | clp->cl_last_renewal = now; |
| 4274 | spin_unlock(&clp->cl_lock); |
| 4275 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4276 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | return status; |
| 4278 | } |
| 4279 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4280 | struct nfs4_delegreturndata { |
| 4281 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4282 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4283 | struct nfs_fh fh; |
| 4284 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4285 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4286 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4287 | int rpc_status; |
| 4288 | }; |
| 4289 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4290 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4291 | { |
| 4292 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4293 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4294 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4295 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4296 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4297 | switch (task->tk_status) { |
| 4298 | case -NFS4ERR_STALE_STATEID: |
| 4299 | case -NFS4ERR_EXPIRED: |
| 4300 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4301 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4302 | break; |
| 4303 | default: |
| 4304 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4305 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4306 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4307 | return; |
| 4308 | } |
| 4309 | } |
| 4310 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | static void nfs4_delegreturn_release(void *calldata) |
| 4314 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4315 | kfree(calldata); |
| 4316 | } |
| 4317 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4318 | #if defined(CONFIG_NFS_V4_1) |
| 4319 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4320 | { |
| 4321 | struct nfs4_delegreturndata *d_data; |
| 4322 | |
| 4323 | d_data = (struct nfs4_delegreturndata *)data; |
| 4324 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4325 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4326 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4327 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4328 | return; |
| 4329 | rpc_call_start(task); |
| 4330 | } |
| 4331 | #endif /* CONFIG_NFS_V4_1 */ |
| 4332 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4333 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4334 | #if defined(CONFIG_NFS_V4_1) |
| 4335 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4336 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4337 | .rpc_call_done = nfs4_delegreturn_done, |
| 4338 | .rpc_release = nfs4_delegreturn_release, |
| 4339 | }; |
| 4340 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4341 | 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] | 4342 | { |
| 4343 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4344 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4345 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4346 | struct rpc_message msg = { |
| 4347 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4348 | .rpc_cred = cred, |
| 4349 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4350 | struct rpc_task_setup task_setup_data = { |
| 4351 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4352 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4353 | .callback_ops = &nfs4_delegreturn_ops, |
| 4354 | .flags = RPC_TASK_ASYNC, |
| 4355 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4356 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4357 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4358 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4359 | if (data == NULL) |
| 4360 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4361 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4362 | data->args.fhandle = &data->fh; |
| 4363 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4364 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4365 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4366 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4367 | data->res.fattr = &data->fattr; |
| 4368 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4369 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4370 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4371 | data->rpc_status = 0; |
| 4372 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4373 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4374 | msg.rpc_argp = &data->args; |
| 4375 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4376 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4377 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4378 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4379 | if (!issync) |
| 4380 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4381 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4382 | if (status != 0) |
| 4383 | goto out; |
| 4384 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4385 | if (status == 0) |
| 4386 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4387 | else |
| 4388 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4389 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4390 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4391 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | } |
| 4393 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4394 | 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] | 4395 | { |
| 4396 | struct nfs_server *server = NFS_SERVER(inode); |
| 4397 | struct nfs4_exception exception = { }; |
| 4398 | int err; |
| 4399 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4400 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | switch (err) { |
| 4402 | case -NFS4ERR_STALE_STATEID: |
| 4403 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | case 0: |
| 4405 | return 0; |
| 4406 | } |
| 4407 | err = nfs4_handle_exception(server, err, &exception); |
| 4408 | } while (exception.retry); |
| 4409 | return err; |
| 4410 | } |
| 4411 | |
| 4412 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4413 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4414 | |
| 4415 | /* |
| 4416 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4417 | */ |
| 4418 | static unsigned long |
| 4419 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4420 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4421 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | timeout <<= 1; |
| 4423 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4424 | return NFS4_LOCK_MAXTIMEOUT; |
| 4425 | return timeout; |
| 4426 | } |
| 4427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4429 | { |
| 4430 | struct inode *inode = state->inode; |
| 4431 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4432 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4433 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4435 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4437 | struct nfs_lockt_res res = { |
| 4438 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | }; |
| 4440 | struct rpc_message msg = { |
| 4441 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4442 | .rpc_argp = &arg, |
| 4443 | .rpc_resp = &res, |
| 4444 | .rpc_cred = state->owner->so_cred, |
| 4445 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | struct nfs4_lock_state *lsp; |
| 4447 | int status; |
| 4448 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4449 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4450 | status = nfs4_set_lock_state(state, request); |
| 4451 | if (status != 0) |
| 4452 | goto out; |
| 4453 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4454 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4455 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4456 | 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] | 4457 | switch (status) { |
| 4458 | case 0: |
| 4459 | request->fl_type = F_UNLCK; |
| 4460 | break; |
| 4461 | case -NFS4ERR_DENIED: |
| 4462 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4464 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4465 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | return status; |
| 4467 | } |
| 4468 | |
| 4469 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4470 | { |
| 4471 | struct nfs4_exception exception = { }; |
| 4472 | int err; |
| 4473 | |
| 4474 | do { |
| 4475 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4476 | _nfs4_proc_getlk(state, cmd, request), |
| 4477 | &exception); |
| 4478 | } while (exception.retry); |
| 4479 | return err; |
| 4480 | } |
| 4481 | |
| 4482 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4483 | { |
| 4484 | int res = 0; |
| 4485 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4486 | case FL_POSIX: |
| 4487 | res = posix_lock_file_wait(file, fl); |
| 4488 | break; |
| 4489 | case FL_FLOCK: |
| 4490 | res = flock_lock_file_wait(file, fl); |
| 4491 | break; |
| 4492 | default: |
| 4493 | BUG(); |
| 4494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | return res; |
| 4496 | } |
| 4497 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4498 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4499 | struct nfs_locku_args arg; |
| 4500 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4501 | struct nfs4_lock_state *lsp; |
| 4502 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4503 | struct file_lock fl; |
| 4504 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4505 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4506 | }; |
| 4507 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4508 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4509 | struct nfs_open_context *ctx, |
| 4510 | struct nfs4_lock_state *lsp, |
| 4511 | struct nfs_seqid *seqid) |
| 4512 | { |
| 4513 | struct nfs4_unlockdata *p; |
| 4514 | struct inode *inode = lsp->ls_state->inode; |
| 4515 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4516 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4517 | if (p == NULL) |
| 4518 | return NULL; |
| 4519 | p->arg.fh = NFS_FH(inode); |
| 4520 | p->arg.fl = &p->fl; |
| 4521 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4522 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4523 | p->arg.stateid = &lsp->ls_stateid; |
| 4524 | p->lsp = lsp; |
| 4525 | atomic_inc(&lsp->ls_count); |
| 4526 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4527 | p->ctx = get_nfs_open_context(ctx); |
| 4528 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4529 | p->server = NFS_SERVER(inode); |
| 4530 | return p; |
| 4531 | } |
| 4532 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4533 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4534 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4535 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4536 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4537 | nfs4_put_lock_state(calldata->lsp); |
| 4538 | put_nfs_open_context(calldata->ctx); |
| 4539 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4542 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4543 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4544 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4545 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4546 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4547 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4548 | switch (task->tk_status) { |
| 4549 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4550 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4551 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4552 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4553 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4554 | case -NFS4ERR_BAD_STATEID: |
| 4555 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4556 | case -NFS4ERR_STALE_STATEID: |
| 4557 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4558 | break; |
| 4559 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4560 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4561 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4562 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4563 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4564 | } |
| 4565 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4566 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4567 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4568 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4570 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4571 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4572 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4573 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4574 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4575 | return; |
| 4576 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4577 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4578 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4579 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4580 | &calldata->res.seq_res, |
| 4581 | task) != 0) |
| 4582 | nfs_release_seqid(calldata->arg.seqid); |
| 4583 | else |
| 4584 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4587 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4588 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4589 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4590 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4591 | }; |
| 4592 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4593 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4594 | struct nfs_open_context *ctx, |
| 4595 | struct nfs4_lock_state *lsp, |
| 4596 | struct nfs_seqid *seqid) |
| 4597 | { |
| 4598 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4599 | struct rpc_message msg = { |
| 4600 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4601 | .rpc_cred = ctx->cred, |
| 4602 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4603 | struct rpc_task_setup task_setup_data = { |
| 4604 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4605 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4606 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4607 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4608 | .flags = RPC_TASK_ASYNC, |
| 4609 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4610 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4611 | /* Ensure this is an unlock - when canceling a lock, the |
| 4612 | * canceled lock is passed in, and it won't be an unlock. |
| 4613 | */ |
| 4614 | fl->fl_type = F_UNLCK; |
| 4615 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4616 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4617 | if (data == NULL) { |
| 4618 | nfs_free_seqid(seqid); |
| 4619 | return ERR_PTR(-ENOMEM); |
| 4620 | } |
| 4621 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4622 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4623 | msg.rpc_argp = &data->arg; |
| 4624 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4625 | task_setup_data.callback_data = data; |
| 4626 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4627 | } |
| 4628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4630 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4631 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4632 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4633 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4634 | struct rpc_task *task; |
| 4635 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4636 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4638 | status = nfs4_set_lock_state(state, request); |
| 4639 | /* Unlock _before_ we do the RPC call */ |
| 4640 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4641 | down_read(&nfsi->rwsem); |
| 4642 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4643 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4644 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4645 | } |
| 4646 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4647 | if (status != 0) |
| 4648 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4649 | /* Is this a delegated lock? */ |
| 4650 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4651 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4652 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4653 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4654 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4655 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4656 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4657 | 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] | 4658 | status = PTR_ERR(task); |
| 4659 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4660 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4661 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4662 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4663 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4664 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4665 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4668 | struct nfs4_lockdata { |
| 4669 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4670 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4671 | struct nfs4_lock_state *lsp; |
| 4672 | struct nfs_open_context *ctx; |
| 4673 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4674 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4675 | int rpc_status; |
| 4676 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4677 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4678 | }; |
| 4679 | |
| 4680 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4681 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4682 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4683 | { |
| 4684 | struct nfs4_lockdata *p; |
| 4685 | struct inode *inode = lsp->ls_state->inode; |
| 4686 | struct nfs_server *server = NFS_SERVER(inode); |
| 4687 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4688 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4689 | if (p == NULL) |
| 4690 | return NULL; |
| 4691 | |
| 4692 | p->arg.fh = NFS_FH(inode); |
| 4693 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4694 | 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] | 4695 | if (p->arg.open_seqid == NULL) |
| 4696 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4697 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4698 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4699 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4700 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4701 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4702 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4703 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4704 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4705 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4706 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4707 | atomic_inc(&lsp->ls_count); |
| 4708 | p->ctx = get_nfs_open_context(ctx); |
| 4709 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4710 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4711 | out_free_seqid: |
| 4712 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4713 | out_free: |
| 4714 | kfree(p); |
| 4715 | return NULL; |
| 4716 | } |
| 4717 | |
| 4718 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4719 | { |
| 4720 | struct nfs4_lockdata *data = calldata; |
| 4721 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4723 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4724 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4725 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4726 | /* Do we need to do an open_to_lock_owner? */ |
| 4727 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4728 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4729 | goto out_release_lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4730 | data->arg.open_stateid = &state->stateid; |
| 4731 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4732 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4733 | } else |
| 4734 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4735 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4736 | if (nfs4_setup_sequence(data->server, |
| 4737 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4738 | &data->res.seq_res, |
| 4739 | task) == 0) { |
| 4740 | rpc_call_start(task); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4741 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4742 | } |
| 4743 | nfs_release_seqid(data->arg.open_seqid); |
| 4744 | out_release_lock_seqid: |
| 4745 | nfs_release_seqid(data->arg.lock_seqid); |
| 4746 | dprintk("%s: done!, ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4747 | } |
| 4748 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4749 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4750 | { |
| 4751 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4752 | nfs4_lock_prepare(task, calldata); |
| 4753 | } |
| 4754 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4755 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4756 | { |
| 4757 | struct nfs4_lockdata *data = calldata; |
| 4758 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4759 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4760 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4761 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4762 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4763 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4764 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4765 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4766 | if (data->rpc_status == 0) |
| 4767 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4768 | else |
| 4769 | goto out; |
| 4770 | } |
| 4771 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4772 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4773 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4774 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4775 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4776 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4777 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | static void nfs4_lock_release(void *calldata) |
| 4781 | { |
| 4782 | struct nfs4_lockdata *data = calldata; |
| 4783 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4784 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4785 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4786 | if (data->cancelled != 0) { |
| 4787 | struct rpc_task *task; |
| 4788 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4789 | data->arg.lock_seqid); |
| 4790 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4791 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4792 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4793 | } else |
| 4794 | nfs_free_seqid(data->arg.lock_seqid); |
| 4795 | nfs4_put_lock_state(data->lsp); |
| 4796 | put_nfs_open_context(data->ctx); |
| 4797 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4798 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4802 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4803 | .rpc_call_done = nfs4_lock_done, |
| 4804 | .rpc_release = nfs4_lock_release, |
| 4805 | }; |
| 4806 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4807 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4808 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4809 | .rpc_call_done = nfs4_lock_done, |
| 4810 | .rpc_release = nfs4_lock_release, |
| 4811 | }; |
| 4812 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4813 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4814 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4815 | switch (error) { |
| 4816 | case -NFS4ERR_ADMIN_REVOKED: |
| 4817 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4818 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4819 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4820 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4821 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4822 | break; |
| 4823 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4824 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4825 | case -NFS4ERR_EXPIRED: |
| 4826 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4827 | }; |
| 4828 | } |
| 4829 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4830 | 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] | 4831 | { |
| 4832 | struct nfs4_lockdata *data; |
| 4833 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4834 | struct rpc_message msg = { |
| 4835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4836 | .rpc_cred = state->owner->so_cred, |
| 4837 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4838 | struct rpc_task_setup task_setup_data = { |
| 4839 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4840 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4841 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4842 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4843 | .flags = RPC_TASK_ASYNC, |
| 4844 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4845 | int ret; |
| 4846 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4847 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4848 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4849 | fl->fl_u.nfs4_fl.owner, |
| 4850 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4851 | if (data == NULL) |
| 4852 | return -ENOMEM; |
| 4853 | if (IS_SETLKW(cmd)) |
| 4854 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4855 | if (recovery_type > NFS_LOCK_NEW) { |
| 4856 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4857 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4858 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4859 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4860 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4861 | msg.rpc_argp = &data->arg; |
| 4862 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4863 | task_setup_data.callback_data = data; |
| 4864 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4865 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4866 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4867 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4868 | if (ret == 0) { |
| 4869 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4870 | if (ret) |
| 4871 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4872 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4873 | } else |
| 4874 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4875 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4876 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4877 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4881 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4882 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4883 | struct nfs4_exception exception = { |
| 4884 | .inode = state->inode, |
| 4885 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4886 | int err; |
| 4887 | |
| 4888 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4889 | /* Cache the lock if possible... */ |
| 4890 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4891 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4892 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4893 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4894 | break; |
| 4895 | nfs4_handle_exception(server, err, &exception); |
| 4896 | } while (exception.retry); |
| 4897 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4901 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4902 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4903 | struct nfs4_exception exception = { |
| 4904 | .inode = state->inode, |
| 4905 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4906 | int err; |
| 4907 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4908 | err = nfs4_set_lock_state(state, request); |
| 4909 | if (err != 0) |
| 4910 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4911 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4912 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4913 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4914 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4915 | switch (err) { |
| 4916 | default: |
| 4917 | goto out; |
| 4918 | case -NFS4ERR_GRACE: |
| 4919 | case -NFS4ERR_DELAY: |
| 4920 | nfs4_handle_exception(server, err, &exception); |
| 4921 | err = 0; |
| 4922 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4923 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4924 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4925 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4928 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4929 | /** |
| 4930 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4931 | * |
| 4932 | * @state: NFSv4 state for an inode |
| 4933 | * |
| 4934 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4935 | * Otherwise a negative NFS4ERR value is returned. |
| 4936 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4937 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4938 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4939 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4940 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4941 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4942 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4943 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4944 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4945 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4946 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4947 | /* Free the stateid unless the server |
| 4948 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4949 | if (status != -NFS4ERR_BAD_STATEID) |
| 4950 | nfs41_free_stateid(server, |
| 4951 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4952 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4953 | ret = status; |
| 4954 | } |
| 4955 | } |
| 4956 | }; |
| 4957 | |
| 4958 | return ret; |
| 4959 | } |
| 4960 | |
| 4961 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4962 | { |
| 4963 | int status = NFS_OK; |
| 4964 | |
| 4965 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4966 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4967 | if (status != NFS_OK) |
| 4968 | status = nfs4_lock_expired(state, request); |
| 4969 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4970 | } |
| 4971 | #endif |
| 4972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4973 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4974 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4975 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4976 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4977 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4979 | if ((fl_flags & FL_POSIX) && |
| 4980 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4981 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4982 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4983 | status = nfs4_set_lock_state(state, request); |
| 4984 | if (status != 0) |
| 4985 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4986 | request->fl_flags |= FL_ACCESS; |
| 4987 | status = do_vfs_lock(request->fl_file, request); |
| 4988 | if (status < 0) |
| 4989 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4990 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4991 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4992 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4993 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4994 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4995 | status = do_vfs_lock(request->fl_file, request); |
| 4996 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4997 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4998 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4999 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5000 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5001 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5002 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5003 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5004 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5005 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5006 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5007 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5008 | out: |
| 5009 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | return status; |
| 5011 | } |
| 5012 | |
| 5013 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5014 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5015 | struct nfs4_exception exception = { |
| 5016 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5017 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5018 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | int err; |
| 5020 | |
| 5021 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5022 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5023 | if (err == -NFS4ERR_DENIED) |
| 5024 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5026 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | } while (exception.retry); |
| 5028 | return err; |
| 5029 | } |
| 5030 | |
| 5031 | static int |
| 5032 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5033 | { |
| 5034 | struct nfs_open_context *ctx; |
| 5035 | struct nfs4_state *state; |
| 5036 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5037 | int status; |
| 5038 | |
| 5039 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5040 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | state = ctx->state; |
| 5042 | |
| 5043 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5044 | return -EINVAL; |
| 5045 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5046 | if (IS_GETLK(cmd)) { |
| 5047 | if (state != NULL) |
| 5048 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5049 | return 0; |
| 5050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | |
| 5052 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5053 | return -EINVAL; |
| 5054 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5055 | if (request->fl_type == F_UNLCK) { |
| 5056 | if (state != NULL) |
| 5057 | return nfs4_proc_unlck(state, cmd, request); |
| 5058 | return 0; |
| 5059 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5061 | if (state == NULL) |
| 5062 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5063 | /* |
| 5064 | * Don't rely on the VFS having checked the file open mode, |
| 5065 | * since it won't do this for flock() locks. |
| 5066 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5067 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5068 | case F_RDLCK: |
| 5069 | if (!(filp->f_mode & FMODE_READ)) |
| 5070 | return -EBADF; |
| 5071 | break; |
| 5072 | case F_WRLCK: |
| 5073 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5074 | return -EBADF; |
| 5075 | } |
| 5076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | do { |
| 5078 | status = nfs4_proc_setlk(state, cmd, request); |
| 5079 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5080 | break; |
| 5081 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5082 | status = -ERESTARTSYS; |
| 5083 | if (signalled()) |
| 5084 | break; |
| 5085 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | return status; |
| 5087 | } |
| 5088 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5089 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5090 | { |
| 5091 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5092 | struct nfs4_exception exception = { }; |
| 5093 | int err; |
| 5094 | |
| 5095 | err = nfs4_set_lock_state(state, fl); |
| 5096 | if (err != 0) |
| 5097 | goto out; |
| 5098 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5099 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5100 | switch (err) { |
| 5101 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5102 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5103 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5104 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5105 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5106 | goto out; |
| 5107 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 5108 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5109 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5110 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5111 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5112 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5113 | case -NFS4ERR_BADSESSION: |
| 5114 | case -NFS4ERR_BADSLOT: |
| 5115 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5116 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5117 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5118 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5119 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5120 | case -ERESTARTSYS: |
| 5121 | /* |
| 5122 | * The show must go on: exit, but mark the |
| 5123 | * stateid as needing recovery. |
| 5124 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5125 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5126 | case -NFS4ERR_ADMIN_REVOKED: |
| 5127 | case -NFS4ERR_BAD_STATEID: |
| 5128 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5129 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5130 | err = 0; |
| 5131 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5132 | case -EKEYEXPIRED: |
| 5133 | /* |
| 5134 | * User RPCSEC_GSS context has expired. |
| 5135 | * We cannot recover this stateid now, so |
| 5136 | * skip it and allow recovery thread to |
| 5137 | * proceed. |
| 5138 | */ |
| 5139 | err = 0; |
| 5140 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5141 | case -ENOMEM: |
| 5142 | case -NFS4ERR_DENIED: |
| 5143 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5144 | err = 0; |
| 5145 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5146 | case -NFS4ERR_DELAY: |
| 5147 | break; |
| 5148 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5149 | err = nfs4_handle_exception(server, err, &exception); |
| 5150 | } while (exception.retry); |
| 5151 | out: |
| 5152 | return err; |
| 5153 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5154 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5155 | struct nfs_release_lockowner_data { |
| 5156 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5157 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5158 | struct nfs_release_lockowner_args args; |
| 5159 | }; |
| 5160 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5161 | static void nfs4_release_lockowner_release(void *calldata) |
| 5162 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5163 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5164 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5165 | kfree(calldata); |
| 5166 | } |
| 5167 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5168 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5169 | .rpc_release = nfs4_release_lockowner_release, |
| 5170 | }; |
| 5171 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5172 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5173 | { |
| 5174 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5175 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5176 | struct rpc_message msg = { |
| 5177 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5178 | }; |
| 5179 | |
| 5180 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5181 | return -EINVAL; |
| 5182 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5183 | if (!data) |
| 5184 | return -ENOMEM; |
| 5185 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5186 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5187 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5188 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5189 | data->args.lock_owner.s_dev = server->s_dev; |
| 5190 | msg.rpc_argp = &data->args; |
| 5191 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5192 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5193 | } |
| 5194 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5195 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5196 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5197 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5198 | const void *buf, size_t buflen, |
| 5199 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5200 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5201 | if (strcmp(key, "") != 0) |
| 5202 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5203 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5204 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5205 | } |
| 5206 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5207 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5208 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5209 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5210 | if (strcmp(key, "") != 0) |
| 5211 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5212 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5213 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5216 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5217 | size_t list_len, const char *name, |
| 5218 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5219 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5220 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5221 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5222 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5223 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5224 | |
| 5225 | if (list && len <= list_len) |
| 5226 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5227 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5230 | /* |
| 5231 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5232 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5233 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5234 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5235 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5236 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5237 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5238 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5239 | return; |
| 5240 | |
| 5241 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5242 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5243 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5244 | fattr->nlink = 2; |
| 5245 | } |
| 5246 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5247 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5248 | const struct qstr *name, |
| 5249 | struct nfs4_fs_locations *fs_locations, |
| 5250 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5251 | { |
| 5252 | struct nfs_server *server = NFS_SERVER(dir); |
| 5253 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5254 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5255 | }; |
| 5256 | struct nfs4_fs_locations_arg args = { |
| 5257 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5258 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5259 | .page = page, |
| 5260 | .bitmask = bitmask, |
| 5261 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5262 | struct nfs4_fs_locations_res res = { |
| 5263 | .fs_locations = fs_locations, |
| 5264 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5265 | struct rpc_message msg = { |
| 5266 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5267 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5268 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5269 | }; |
| 5270 | int status; |
| 5271 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5272 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5273 | |
| 5274 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5275 | * is not supported */ |
| 5276 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5277 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5278 | else |
| 5279 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5280 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5281 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5282 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5283 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5284 | 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] | 5285 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5286 | return status; |
| 5287 | } |
| 5288 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5289 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5290 | const struct qstr *name, |
| 5291 | struct nfs4_fs_locations *fs_locations, |
| 5292 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5293 | { |
| 5294 | struct nfs4_exception exception = { }; |
| 5295 | int err; |
| 5296 | do { |
| 5297 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5298 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5299 | &exception); |
| 5300 | } while (exception.retry); |
| 5301 | return err; |
| 5302 | } |
| 5303 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5304 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5305 | { |
| 5306 | int status; |
| 5307 | struct nfs4_secinfo_arg args = { |
| 5308 | .dir_fh = NFS_FH(dir), |
| 5309 | .name = name, |
| 5310 | }; |
| 5311 | struct nfs4_secinfo_res res = { |
| 5312 | .flavors = flavors, |
| 5313 | }; |
| 5314 | struct rpc_message msg = { |
| 5315 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5316 | .rpc_argp = &args, |
| 5317 | .rpc_resp = &res, |
| 5318 | }; |
| 5319 | |
| 5320 | dprintk("NFS call secinfo %s\n", name->name); |
| 5321 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5322 | dprintk("NFS reply secinfo: %d\n", status); |
| 5323 | return status; |
| 5324 | } |
| 5325 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5326 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5327 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5328 | { |
| 5329 | struct nfs4_exception exception = { }; |
| 5330 | int err; |
| 5331 | do { |
| 5332 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5333 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5334 | &exception); |
| 5335 | } while (exception.retry); |
| 5336 | return err; |
| 5337 | } |
| 5338 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5339 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5340 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5341 | * Check the exchange flags returned by the server for invalid flags, having |
| 5342 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5343 | * DS flags set. |
| 5344 | */ |
| 5345 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5346 | { |
| 5347 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5348 | goto out_inval; |
| 5349 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5350 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5351 | goto out_inval; |
| 5352 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5353 | goto out_inval; |
| 5354 | return NFS_OK; |
| 5355 | out_inval: |
| 5356 | return -NFS4ERR_INVAL; |
| 5357 | } |
| 5358 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5359 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5360 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5361 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5362 | { |
| 5363 | if (a->server_scope_sz == b->server_scope_sz && |
| 5364 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5365 | return true; |
| 5366 | |
| 5367 | return false; |
| 5368 | } |
| 5369 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5370 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5371 | * nfs4_proc_bind_conn_to_session() |
| 5372 | * |
| 5373 | * The 4.1 client currently uses the same TCP connection for the |
| 5374 | * fore and backchannel. |
| 5375 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5376 | 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] | 5377 | { |
| 5378 | int status; |
| 5379 | struct nfs41_bind_conn_to_session_res res; |
| 5380 | struct rpc_message msg = { |
| 5381 | .rpc_proc = |
| 5382 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5383 | .rpc_argp = clp, |
| 5384 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5385 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5386 | }; |
| 5387 | |
| 5388 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5389 | |
| 5390 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5391 | if (unlikely(res.session == NULL)) { |
| 5392 | status = -ENOMEM; |
| 5393 | goto out; |
| 5394 | } |
| 5395 | |
| 5396 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5397 | if (status == 0) { |
| 5398 | if (memcmp(res.session->sess_id.data, |
| 5399 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5400 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5401 | status = -EIO; |
| 5402 | goto out_session; |
| 5403 | } |
| 5404 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5405 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5406 | __func__); |
| 5407 | status = -EIO; |
| 5408 | goto out_session; |
| 5409 | } |
| 5410 | if (res.use_conn_in_rdma_mode) { |
| 5411 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5412 | __func__); |
| 5413 | status = -EIO; |
| 5414 | goto out_session; |
| 5415 | } |
| 5416 | } |
| 5417 | out_session: |
| 5418 | kfree(res.session); |
| 5419 | out: |
| 5420 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5421 | return status; |
| 5422 | } |
| 5423 | |
| 5424 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5425 | * nfs4_proc_exchange_id() |
| 5426 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5427 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5428 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5429 | * Since the clientid has expired, all compounds using sessions |
| 5430 | * associated with the stale clientid will be returning |
| 5431 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5432 | * be in some phase of session reset. |
| 5433 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5434 | 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] | 5435 | { |
| 5436 | nfs4_verifier verifier; |
| 5437 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5438 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5439 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5440 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5441 | }; |
| 5442 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5443 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5444 | }; |
| 5445 | int status; |
| 5446 | struct rpc_message msg = { |
| 5447 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5448 | .rpc_argp = &args, |
| 5449 | .rpc_resp = &res, |
| 5450 | .rpc_cred = cred, |
| 5451 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5452 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5453 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5454 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5455 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5456 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5457 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5458 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5459 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5460 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5461 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5462 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5463 | status = -ENOMEM; |
| 5464 | goto out; |
| 5465 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5466 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5467 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5468 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5469 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5470 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5471 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5472 | } |
| 5473 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5474 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5475 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5476 | status = -ENOMEM; |
| 5477 | goto out_server_scope; |
| 5478 | } |
| 5479 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5480 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5481 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5482 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5483 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5484 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5485 | clp->cl_clientid = res.clientid; |
| 5486 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5487 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5488 | clp->cl_seqid = res.seqid; |
| 5489 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5490 | kfree(clp->cl_serverowner); |
| 5491 | clp->cl_serverowner = res.server_owner; |
| 5492 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5493 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5494 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5495 | kfree(clp->cl_implid); |
| 5496 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5497 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5498 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5499 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5500 | res.server_scope)) { |
| 5501 | dprintk("%s: server_scope mismatch detected\n", |
| 5502 | __func__); |
| 5503 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5504 | kfree(clp->cl_serverscope); |
| 5505 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5506 | } |
| 5507 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5508 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5509 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5510 | goto out; |
| 5511 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5512 | } else |
| 5513 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5514 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5515 | out_server_owner: |
| 5516 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5517 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5518 | kfree(res.server_scope); |
| 5519 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5520 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5521 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5522 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5523 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5524 | clp->cl_implid->date.seconds, |
| 5525 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5526 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5527 | return status; |
| 5528 | } |
| 5529 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5530 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5531 | struct rpc_cred *cred) |
| 5532 | { |
| 5533 | struct rpc_message msg = { |
| 5534 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5535 | .rpc_argp = clp, |
| 5536 | .rpc_cred = cred, |
| 5537 | }; |
| 5538 | int status; |
| 5539 | |
| 5540 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5541 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5542 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5543 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5544 | return status; |
| 5545 | } |
| 5546 | |
| 5547 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5548 | struct rpc_cred *cred) |
| 5549 | { |
| 5550 | unsigned int loop; |
| 5551 | int ret; |
| 5552 | |
| 5553 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5554 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5555 | switch (ret) { |
| 5556 | case -NFS4ERR_DELAY: |
| 5557 | case -NFS4ERR_CLIENTID_BUSY: |
| 5558 | ssleep(1); |
| 5559 | break; |
| 5560 | default: |
| 5561 | return ret; |
| 5562 | } |
| 5563 | } |
| 5564 | return 0; |
| 5565 | } |
| 5566 | |
| 5567 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5568 | { |
| 5569 | struct rpc_cred *cred; |
| 5570 | int ret = 0; |
| 5571 | |
| 5572 | if (clp->cl_mvops->minor_version < 1) |
| 5573 | goto out; |
| 5574 | if (clp->cl_exchange_flags == 0) |
| 5575 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5576 | if (clp->cl_preserve_clid) |
| 5577 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5578 | cred = nfs4_get_exchange_id_cred(clp); |
| 5579 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5580 | if (cred) |
| 5581 | put_rpccred(cred); |
| 5582 | switch (ret) { |
| 5583 | case 0: |
| 5584 | case -NFS4ERR_STALE_CLIENTID: |
| 5585 | clp->cl_exchange_flags = 0; |
| 5586 | } |
| 5587 | out: |
| 5588 | return ret; |
| 5589 | } |
| 5590 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5591 | struct nfs4_get_lease_time_data { |
| 5592 | struct nfs4_get_lease_time_args *args; |
| 5593 | struct nfs4_get_lease_time_res *res; |
| 5594 | struct nfs_client *clp; |
| 5595 | }; |
| 5596 | |
| 5597 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5598 | void *calldata) |
| 5599 | { |
| 5600 | int ret; |
| 5601 | struct nfs4_get_lease_time_data *data = |
| 5602 | (struct nfs4_get_lease_time_data *)calldata; |
| 5603 | |
| 5604 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5605 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5606 | /* just setup sequence, do not trigger session recovery |
| 5607 | since we're invoked within one */ |
| 5608 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5609 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5610 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5611 | |
Trond Myklebust | d3edcf9 | 2012-10-15 13:14:43 -0400 | [diff] [blame] | 5612 | if (ret != -EAGAIN) |
| 5613 | rpc_call_start(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5614 | dprintk("<-- %s\n", __func__); |
| 5615 | } |
| 5616 | |
| 5617 | /* |
| 5618 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5619 | * from sequence operation or clientid errors. |
| 5620 | */ |
| 5621 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5622 | { |
| 5623 | struct nfs4_get_lease_time_data *data = |
| 5624 | (struct nfs4_get_lease_time_data *)calldata; |
| 5625 | |
| 5626 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5627 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5628 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5629 | switch (task->tk_status) { |
| 5630 | case -NFS4ERR_DELAY: |
| 5631 | case -NFS4ERR_GRACE: |
| 5632 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5633 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5634 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5635 | /* fall through */ |
| 5636 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5637 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5638 | return; |
| 5639 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5640 | dprintk("<-- %s\n", __func__); |
| 5641 | } |
| 5642 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5643 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5644 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5645 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5646 | }; |
| 5647 | |
| 5648 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5649 | { |
| 5650 | struct rpc_task *task; |
| 5651 | struct nfs4_get_lease_time_args args; |
| 5652 | struct nfs4_get_lease_time_res res = { |
| 5653 | .lr_fsinfo = fsinfo, |
| 5654 | }; |
| 5655 | struct nfs4_get_lease_time_data data = { |
| 5656 | .args = &args, |
| 5657 | .res = &res, |
| 5658 | .clp = clp, |
| 5659 | }; |
| 5660 | struct rpc_message msg = { |
| 5661 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5662 | .rpc_argp = &args, |
| 5663 | .rpc_resp = &res, |
| 5664 | }; |
| 5665 | struct rpc_task_setup task_setup = { |
| 5666 | .rpc_client = clp->cl_rpcclient, |
| 5667 | .rpc_message = &msg, |
| 5668 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5669 | .callback_data = &data, |
| 5670 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5671 | }; |
| 5672 | int status; |
| 5673 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5674 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5675 | dprintk("--> %s\n", __func__); |
| 5676 | task = rpc_run_task(&task_setup); |
| 5677 | |
| 5678 | if (IS_ERR(task)) |
| 5679 | status = PTR_ERR(task); |
| 5680 | else { |
| 5681 | status = task->tk_status; |
| 5682 | rpc_put_task(task); |
| 5683 | } |
| 5684 | dprintk("<-- %s return %d\n", __func__, status); |
| 5685 | |
| 5686 | return status; |
| 5687 | } |
| 5688 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5689 | struct nfs4_slot *nfs4_alloc_slots(struct nfs4_slot_table *table, |
| 5690 | u32 max_slots, gfp_t gfp_flags) |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5691 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5692 | struct nfs4_slot *tbl; |
| 5693 | u32 i; |
| 5694 | |
| 5695 | tbl = kmalloc_array(max_slots, sizeof(*tbl), gfp_flags); |
| 5696 | if (tbl != NULL) { |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 5697 | for (i = 0; i < max_slots; i++) { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5698 | tbl[i].table = table; |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 5699 | tbl[i].slot_nr = i; |
| 5700 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5701 | } |
| 5702 | return tbl; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5706 | struct nfs4_slot *new, |
| 5707 | u32 max_slots, |
| 5708 | u32 ivalue) |
| 5709 | { |
| 5710 | struct nfs4_slot *old = NULL; |
| 5711 | u32 i; |
| 5712 | |
| 5713 | spin_lock(&tbl->slot_tbl_lock); |
| 5714 | if (new) { |
| 5715 | old = tbl->slots; |
| 5716 | tbl->slots = new; |
| 5717 | tbl->max_slots = max_slots; |
| 5718 | } |
Trond Myklebust | f9b1ef5 | 2012-10-29 16:48:40 -0400 | [diff] [blame] | 5719 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame^] | 5720 | tbl->target_highest_slotid = max_slots - 1; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5721 | for (i = 0; i < tbl->max_slots; i++) |
| 5722 | tbl->slots[i].seq_nr = ivalue; |
| 5723 | spin_unlock(&tbl->slot_tbl_lock); |
| 5724 | kfree(old); |
| 5725 | } |
| 5726 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5727 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5728 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5729 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5730 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5731 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5732 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5733 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5734 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5735 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5736 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5737 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5738 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5739 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5740 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5741 | new = nfs4_alloc_slots(tbl, max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5742 | if (!new) |
| 5743 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5744 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5745 | ret = 0; |
| 5746 | |
| 5747 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5748 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5749 | tbl, tbl->slots, tbl->max_slots); |
| 5750 | out: |
| 5751 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5752 | return ret; |
| 5753 | } |
| 5754 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5755 | /* Destroy the slot table */ |
| 5756 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5757 | { |
| 5758 | if (session->fc_slot_table.slots != NULL) { |
| 5759 | kfree(session->fc_slot_table.slots); |
| 5760 | session->fc_slot_table.slots = NULL; |
| 5761 | } |
| 5762 | if (session->bc_slot_table.slots != NULL) { |
| 5763 | kfree(session->bc_slot_table.slots); |
| 5764 | session->bc_slot_table.slots = NULL; |
| 5765 | } |
| 5766 | return; |
| 5767 | } |
| 5768 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5769 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5770 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5771 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5772 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5773 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5774 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5775 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5776 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5777 | dprintk("--> %s\n", __func__); |
| 5778 | /* Fore channel */ |
| 5779 | tbl = &ses->fc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5780 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5781 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5782 | if (status) /* -ENOMEM */ |
| 5783 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5784 | /* Back channel */ |
| 5785 | tbl = &ses->bc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5786 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5787 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5788 | if (status && tbl->slots == NULL) |
| 5789 | /* Fore and back channel share a connection so get |
| 5790 | * both slot tables or neither */ |
| 5791 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5792 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5796 | { |
| 5797 | struct nfs4_session *session; |
| 5798 | struct nfs4_slot_table *tbl; |
| 5799 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5800 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5801 | if (!session) |
| 5802 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5803 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5804 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5805 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5806 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5807 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5808 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5809 | |
| 5810 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5811 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5812 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5813 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5814 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5815 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5816 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5817 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5818 | session->clp = clp; |
| 5819 | return session; |
| 5820 | } |
| 5821 | |
| 5822 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5823 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5824 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5825 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5826 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5827 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5828 | nfs4_proc_destroy_session(session, cred); |
| 5829 | if (cred) |
| 5830 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5831 | |
| 5832 | rcu_read_lock(); |
| 5833 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5834 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5835 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5836 | __func__, xprt); |
| 5837 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5838 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5839 | kfree(session); |
| 5840 | } |
| 5841 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5842 | /* |
| 5843 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5844 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5845 | * use them. |
| 5846 | * |
| 5847 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5848 | * always set csa_cachethis to FALSE because the current implementation |
| 5849 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5850 | */ |
| 5851 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5852 | { |
| 5853 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5854 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5855 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5856 | |
| 5857 | if (mxrqst_sz == 0) |
| 5858 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5859 | if (mxresp_sz == 0) |
| 5860 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5861 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5862 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5863 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5864 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5865 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5866 | |
| 5867 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5868 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5869 | __func__, |
| 5870 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5871 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5872 | |
| 5873 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5874 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5875 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5876 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5877 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5878 | args->bc_attrs.max_reqs = 1; |
| 5879 | |
| 5880 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5881 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5882 | __func__, |
| 5883 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5884 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5885 | args->bc_attrs.max_reqs); |
| 5886 | } |
| 5887 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5888 | 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] | 5889 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5890 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5891 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5892 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5893 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5894 | return -EINVAL; |
| 5895 | /* |
| 5896 | * Our requested max_ops is the minimum we need; we're not |
| 5897 | * prepared to break up compounds into smaller pieces than that. |
| 5898 | * So, no point even trying to continue if the server won't |
| 5899 | * cooperate: |
| 5900 | */ |
| 5901 | if (rcvd->max_ops < sent->max_ops) |
| 5902 | return -EINVAL; |
| 5903 | if (rcvd->max_reqs == 0) |
| 5904 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5905 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5906 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5907 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5908 | } |
| 5909 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5910 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5911 | { |
| 5912 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5913 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5914 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5915 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5916 | return -EINVAL; |
| 5917 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5918 | return -EINVAL; |
| 5919 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5920 | return -EINVAL; |
| 5921 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5922 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5923 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5924 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5925 | return -EINVAL; |
| 5926 | return 0; |
| 5927 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5928 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5929 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5930 | struct nfs4_session *session) |
| 5931 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5932 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5933 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5934 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5935 | if (ret) |
| 5936 | return ret; |
| 5937 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5938 | } |
| 5939 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5940 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5941 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5942 | { |
| 5943 | struct nfs4_session *session = clp->cl_session; |
| 5944 | struct nfs41_create_session_args args = { |
| 5945 | .client = clp, |
| 5946 | .cb_program = NFS4_CALLBACK, |
| 5947 | }; |
| 5948 | struct nfs41_create_session_res res = { |
| 5949 | .client = clp, |
| 5950 | }; |
| 5951 | struct rpc_message msg = { |
| 5952 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5953 | .rpc_argp = &args, |
| 5954 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5955 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5956 | }; |
| 5957 | int status; |
| 5958 | |
| 5959 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5960 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5961 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5962 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5963 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5964 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5965 | /* Verify the session's negotiated channel_attrs values */ |
| 5966 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5967 | /* Increment the clientid slot sequence id */ |
| 5968 | clp->cl_seqid++; |
| 5969 | } |
| 5970 | |
| 5971 | return status; |
| 5972 | } |
| 5973 | |
| 5974 | /* |
| 5975 | * Issues a CREATE_SESSION operation to the server. |
| 5976 | * It is the responsibility of the caller to verify the session is |
| 5977 | * expired before calling this routine. |
| 5978 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5979 | 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] | 5980 | { |
| 5981 | int status; |
| 5982 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5983 | struct nfs4_session *session = clp->cl_session; |
| 5984 | |
| 5985 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5986 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5987 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5988 | if (status) |
| 5989 | goto out; |
| 5990 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5991 | /* Init or reset the session slot tables */ |
| 5992 | status = nfs4_setup_session_slot_tables(session); |
| 5993 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5994 | if (status) |
| 5995 | goto out; |
| 5996 | |
| 5997 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5998 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5999 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6000 | out: |
| 6001 | dprintk("<-- %s\n", __func__); |
| 6002 | return status; |
| 6003 | } |
| 6004 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6005 | /* |
| 6006 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6007 | * The caller must serialize access to this routine. |
| 6008 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6009 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6010 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6011 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6012 | struct rpc_message msg = { |
| 6013 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6014 | .rpc_argp = session, |
| 6015 | .rpc_cred = cred, |
| 6016 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6017 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6018 | |
| 6019 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6020 | |
| 6021 | /* session is still being setup */ |
| 6022 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6023 | return status; |
| 6024 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6025 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6026 | |
| 6027 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6028 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6029 | "Session has been destroyed regardless...\n", status); |
| 6030 | |
| 6031 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6032 | return status; |
| 6033 | } |
| 6034 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6035 | /* |
| 6036 | * With sessions, the client is not marked ready until after a |
| 6037 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 6038 | * |
| 6039 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 6040 | * other versions of NFS can be tried. |
| 6041 | */ |
| 6042 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 6043 | { |
| 6044 | int ret; |
| 6045 | |
| 6046 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 6047 | ret = nfs4_client_recover_expired_lease(clp); |
| 6048 | if (ret) |
| 6049 | return ret; |
| 6050 | } |
| 6051 | if (clp->cl_cons_state < NFS_CS_READY) |
| 6052 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 6053 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6054 | return 0; |
| 6055 | } |
| 6056 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6057 | int nfs4_init_session(struct nfs_server *server) |
| 6058 | { |
| 6059 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6060 | struct nfs4_session *session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6061 | unsigned int target_max_rqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 6062 | unsigned int target_max_resp_sz = NFS_MAX_FILE_IO_SIZE; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6063 | |
| 6064 | if (!nfs4_has_session(clp)) |
| 6065 | return 0; |
| 6066 | |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6067 | if (server->rsize != 0) |
| 6068 | target_max_resp_sz = server->rsize; |
| 6069 | target_max_resp_sz += nfs41_maxread_overhead; |
| 6070 | |
| 6071 | if (server->wsize != 0) |
| 6072 | target_max_rqst_sz = server->wsize; |
| 6073 | target_max_rqst_sz += nfs41_maxwrite_overhead; |
| 6074 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6075 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6076 | spin_lock(&clp->cl_lock); |
| 6077 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6078 | /* Initialise targets and channel attributes */ |
| 6079 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6080 | session->fc_attrs.max_rqst_sz = target_max_rqst_sz; |
| 6081 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6082 | session->fc_attrs.max_resp_sz = target_max_resp_sz; |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6083 | } else { |
| 6084 | /* Just adjust the targets */ |
| 6085 | if (target_max_rqst_sz > session->fc_target_max_rqst_sz) { |
| 6086 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6087 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6088 | } |
| 6089 | if (target_max_resp_sz > session->fc_target_max_resp_sz) { |
| 6090 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6091 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6092 | } |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6093 | } |
| 6094 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6095 | |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6096 | if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)) |
| 6097 | nfs4_schedule_lease_recovery(clp); |
| 6098 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6099 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6100 | } |
| 6101 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6102 | 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] | 6103 | { |
| 6104 | struct nfs4_session *session = clp->cl_session; |
| 6105 | int ret; |
| 6106 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6107 | spin_lock(&clp->cl_lock); |
| 6108 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 6109 | /* |
| 6110 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 6111 | * DS lease to be equal to the MDS lease. |
| 6112 | */ |
| 6113 | clp->cl_lease_time = lease_time; |
| 6114 | clp->cl_last_renewal = jiffies; |
| 6115 | } |
| 6116 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6117 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6118 | ret = nfs41_check_session_ready(clp); |
| 6119 | if (ret) |
| 6120 | return ret; |
| 6121 | /* Test for the DS role */ |
| 6122 | if (!is_ds_client(clp)) |
| 6123 | return -ENODEV; |
| 6124 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6125 | } |
| 6126 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 6127 | |
| 6128 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6129 | /* |
| 6130 | * Renew the cl_session lease. |
| 6131 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6132 | struct nfs4_sequence_data { |
| 6133 | struct nfs_client *clp; |
| 6134 | struct nfs4_sequence_args args; |
| 6135 | struct nfs4_sequence_res res; |
| 6136 | }; |
| 6137 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6138 | static void nfs41_sequence_release(void *data) |
| 6139 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6140 | struct nfs4_sequence_data *calldata = data; |
| 6141 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6142 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6143 | if (atomic_read(&clp->cl_count) > 1) |
| 6144 | nfs4_schedule_state_renewal(clp); |
| 6145 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6146 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6147 | } |
| 6148 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6149 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6150 | { |
| 6151 | switch(task->tk_status) { |
| 6152 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6153 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6154 | return -EAGAIN; |
| 6155 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6156 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6157 | } |
| 6158 | return 0; |
| 6159 | } |
| 6160 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6161 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6162 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6163 | struct nfs4_sequence_data *calldata = data; |
| 6164 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6165 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6166 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6167 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6168 | |
| 6169 | if (task->tk_status < 0) { |
| 6170 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6171 | if (atomic_read(&clp->cl_count) == 1) |
| 6172 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6173 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6174 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6175 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6176 | return; |
| 6177 | } |
| 6178 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6179 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6180 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6181 | dprintk("<-- %s\n", __func__); |
| 6182 | } |
| 6183 | |
| 6184 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6185 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6186 | struct nfs4_sequence_data *calldata = data; |
| 6187 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6188 | struct nfs4_sequence_args *args; |
| 6189 | struct nfs4_sequence_res *res; |
| 6190 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6191 | args = task->tk_msg.rpc_argp; |
| 6192 | res = task->tk_msg.rpc_resp; |
| 6193 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6194 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6195 | return; |
| 6196 | rpc_call_start(task); |
| 6197 | } |
| 6198 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6199 | static void nfs41_sequence_prepare_privileged(struct rpc_task *task, void *data) |
| 6200 | { |
| 6201 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 6202 | nfs41_sequence_prepare(task, data); |
| 6203 | } |
| 6204 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6205 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6206 | .rpc_call_done = nfs41_sequence_call_done, |
| 6207 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6208 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6209 | }; |
| 6210 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6211 | static const struct rpc_call_ops nfs41_sequence_privileged_ops = { |
| 6212 | .rpc_call_done = nfs41_sequence_call_done, |
| 6213 | .rpc_call_prepare = nfs41_sequence_prepare_privileged, |
| 6214 | .rpc_release = nfs41_sequence_release, |
| 6215 | }; |
| 6216 | |
| 6217 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred, |
| 6218 | const struct rpc_call_ops *seq_ops) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6219 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6220 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6221 | struct rpc_message msg = { |
| 6222 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6223 | .rpc_cred = cred, |
| 6224 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6225 | struct rpc_task_setup task_setup_data = { |
| 6226 | .rpc_client = clp->cl_rpcclient, |
| 6227 | .rpc_message = &msg, |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6228 | .callback_ops = seq_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6229 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6230 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6231 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6232 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6233 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6234 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6235 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6236 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6237 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6238 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6239 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6240 | msg.rpc_argp = &calldata->args; |
| 6241 | msg.rpc_resp = &calldata->res; |
| 6242 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6243 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6244 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6245 | return rpc_run_task(&task_setup_data); |
| 6246 | } |
| 6247 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6248 | 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] | 6249 | { |
| 6250 | struct rpc_task *task; |
| 6251 | int ret = 0; |
| 6252 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6253 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6254 | return 0; |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6255 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6256 | if (IS_ERR(task)) |
| 6257 | ret = PTR_ERR(task); |
| 6258 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6259 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6260 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6261 | return ret; |
| 6262 | } |
| 6263 | |
| 6264 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6265 | { |
| 6266 | struct rpc_task *task; |
| 6267 | int ret; |
| 6268 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6269 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_privileged_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6270 | if (IS_ERR(task)) { |
| 6271 | ret = PTR_ERR(task); |
| 6272 | goto out; |
| 6273 | } |
| 6274 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6275 | if (!ret) { |
| 6276 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6277 | |
| 6278 | if (task->tk_status == 0) |
| 6279 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6280 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6281 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6282 | rpc_put_task(task); |
| 6283 | out: |
| 6284 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6285 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6286 | } |
| 6287 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6288 | struct nfs4_reclaim_complete_data { |
| 6289 | struct nfs_client *clp; |
| 6290 | struct nfs41_reclaim_complete_args arg; |
| 6291 | struct nfs41_reclaim_complete_res res; |
| 6292 | }; |
| 6293 | |
| 6294 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6295 | { |
| 6296 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6297 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6298 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6299 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6300 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6301 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6302 | return; |
| 6303 | |
| 6304 | rpc_call_start(task); |
| 6305 | } |
| 6306 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6307 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6308 | { |
| 6309 | switch(task->tk_status) { |
| 6310 | case 0: |
| 6311 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6312 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6313 | break; |
| 6314 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6315 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6316 | /* fall through */ |
| 6317 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6318 | return -EAGAIN; |
| 6319 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6320 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6321 | } |
| 6322 | return 0; |
| 6323 | } |
| 6324 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6325 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6326 | { |
| 6327 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6328 | struct nfs_client *clp = calldata->clp; |
| 6329 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6330 | |
| 6331 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6332 | if (!nfs41_sequence_done(task, res)) |
| 6333 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6334 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6335 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6336 | rpc_restart_call_prepare(task); |
| 6337 | return; |
| 6338 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6339 | dprintk("<-- %s\n", __func__); |
| 6340 | } |
| 6341 | |
| 6342 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6343 | { |
| 6344 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6345 | |
| 6346 | kfree(calldata); |
| 6347 | } |
| 6348 | |
| 6349 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6350 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6351 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6352 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6353 | }; |
| 6354 | |
| 6355 | /* |
| 6356 | * Issue a global reclaim complete. |
| 6357 | */ |
| 6358 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6359 | { |
| 6360 | struct nfs4_reclaim_complete_data *calldata; |
| 6361 | struct rpc_task *task; |
| 6362 | struct rpc_message msg = { |
| 6363 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6364 | }; |
| 6365 | struct rpc_task_setup task_setup_data = { |
| 6366 | .rpc_client = clp->cl_rpcclient, |
| 6367 | .rpc_message = &msg, |
| 6368 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6369 | .flags = RPC_TASK_ASYNC, |
| 6370 | }; |
| 6371 | int status = -ENOMEM; |
| 6372 | |
| 6373 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6374 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6375 | if (calldata == NULL) |
| 6376 | goto out; |
| 6377 | calldata->clp = clp; |
| 6378 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6379 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6380 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6381 | msg.rpc_argp = &calldata->arg; |
| 6382 | msg.rpc_resp = &calldata->res; |
| 6383 | task_setup_data.callback_data = calldata; |
| 6384 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6385 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6386 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6387 | goto out; |
| 6388 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6389 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6390 | if (status == 0) |
| 6391 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6392 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6393 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6394 | out: |
| 6395 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6396 | return status; |
| 6397 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6398 | |
| 6399 | static void |
| 6400 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6401 | { |
| 6402 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6403 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6404 | |
| 6405 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6406 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6407 | * right now covering the LAYOUTGET we are about to send. |
| 6408 | * However, that is not so catastrophic, and there seems |
| 6409 | * to be no way to prevent it completely. |
| 6410 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6411 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6412 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6413 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6414 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6415 | NFS_I(lgp->args.inode)->layout, |
| 6416 | lgp->args.ctx->state)) { |
| 6417 | rpc_exit(task, NFS4_OK); |
| 6418 | return; |
| 6419 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6420 | rpc_call_start(task); |
| 6421 | } |
| 6422 | |
| 6423 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6424 | { |
| 6425 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6426 | struct inode *inode = lgp->args.inode; |
| 6427 | struct nfs_server *server = NFS_SERVER(inode); |
| 6428 | struct pnfs_layout_hdr *lo; |
| 6429 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6430 | |
| 6431 | dprintk("--> %s\n", __func__); |
| 6432 | |
| 6433 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6434 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6435 | |
| 6436 | switch (task->tk_status) { |
| 6437 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6438 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6439 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6440 | case -NFS4ERR_RECALLCONFLICT: |
| 6441 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6442 | break; |
| 6443 | case -NFS4ERR_EXPIRED: |
| 6444 | case -NFS4ERR_BAD_STATEID: |
| 6445 | spin_lock(&inode->i_lock); |
| 6446 | lo = NFS_I(inode)->layout; |
| 6447 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6448 | spin_unlock(&inode->i_lock); |
| 6449 | /* If the open stateid was bad, then recover it. */ |
| 6450 | state = lgp->args.ctx->state; |
| 6451 | } else { |
| 6452 | LIST_HEAD(head); |
| 6453 | |
| 6454 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6455 | spin_unlock(&inode->i_lock); |
| 6456 | /* Mark the bad layout state as invalid, then |
| 6457 | * retry using the open stateid. */ |
| 6458 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6459 | } |
| 6460 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6461 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6462 | rpc_restart_call_prepare(task); |
| 6463 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6464 | dprintk("<-- %s\n", __func__); |
| 6465 | } |
| 6466 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6467 | static size_t max_response_pages(struct nfs_server *server) |
| 6468 | { |
| 6469 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6470 | return nfs_page_array_len(0, max_resp_sz); |
| 6471 | } |
| 6472 | |
| 6473 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6474 | { |
| 6475 | int i; |
| 6476 | |
| 6477 | if (!pages) |
| 6478 | return; |
| 6479 | |
| 6480 | for (i = 0; i < size; i++) { |
| 6481 | if (!pages[i]) |
| 6482 | break; |
| 6483 | __free_page(pages[i]); |
| 6484 | } |
| 6485 | kfree(pages); |
| 6486 | } |
| 6487 | |
| 6488 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6489 | { |
| 6490 | struct page **pages; |
| 6491 | int i; |
| 6492 | |
| 6493 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6494 | if (!pages) { |
| 6495 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6496 | return NULL; |
| 6497 | } |
| 6498 | |
| 6499 | for (i = 0; i < size; i++) { |
| 6500 | pages[i] = alloc_page(gfp_flags); |
| 6501 | if (!pages[i]) { |
| 6502 | dprintk("%s: failed to allocate page\n", __func__); |
| 6503 | nfs4_free_pages(pages, size); |
| 6504 | return NULL; |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | return pages; |
| 6509 | } |
| 6510 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6511 | static void nfs4_layoutget_release(void *calldata) |
| 6512 | { |
| 6513 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6514 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6515 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6516 | |
| 6517 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6518 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6519 | put_nfs_open_context(lgp->args.ctx); |
| 6520 | kfree(calldata); |
| 6521 | dprintk("<-- %s\n", __func__); |
| 6522 | } |
| 6523 | |
| 6524 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6525 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6526 | .rpc_call_done = nfs4_layoutget_done, |
| 6527 | .rpc_release = nfs4_layoutget_release, |
| 6528 | }; |
| 6529 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6530 | struct pnfs_layout_segment * |
| 6531 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6532 | { |
| 6533 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6534 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6535 | struct rpc_task *task; |
| 6536 | struct rpc_message msg = { |
| 6537 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6538 | .rpc_argp = &lgp->args, |
| 6539 | .rpc_resp = &lgp->res, |
| 6540 | }; |
| 6541 | struct rpc_task_setup task_setup_data = { |
| 6542 | .rpc_client = server->client, |
| 6543 | .rpc_message = &msg, |
| 6544 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6545 | .callback_data = lgp, |
| 6546 | .flags = RPC_TASK_ASYNC, |
| 6547 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6548 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6549 | int status = 0; |
| 6550 | |
| 6551 | dprintk("--> %s\n", __func__); |
| 6552 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6553 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6554 | if (!lgp->args.layout.pages) { |
| 6555 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6556 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6557 | } |
| 6558 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6559 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6560 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6561 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6562 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6563 | task = rpc_run_task(&task_setup_data); |
| 6564 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6565 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6566 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6567 | if (status == 0) |
| 6568 | status = task->tk_status; |
| 6569 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6570 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6571 | rpc_put_task(task); |
| 6572 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6573 | if (status) |
| 6574 | return ERR_PTR(status); |
| 6575 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6576 | } |
| 6577 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6578 | static void |
| 6579 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6580 | { |
| 6581 | struct nfs4_layoutreturn *lrp = calldata; |
| 6582 | |
| 6583 | dprintk("--> %s\n", __func__); |
| 6584 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6585 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6586 | return; |
| 6587 | rpc_call_start(task); |
| 6588 | } |
| 6589 | |
| 6590 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6591 | { |
| 6592 | struct nfs4_layoutreturn *lrp = calldata; |
| 6593 | struct nfs_server *server; |
| 6594 | |
| 6595 | dprintk("--> %s\n", __func__); |
| 6596 | |
| 6597 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6598 | return; |
| 6599 | |
| 6600 | server = NFS_SERVER(lrp->args.inode); |
| 6601 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6602 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6603 | return; |
| 6604 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6605 | dprintk("<-- %s\n", __func__); |
| 6606 | } |
| 6607 | |
| 6608 | static void nfs4_layoutreturn_release(void *calldata) |
| 6609 | { |
| 6610 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6611 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6612 | |
| 6613 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6614 | spin_lock(&lo->plh_inode->i_lock); |
| 6615 | if (lrp->res.lrs_present) |
| 6616 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6617 | lo->plh_block_lgets--; |
| 6618 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6619 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6620 | kfree(calldata); |
| 6621 | dprintk("<-- %s\n", __func__); |
| 6622 | } |
| 6623 | |
| 6624 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6625 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6626 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6627 | .rpc_release = nfs4_layoutreturn_release, |
| 6628 | }; |
| 6629 | |
| 6630 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6631 | { |
| 6632 | struct rpc_task *task; |
| 6633 | struct rpc_message msg = { |
| 6634 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6635 | .rpc_argp = &lrp->args, |
| 6636 | .rpc_resp = &lrp->res, |
| 6637 | }; |
| 6638 | struct rpc_task_setup task_setup_data = { |
| 6639 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6640 | .rpc_message = &msg, |
| 6641 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6642 | .callback_data = lrp, |
| 6643 | }; |
| 6644 | int status; |
| 6645 | |
| 6646 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6647 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6648 | task = rpc_run_task(&task_setup_data); |
| 6649 | if (IS_ERR(task)) |
| 6650 | return PTR_ERR(task); |
| 6651 | status = task->tk_status; |
| 6652 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6653 | rpc_put_task(task); |
| 6654 | return status; |
| 6655 | } |
| 6656 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6657 | /* |
| 6658 | * Retrieve the list of Data Server devices from the MDS. |
| 6659 | */ |
| 6660 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6661 | const struct nfs_fh *fh, |
| 6662 | struct pnfs_devicelist *devlist) |
| 6663 | { |
| 6664 | struct nfs4_getdevicelist_args args = { |
| 6665 | .fh = fh, |
| 6666 | .layoutclass = server->pnfs_curr_ld->id, |
| 6667 | }; |
| 6668 | struct nfs4_getdevicelist_res res = { |
| 6669 | .devlist = devlist, |
| 6670 | }; |
| 6671 | struct rpc_message msg = { |
| 6672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6673 | .rpc_argp = &args, |
| 6674 | .rpc_resp = &res, |
| 6675 | }; |
| 6676 | int status; |
| 6677 | |
| 6678 | dprintk("--> %s\n", __func__); |
| 6679 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6680 | &res.seq_res, 0); |
| 6681 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6682 | return status; |
| 6683 | } |
| 6684 | |
| 6685 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6686 | const struct nfs_fh *fh, |
| 6687 | struct pnfs_devicelist *devlist) |
| 6688 | { |
| 6689 | struct nfs4_exception exception = { }; |
| 6690 | int err; |
| 6691 | |
| 6692 | do { |
| 6693 | err = nfs4_handle_exception(server, |
| 6694 | _nfs4_getdevicelist(server, fh, devlist), |
| 6695 | &exception); |
| 6696 | } while (exception.retry); |
| 6697 | |
| 6698 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6699 | err, devlist->num_devs); |
| 6700 | |
| 6701 | return err; |
| 6702 | } |
| 6703 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6704 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6705 | static int |
| 6706 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6707 | { |
| 6708 | struct nfs4_getdeviceinfo_args args = { |
| 6709 | .pdev = pdev, |
| 6710 | }; |
| 6711 | struct nfs4_getdeviceinfo_res res = { |
| 6712 | .pdev = pdev, |
| 6713 | }; |
| 6714 | struct rpc_message msg = { |
| 6715 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6716 | .rpc_argp = &args, |
| 6717 | .rpc_resp = &res, |
| 6718 | }; |
| 6719 | int status; |
| 6720 | |
| 6721 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6722 | 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] | 6723 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6724 | |
| 6725 | return status; |
| 6726 | } |
| 6727 | |
| 6728 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6729 | { |
| 6730 | struct nfs4_exception exception = { }; |
| 6731 | int err; |
| 6732 | |
| 6733 | do { |
| 6734 | err = nfs4_handle_exception(server, |
| 6735 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6736 | &exception); |
| 6737 | } while (exception.retry); |
| 6738 | return err; |
| 6739 | } |
| 6740 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6741 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6742 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6743 | { |
| 6744 | struct nfs4_layoutcommit_data *data = calldata; |
| 6745 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6746 | |
| 6747 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6748 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6749 | return; |
| 6750 | rpc_call_start(task); |
| 6751 | } |
| 6752 | |
| 6753 | static void |
| 6754 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6755 | { |
| 6756 | struct nfs4_layoutcommit_data *data = calldata; |
| 6757 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6758 | |
| 6759 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6760 | return; |
| 6761 | |
| 6762 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6763 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6764 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6765 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6766 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6767 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6768 | break; |
| 6769 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6770 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6771 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6772 | break; |
| 6773 | default: |
| 6774 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6775 | rpc_restart_call_prepare(task); |
| 6776 | return; |
| 6777 | } |
| 6778 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | static void nfs4_layoutcommit_release(void *calldata) |
| 6782 | { |
| 6783 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6784 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6785 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6786 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6787 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6788 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6789 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6790 | list_del_init(&lseg->pls_lc_list); |
| 6791 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6792 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6793 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6794 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6795 | |
| 6796 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6797 | smp_mb__after_clear_bit(); |
| 6798 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6799 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6800 | put_rpccred(data->cred); |
| 6801 | kfree(data); |
| 6802 | } |
| 6803 | |
| 6804 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6805 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6806 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6807 | .rpc_release = nfs4_layoutcommit_release, |
| 6808 | }; |
| 6809 | |
| 6810 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6811 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6812 | { |
| 6813 | struct rpc_message msg = { |
| 6814 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6815 | .rpc_argp = &data->args, |
| 6816 | .rpc_resp = &data->res, |
| 6817 | .rpc_cred = data->cred, |
| 6818 | }; |
| 6819 | struct rpc_task_setup task_setup_data = { |
| 6820 | .task = &data->task, |
| 6821 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6822 | .rpc_message = &msg, |
| 6823 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6824 | .callback_data = data, |
| 6825 | .flags = RPC_TASK_ASYNC, |
| 6826 | }; |
| 6827 | struct rpc_task *task; |
| 6828 | int status = 0; |
| 6829 | |
| 6830 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6831 | "lbw: %llu inode %lu\n", |
| 6832 | data->task.tk_pid, sync, |
| 6833 | data->args.lastbytewritten, |
| 6834 | data->args.inode->i_ino); |
| 6835 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6836 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6837 | task = rpc_run_task(&task_setup_data); |
| 6838 | if (IS_ERR(task)) |
| 6839 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6840 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6841 | goto out; |
| 6842 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6843 | if (status != 0) |
| 6844 | goto out; |
| 6845 | status = task->tk_status; |
| 6846 | out: |
| 6847 | dprintk("%s: status %d\n", __func__, status); |
| 6848 | rpc_put_task(task); |
| 6849 | return status; |
| 6850 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6851 | |
| 6852 | static int |
| 6853 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6854 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6855 | { |
| 6856 | struct nfs41_secinfo_no_name_args args = { |
| 6857 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6858 | }; |
| 6859 | struct nfs4_secinfo_res res = { |
| 6860 | .flavors = flavors, |
| 6861 | }; |
| 6862 | struct rpc_message msg = { |
| 6863 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6864 | .rpc_argp = &args, |
| 6865 | .rpc_resp = &res, |
| 6866 | }; |
| 6867 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6868 | } |
| 6869 | |
| 6870 | static int |
| 6871 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6872 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6873 | { |
| 6874 | struct nfs4_exception exception = { }; |
| 6875 | int err; |
| 6876 | do { |
| 6877 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6878 | switch (err) { |
| 6879 | case 0: |
| 6880 | case -NFS4ERR_WRONGSEC: |
| 6881 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6882 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6883 | default: |
| 6884 | err = nfs4_handle_exception(server, err, &exception); |
| 6885 | } |
| 6886 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6887 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6888 | return err; |
| 6889 | } |
| 6890 | |
| 6891 | static int |
| 6892 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6893 | struct nfs_fsinfo *info) |
| 6894 | { |
| 6895 | int err; |
| 6896 | struct page *page; |
| 6897 | rpc_authflavor_t flavor; |
| 6898 | struct nfs4_secinfo_flavors *flavors; |
| 6899 | |
| 6900 | page = alloc_page(GFP_KERNEL); |
| 6901 | if (!page) { |
| 6902 | err = -ENOMEM; |
| 6903 | goto out; |
| 6904 | } |
| 6905 | |
| 6906 | flavors = page_address(page); |
| 6907 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6908 | |
| 6909 | /* |
| 6910 | * Fall back on "guess and check" method if |
| 6911 | * the server doesn't support SECINFO_NO_NAME |
| 6912 | */ |
| 6913 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6914 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6915 | goto out_freepage; |
| 6916 | } |
| 6917 | if (err) |
| 6918 | goto out_freepage; |
| 6919 | |
| 6920 | flavor = nfs_find_best_sec(flavors); |
| 6921 | if (err == 0) |
| 6922 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6923 | |
| 6924 | out_freepage: |
| 6925 | put_page(page); |
| 6926 | if (err == -EACCES) |
| 6927 | return -EPERM; |
| 6928 | out: |
| 6929 | return err; |
| 6930 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6931 | |
| 6932 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6933 | { |
| 6934 | int status; |
| 6935 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6936 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6937 | }; |
| 6938 | struct nfs41_test_stateid_res res; |
| 6939 | struct rpc_message msg = { |
| 6940 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6941 | .rpc_argp = &args, |
| 6942 | .rpc_resp = &res, |
| 6943 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6944 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6945 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6946 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6947 | 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] | 6948 | if (status != NFS_OK) { |
| 6949 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6950 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6951 | } |
| 6952 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6953 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6954 | } |
| 6955 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6956 | /** |
| 6957 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6958 | * |
| 6959 | * @server: server / transport on which to perform the operation |
| 6960 | * @stateid: state ID to test |
| 6961 | * |
| 6962 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6963 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6964 | * failed or the state ID is not currently valid. |
| 6965 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6966 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6967 | { |
| 6968 | struct nfs4_exception exception = { }; |
| 6969 | int err; |
| 6970 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6971 | err = _nfs41_test_stateid(server, stateid); |
| 6972 | if (err != -NFS4ERR_DELAY) |
| 6973 | break; |
| 6974 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6975 | } while (exception.retry); |
| 6976 | return err; |
| 6977 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6978 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6979 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6980 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6981 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6982 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6983 | }; |
| 6984 | struct nfs41_free_stateid_res res; |
| 6985 | struct rpc_message msg = { |
| 6986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6987 | .rpc_argp = &args, |
| 6988 | .rpc_resp = &res, |
| 6989 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6990 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6991 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6992 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6993 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6994 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6995 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6996 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6997 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6998 | } |
| 6999 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7000 | /** |
| 7001 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7002 | * |
| 7003 | * @server: server / transport on which to perform the operation |
| 7004 | * @stateid: state ID to release |
| 7005 | * |
| 7006 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7007 | * negative NFS4ERR value is returned. |
| 7008 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7009 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7010 | { |
| 7011 | struct nfs4_exception exception = { }; |
| 7012 | int err; |
| 7013 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7014 | err = _nfs4_free_stateid(server, stateid); |
| 7015 | if (err != -NFS4ERR_DELAY) |
| 7016 | break; |
| 7017 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7018 | } while (exception.retry); |
| 7019 | return err; |
| 7020 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7021 | |
| 7022 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7023 | const nfs4_stateid *s2) |
| 7024 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7025 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7026 | return false; |
| 7027 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7028 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7029 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7030 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7031 | return true; |
| 7032 | |
| 7033 | return false; |
| 7034 | } |
| 7035 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7036 | #endif /* CONFIG_NFS_V4_1 */ |
| 7037 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7038 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7039 | const nfs4_stateid *s2) |
| 7040 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7041 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7042 | } |
| 7043 | |
| 7044 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7045 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7046 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7047 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7048 | .recover_open = nfs4_open_reclaim, |
| 7049 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7050 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7051 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7052 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7053 | }; |
| 7054 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7055 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7056 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7057 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7058 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7059 | .recover_open = nfs4_open_reclaim, |
| 7060 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7061 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7062 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7063 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7064 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7065 | }; |
| 7066 | #endif /* CONFIG_NFS_V4_1 */ |
| 7067 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7068 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7069 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7070 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7071 | .recover_open = nfs4_open_expired, |
| 7072 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7073 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7074 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7075 | }; |
| 7076 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7077 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7078 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7079 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7080 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7081 | .recover_open = nfs41_open_expired, |
| 7082 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7083 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7084 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7085 | }; |
| 7086 | #endif /* CONFIG_NFS_V4_1 */ |
| 7087 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7088 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7089 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7090 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7091 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7092 | }; |
| 7093 | |
| 7094 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7095 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7096 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7097 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7098 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7099 | }; |
| 7100 | #endif |
| 7101 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7102 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7103 | .minor_version = 0, |
| 7104 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7105 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7106 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7107 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7108 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7109 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7110 | }; |
| 7111 | |
| 7112 | #if defined(CONFIG_NFS_V4_1) |
| 7113 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7114 | .minor_version = 1, |
| 7115 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7116 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7117 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7118 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7119 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7120 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7121 | }; |
| 7122 | #endif |
| 7123 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7124 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7125 | [0] = &nfs_v4_0_minor_ops, |
| 7126 | #if defined(CONFIG_NFS_V4_1) |
| 7127 | [1] = &nfs_v4_1_minor_ops, |
| 7128 | #endif |
| 7129 | }; |
| 7130 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7131 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7132 | .create = nfs_create, |
| 7133 | .lookup = nfs_lookup, |
| 7134 | .atomic_open = nfs_atomic_open, |
| 7135 | .link = nfs_link, |
| 7136 | .unlink = nfs_unlink, |
| 7137 | .symlink = nfs_symlink, |
| 7138 | .mkdir = nfs_mkdir, |
| 7139 | .rmdir = nfs_rmdir, |
| 7140 | .mknod = nfs_mknod, |
| 7141 | .rename = nfs_rename, |
| 7142 | .permission = nfs_permission, |
| 7143 | .getattr = nfs_getattr, |
| 7144 | .setattr = nfs_setattr, |
| 7145 | .getxattr = generic_getxattr, |
| 7146 | .setxattr = generic_setxattr, |
| 7147 | .listxattr = generic_listxattr, |
| 7148 | .removexattr = generic_removexattr, |
| 7149 | }; |
| 7150 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7151 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7152 | .permission = nfs_permission, |
| 7153 | .getattr = nfs_getattr, |
| 7154 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7155 | .getxattr = generic_getxattr, |
| 7156 | .setxattr = generic_setxattr, |
| 7157 | .listxattr = generic_listxattr, |
| 7158 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7159 | }; |
| 7160 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7161 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7162 | .version = 4, /* protocol version */ |
| 7163 | .dentry_ops = &nfs4_dentry_operations, |
| 7164 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7165 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7166 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7167 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7168 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7169 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7170 | .getattr = nfs4_proc_getattr, |
| 7171 | .setattr = nfs4_proc_setattr, |
| 7172 | .lookup = nfs4_proc_lookup, |
| 7173 | .access = nfs4_proc_access, |
| 7174 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7175 | .create = nfs4_proc_create, |
| 7176 | .remove = nfs4_proc_remove, |
| 7177 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7178 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7179 | .unlink_done = nfs4_proc_unlink_done, |
| 7180 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7181 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7182 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7183 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7184 | .link = nfs4_proc_link, |
| 7185 | .symlink = nfs4_proc_symlink, |
| 7186 | .mkdir = nfs4_proc_mkdir, |
| 7187 | .rmdir = nfs4_proc_remove, |
| 7188 | .readdir = nfs4_proc_readdir, |
| 7189 | .mknod = nfs4_proc_mknod, |
| 7190 | .statfs = nfs4_proc_statfs, |
| 7191 | .fsinfo = nfs4_proc_fsinfo, |
| 7192 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7193 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7194 | .decode_dirent = nfs4_decode_dirent, |
| 7195 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7196 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7197 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7198 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7199 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7200 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7201 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7202 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7203 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7204 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7205 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7206 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7207 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7208 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7209 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7210 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7211 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7212 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7213 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7214 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7215 | .create_server = nfs4_create_server, |
| 7216 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7217 | }; |
| 7218 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7219 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7220 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7221 | .list = nfs4_xattr_list_nfs4_acl, |
| 7222 | .get = nfs4_xattr_get_nfs4_acl, |
| 7223 | .set = nfs4_xattr_set_nfs4_acl, |
| 7224 | }; |
| 7225 | |
| 7226 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7227 | &nfs4_xattr_nfs4_acl_handler, |
| 7228 | NULL |
| 7229 | }; |
| 7230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7231 | /* |
| 7232 | * Local variables: |
| 7233 | * c-basic-offset: 8 |
| 7234 | * End: |
| 7235 | */ |