Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 55 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 56 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 57 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 58 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 60 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 62 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 63 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 64 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 65 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 66 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 75 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 76 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 77 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 79 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 80 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 81 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 82 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 83 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 84 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 85 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 86 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 87 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 88 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 91 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | if (err >= -1000) |
| 94 | return err; |
| 95 | switch (err) { |
| 96 | case -NFS4ERR_RESOURCE: |
| 97 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 98 | case -NFS4ERR_WRONGSEC: |
| 99 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 100 | case -NFS4ERR_BADOWNER: |
| 101 | case -NFS4ERR_BADNAME: |
| 102 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 103 | case -NFS4ERR_SHARE_DENIED: |
| 104 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 105 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 106 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 107 | case -NFS4ERR_ACCESS: |
| 108 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 111 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 114 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * This is our standard bitmap for GETATTR requests. |
| 119 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 120 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | FATTR4_WORD0_TYPE |
| 122 | | FATTR4_WORD0_CHANGE |
| 123 | | FATTR4_WORD0_SIZE |
| 124 | | FATTR4_WORD0_FSID |
| 125 | | FATTR4_WORD0_FILEID, |
| 126 | FATTR4_WORD1_MODE |
| 127 | | FATTR4_WORD1_NUMLINKS |
| 128 | | FATTR4_WORD1_OWNER |
| 129 | | FATTR4_WORD1_OWNER_GROUP |
| 130 | | FATTR4_WORD1_RAWDEV |
| 131 | | FATTR4_WORD1_SPACE_USED |
| 132 | | FATTR4_WORD1_TIME_ACCESS |
| 133 | | FATTR4_WORD1_TIME_METADATA |
| 134 | | FATTR4_WORD1_TIME_MODIFY |
| 135 | }; |
| 136 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 137 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 138 | FATTR4_WORD0_TYPE |
| 139 | | FATTR4_WORD0_CHANGE |
| 140 | | FATTR4_WORD0_SIZE |
| 141 | | FATTR4_WORD0_FSID |
| 142 | | FATTR4_WORD0_FILEID, |
| 143 | FATTR4_WORD1_MODE |
| 144 | | FATTR4_WORD1_NUMLINKS |
| 145 | | FATTR4_WORD1_OWNER |
| 146 | | FATTR4_WORD1_OWNER_GROUP |
| 147 | | FATTR4_WORD1_RAWDEV |
| 148 | | FATTR4_WORD1_SPACE_USED |
| 149 | | FATTR4_WORD1_TIME_ACCESS |
| 150 | | FATTR4_WORD1_TIME_METADATA |
| 151 | | FATTR4_WORD1_TIME_MODIFY, |
| 152 | FATTR4_WORD2_MDSTHRESHOLD |
| 153 | }; |
| 154 | |
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 | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | 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] | 492 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 493 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 494 | struct nfs4_slot *slot; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 495 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 497 | |
| 498 | /* |
| 499 | * sr_status remains 1 if an RPC level error occurred. The server |
| 500 | * may or may not have processed the sequence operation.. |
| 501 | * Proceed as if the server received and processed the sequence |
| 502 | * operation. |
| 503 | */ |
| 504 | if (res->sr_status == 1) |
| 505 | res->sr_status = NFS_OK; |
| 506 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 507 | /* don't increment the sequence number if the task wasn't sent */ |
| 508 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 509 | goto out; |
| 510 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 511 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 512 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 513 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 514 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 515 | switch (res->sr_status) { |
| 516 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 517 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 518 | ++slot->seq_nr; |
| 519 | timestamp = slot->renewal_time; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 520 | clp = session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 521 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 522 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 523 | if (res->sr_status_flags != 0) |
| 524 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 525 | break; |
| 526 | case -NFS4ERR_DELAY: |
| 527 | /* The server detected a resend of the RPC call and |
| 528 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 529 | * of RFC5661. |
| 530 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 531 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 532 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 533 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 534 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 535 | goto out_retry; |
| 536 | default: |
| 537 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 538 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 539 | } |
| 540 | out: |
| 541 | /* The session may be reset by one of the error handlers. */ |
| 542 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 543 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 544 | return 1; |
| 545 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 546 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 547 | goto out; |
| 548 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 549 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 552 | static int nfs4_sequence_done(struct rpc_task *task, |
| 553 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 554 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 555 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 556 | return 1; |
| 557 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 558 | } |
| 559 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 560 | /* |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 561 | * nfs4_alloc_slot - efficiently look for a free slot |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 562 | * |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 563 | * 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] | 564 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 565 | * and respectively set up the sequence operation args. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 566 | * |
| 567 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 568 | */ |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 569 | static struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 570 | { |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 571 | struct nfs4_slot *ret = NULL; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 572 | u32 slotid; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 573 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 574 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 575 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 576 | tbl->max_slots); |
| 577 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 578 | if (slotid >= tbl->max_slots) |
| 579 | goto out; |
| 580 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 581 | if (slotid > tbl->highest_used_slotid || |
| 582 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 583 | tbl->highest_used_slotid = slotid; |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 584 | ret = &tbl->slots[slotid]; |
| 585 | ret->renewal_time = jiffies; |
| 586 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 587 | out: |
| 588 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 589 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 590 | ret ? ret->slot_nr : -1); |
| 591 | return ret; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 594 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 595 | struct nfs4_sequence_res *res, int cache_reply) |
| 596 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 597 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 598 | args->sa_cache_this = 0; |
| 599 | if (cache_reply) |
| 600 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 601 | res->sr_slot = NULL; |
| 602 | } |
| 603 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 604 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 605 | struct nfs4_sequence_args *args, |
| 606 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 607 | struct rpc_task *task) |
| 608 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 609 | struct nfs4_slot *slot; |
| 610 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 611 | |
| 612 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 614 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | return 0; |
| 616 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 617 | tbl = &session->fc_slot_table; |
| 618 | |
| 619 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 620 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 621 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 622 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 623 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 624 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 625 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 626 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 627 | } |
| 628 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 629 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 630 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 631 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 632 | spin_unlock(&tbl->slot_tbl_lock); |
| 633 | dprintk("%s enforce FIFO order\n", __func__); |
| 634 | return -EAGAIN; |
| 635 | } |
| 636 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 637 | slot = nfs4_alloc_slot(tbl); |
| 638 | if (slot == NULL) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 639 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 640 | spin_unlock(&tbl->slot_tbl_lock); |
| 641 | dprintk("<-- %s: no free slots\n", __func__); |
| 642 | return -EAGAIN; |
| 643 | } |
| 644 | spin_unlock(&tbl->slot_tbl_lock); |
| 645 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 646 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 647 | |
| 648 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 649 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 650 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 651 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 652 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 653 | res->sr_slot = slot; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 654 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 655 | /* |
| 656 | * sr_status is only set in decode_sequence, and so will remain |
| 657 | * set to 1 if an rpc level failure occurs. |
| 658 | */ |
| 659 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 660 | return 0; |
| 661 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 662 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 664 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 665 | struct nfs4_sequence_args *args, |
| 666 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | struct rpc_task *task) |
| 668 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 669 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 670 | int ret = 0; |
| 671 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 672 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 673 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 674 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 675 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 676 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 677 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 678 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 679 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | out: |
| 681 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 682 | return ret; |
| 683 | } |
| 684 | |
| 685 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 687 | struct nfs4_sequence_args *seq_args; |
| 688 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 689 | }; |
| 690 | |
| 691 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 692 | { |
| 693 | struct nfs41_call_sync_data *data = calldata; |
| 694 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 695 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 696 | |
| 697 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 698 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 699 | return; |
| 700 | rpc_call_start(task); |
| 701 | } |
| 702 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 703 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 704 | { |
| 705 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 706 | nfs41_call_sync_prepare(task, calldata); |
| 707 | } |
| 708 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 709 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 710 | { |
| 711 | struct nfs41_call_sync_data *data = calldata; |
| 712 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 713 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 714 | } |
| 715 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 716 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 717 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 718 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 719 | }; |
| 720 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 721 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 722 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 723 | .rpc_call_done = nfs41_call_sync_done, |
| 724 | }; |
| 725 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 726 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 727 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 728 | struct rpc_message *msg, |
| 729 | struct nfs4_sequence_args *args, |
| 730 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 731 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 732 | { |
| 733 | int ret; |
| 734 | struct rpc_task *task; |
| 735 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 736 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 737 | .seq_args = args, |
| 738 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 739 | }; |
| 740 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 741 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 742 | .rpc_message = msg, |
| 743 | .callback_ops = &nfs41_call_sync_ops, |
| 744 | .callback_data = &data |
| 745 | }; |
| 746 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 747 | if (privileged) |
| 748 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 749 | task = rpc_run_task(&task_setup); |
| 750 | if (IS_ERR(task)) |
| 751 | ret = PTR_ERR(task); |
| 752 | else { |
| 753 | ret = task->tk_status; |
| 754 | rpc_put_task(task); |
| 755 | } |
| 756 | return ret; |
| 757 | } |
| 758 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 759 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 760 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 761 | struct rpc_message *msg, |
| 762 | struct nfs4_sequence_args *args, |
| 763 | struct nfs4_sequence_res *res, |
| 764 | int cache_reply) |
| 765 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 766 | nfs41_init_sequence(args, res, cache_reply); |
| 767 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 768 | } |
| 769 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 770 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 771 | static inline |
| 772 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 773 | struct nfs4_sequence_res *res, int cache_reply) |
| 774 | { |
| 775 | } |
| 776 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 777 | static int nfs4_sequence_done(struct rpc_task *task, |
| 778 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 779 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 780 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 781 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 782 | #endif /* CONFIG_NFS_V4_1 */ |
| 783 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 784 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 785 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 786 | struct rpc_message *msg, |
| 787 | struct nfs4_sequence_args *args, |
| 788 | struct nfs4_sequence_res *res, |
| 789 | int cache_reply) |
| 790 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 791 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 792 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 795 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 796 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 797 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 798 | struct rpc_message *msg, |
| 799 | struct nfs4_sequence_args *args, |
| 800 | struct nfs4_sequence_res *res, |
| 801 | int cache_reply) |
| 802 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 803 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 804 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 805 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 806 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 807 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 809 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 811 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 812 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 813 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 814 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 815 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 816 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 819 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 820 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | struct nfs_openargs o_arg; |
| 822 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 823 | struct nfs_open_confirmargs c_arg; |
| 824 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 825 | struct nfs4_string owner_name; |
| 826 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 829 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 830 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 831 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 833 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 834 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 835 | int rpc_status; |
| 836 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 837 | }; |
| 838 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 839 | |
| 840 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 841 | { |
| 842 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 843 | p->o_res.seqid = p->o_arg.seqid; |
| 844 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 845 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 846 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 847 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 848 | 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] | 849 | } |
| 850 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 851 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 852 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 853 | const struct iattr *attrs, |
| 854 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 856 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 857 | struct inode *dir = parent->d_inode; |
| 858 | struct nfs_server *server = NFS_SERVER(dir); |
| 859 | struct nfs4_opendata *p; |
| 860 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 861 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 862 | if (p == NULL) |
| 863 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 864 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 865 | if (p->o_arg.seqid == NULL) |
| 866 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 867 | nfs_sb_active(dentry->d_sb); |
| 868 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 869 | p->dir = parent; |
| 870 | p->owner = sp; |
| 871 | atomic_inc(&sp->so_count); |
| 872 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 873 | p->o_arg.open_flags = flags; |
| 874 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 875 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 876 | * will return permission denied for all bits until close */ |
| 877 | if (!(flags & O_EXCL)) { |
| 878 | /* ask server to check for all possible rights as results |
| 879 | * are cached */ |
| 880 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 881 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 882 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 883 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 884 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 885 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 886 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 887 | p->o_arg.server = server; |
| 888 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 889 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 890 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 891 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 892 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 893 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 894 | p->o_arg.u.attrs = &p->attrs; |
| 895 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 896 | |
| 897 | verf[0] = jiffies; |
| 898 | verf[1] = current->pid; |
| 899 | memcpy(p->o_arg.u.verifier.data, verf, |
| 900 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 901 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 902 | p->c_arg.fh = &p->o_res.fh; |
| 903 | p->c_arg.stateid = &p->o_res.stateid; |
| 904 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 905 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 906 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 907 | return p; |
| 908 | err_free: |
| 909 | kfree(p); |
| 910 | err: |
| 911 | dput(parent); |
| 912 | return NULL; |
| 913 | } |
| 914 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 915 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 916 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 917 | struct nfs4_opendata *p = container_of(kref, |
| 918 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 919 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 920 | |
| 921 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 922 | if (p->state != NULL) |
| 923 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 924 | nfs4_put_state_owner(p->owner); |
| 925 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 926 | dput(p->dentry); |
| 927 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 928 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 929 | kfree(p); |
| 930 | } |
| 931 | |
| 932 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 933 | { |
| 934 | if (p != NULL) |
| 935 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 938 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 939 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 940 | int ret; |
| 941 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 942 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 943 | return ret; |
| 944 | } |
| 945 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | 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] | 947 | { |
| 948 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 949 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 950 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | goto out; |
| 952 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 953 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 954 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 955 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 956 | break; |
| 957 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 958 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 959 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 960 | break; |
| 961 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 962 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 963 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 964 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 965 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 966 | return ret; |
| 967 | } |
| 968 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 970 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 971 | if (delegation == NULL) |
| 972 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 974 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 975 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 976 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 977 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 978 | return 1; |
| 979 | } |
| 980 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 981 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 982 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 983 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 984 | case FMODE_WRITE: |
| 985 | state->n_wronly++; |
| 986 | break; |
| 987 | case FMODE_READ: |
| 988 | state->n_rdonly++; |
| 989 | break; |
| 990 | case FMODE_READ|FMODE_WRITE: |
| 991 | state->n_rdwr++; |
| 992 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 993 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | 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] | 997 | { |
| 998 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 999 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1000 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1002 | case FMODE_READ: |
| 1003 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1004 | break; |
| 1005 | case FMODE_WRITE: |
| 1006 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1007 | break; |
| 1008 | case FMODE_READ|FMODE_WRITE: |
| 1009 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1010 | } |
| 1011 | } |
| 1012 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | 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] | 1014 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1015 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1016 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1017 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1018 | } |
| 1019 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | 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] | 1021 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1022 | /* |
| 1023 | * Protect the call to nfs4_state_set_mode_locked and |
| 1024 | * serialise the stateid update |
| 1025 | */ |
| 1026 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1027 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1028 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1029 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1030 | } |
| 1031 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1032 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1033 | write_sequnlock(&state->seqlock); |
| 1034 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1036 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1039 | 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] | 1040 | { |
| 1041 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1042 | struct nfs_delegation *deleg_cur; |
| 1043 | int ret = 0; |
| 1044 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1046 | |
| 1047 | rcu_read_lock(); |
| 1048 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1049 | if (deleg_cur == NULL) |
| 1050 | goto no_delegation; |
| 1051 | |
| 1052 | spin_lock(&deleg_cur->lock); |
| 1053 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1054 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1055 | goto no_delegation_unlock; |
| 1056 | |
| 1057 | if (delegation == NULL) |
| 1058 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1059 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1060 | goto no_delegation_unlock; |
| 1061 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1062 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1063 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1064 | ret = 1; |
| 1065 | no_delegation_unlock: |
| 1066 | spin_unlock(&deleg_cur->lock); |
| 1067 | no_delegation: |
| 1068 | rcu_read_unlock(); |
| 1069 | |
| 1070 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1071 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1072 | ret = 1; |
| 1073 | } |
| 1074 | |
| 1075 | return ret; |
| 1076 | } |
| 1077 | |
| 1078 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1079 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1080 | { |
| 1081 | struct nfs_delegation *delegation; |
| 1082 | |
| 1083 | rcu_read_lock(); |
| 1084 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1086 | rcu_read_unlock(); |
| 1087 | return; |
| 1088 | } |
| 1089 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1090 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1091 | } |
| 1092 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1093 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1094 | { |
| 1095 | struct nfs4_state *state = opendata->state; |
| 1096 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1097 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1098 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1099 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1100 | nfs4_stateid stateid; |
| 1101 | int ret = -EAGAIN; |
| 1102 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1103 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1104 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1105 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1106 | if (can_open_cached(state, fmode, open_mode)) { |
| 1107 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1108 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1109 | goto out_return_state; |
| 1110 | } |
| 1111 | spin_unlock(&state->owner->so_lock); |
| 1112 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1113 | rcu_read_lock(); |
| 1114 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1115 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1116 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1117 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1118 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1119 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1120 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1121 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1122 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1123 | if (ret != 0) |
| 1124 | goto out; |
| 1125 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1126 | |
| 1127 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1128 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1129 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1130 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1131 | out: |
| 1132 | return ERR_PTR(ret); |
| 1133 | out_return_state: |
| 1134 | atomic_inc(&state->count); |
| 1135 | return state; |
| 1136 | } |
| 1137 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1138 | static void |
| 1139 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1140 | { |
| 1141 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1142 | struct nfs_delegation *delegation; |
| 1143 | int delegation_flags = 0; |
| 1144 | |
| 1145 | rcu_read_lock(); |
| 1146 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1147 | if (delegation) |
| 1148 | delegation_flags = delegation->flags; |
| 1149 | rcu_read_unlock(); |
| 1150 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1151 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1152 | "returning a delegation for " |
| 1153 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1154 | clp->cl_hostname); |
| 1155 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1156 | nfs_inode_set_delegation(state->inode, |
| 1157 | data->owner->so_cred, |
| 1158 | &data->o_res); |
| 1159 | else |
| 1160 | nfs_inode_reclaim_delegation(state->inode, |
| 1161 | data->owner->so_cred, |
| 1162 | &data->o_res); |
| 1163 | } |
| 1164 | |
| 1165 | /* |
| 1166 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1167 | * and update the nfs4_state. |
| 1168 | */ |
| 1169 | static struct nfs4_state * |
| 1170 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1171 | { |
| 1172 | struct inode *inode = data->state->inode; |
| 1173 | struct nfs4_state *state = data->state; |
| 1174 | int ret; |
| 1175 | |
| 1176 | if (!data->rpc_done) { |
| 1177 | ret = data->rpc_status; |
| 1178 | goto err; |
| 1179 | } |
| 1180 | |
| 1181 | ret = -ESTALE; |
| 1182 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1183 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1184 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1185 | goto err; |
| 1186 | |
| 1187 | ret = -ENOMEM; |
| 1188 | state = nfs4_get_open_state(inode, data->owner); |
| 1189 | if (state == NULL) |
| 1190 | goto err; |
| 1191 | |
| 1192 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1193 | if (ret) |
| 1194 | goto err; |
| 1195 | |
| 1196 | if (data->o_res.delegation_type != 0) |
| 1197 | nfs4_opendata_check_deleg(data, state); |
| 1198 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1199 | data->o_arg.fmode); |
| 1200 | |
| 1201 | return state; |
| 1202 | err: |
| 1203 | return ERR_PTR(ret); |
| 1204 | |
| 1205 | } |
| 1206 | |
| 1207 | static struct nfs4_state * |
| 1208 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1209 | { |
| 1210 | struct inode *inode; |
| 1211 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1212 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1213 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1214 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1215 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1216 | goto out; |
| 1217 | } |
| 1218 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1219 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1220 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1221 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1222 | 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] | 1223 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1224 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1225 | goto err; |
| 1226 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1227 | state = nfs4_get_open_state(inode, data->owner); |
| 1228 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1229 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1230 | if (data->o_res.delegation_type != 0) |
| 1231 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1232 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1233 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1234 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1235 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1236 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1237 | err_put_inode: |
| 1238 | iput(inode); |
| 1239 | err: |
| 1240 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1241 | } |
| 1242 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1243 | static struct nfs4_state * |
| 1244 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1245 | { |
| 1246 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1247 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1248 | return _nfs4_opendata_to_nfs4_state(data); |
| 1249 | } |
| 1250 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1251 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1252 | { |
| 1253 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1254 | struct nfs_open_context *ctx; |
| 1255 | |
| 1256 | spin_lock(&state->inode->i_lock); |
| 1257 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1258 | if (ctx->state != state) |
| 1259 | continue; |
| 1260 | get_nfs_open_context(ctx); |
| 1261 | spin_unlock(&state->inode->i_lock); |
| 1262 | return ctx; |
| 1263 | } |
| 1264 | spin_unlock(&state->inode->i_lock); |
| 1265 | return ERR_PTR(-ENOENT); |
| 1266 | } |
| 1267 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1268 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1269 | { |
| 1270 | struct nfs4_opendata *opendata; |
| 1271 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1272 | 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] | 1273 | if (opendata == NULL) |
| 1274 | return ERR_PTR(-ENOMEM); |
| 1275 | opendata->state = state; |
| 1276 | atomic_inc(&state->count); |
| 1277 | return opendata; |
| 1278 | } |
| 1279 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1280 | 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] | 1281 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1282 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1283 | int ret; |
| 1284 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1285 | opendata->o_arg.open_flags = 0; |
| 1286 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1287 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1288 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1289 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1290 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1291 | if (ret != 0) |
| 1292 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1293 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1294 | if (IS_ERR(newstate)) |
| 1295 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1296 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1297 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1302 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1303 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1304 | int ret; |
| 1305 | |
| 1306 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1307 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1308 | smp_rmb(); |
| 1309 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1310 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1311 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1312 | if (ret != 0) |
| 1313 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1314 | if (newstate != state) |
| 1315 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1316 | } |
| 1317 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1318 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1319 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1320 | if (ret != 0) |
| 1321 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1322 | if (newstate != state) |
| 1323 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1324 | } |
| 1325 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1326 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1327 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1328 | if (ret != 0) |
| 1329 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1330 | if (newstate != state) |
| 1331 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1332 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1333 | /* |
| 1334 | * We may have performed cached opens for all three recoveries. |
| 1335 | * Check if we need to update the current stateid. |
| 1336 | */ |
| 1337 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1338 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1339 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1340 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1341 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1342 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1343 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1344 | return 0; |
| 1345 | } |
| 1346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | /* |
| 1348 | * OPEN_RECLAIM: |
| 1349 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1351 | 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] | 1352 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1353 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1354 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | int status; |
| 1357 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1358 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1359 | if (IS_ERR(opendata)) |
| 1360 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1361 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1362 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1363 | rcu_read_lock(); |
| 1364 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1365 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1366 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1367 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1368 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1369 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1370 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | return status; |
| 1372 | } |
| 1373 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1374 | 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] | 1375 | { |
| 1376 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1377 | struct nfs4_exception exception = { }; |
| 1378 | int err; |
| 1379 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1380 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1381 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1382 | break; |
| 1383 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | } while (exception.retry); |
| 1385 | return err; |
| 1386 | } |
| 1387 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1388 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1389 | { |
| 1390 | struct nfs_open_context *ctx; |
| 1391 | int ret; |
| 1392 | |
| 1393 | ctx = nfs4_state_find_open_context(state); |
| 1394 | if (IS_ERR(ctx)) |
| 1395 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1396 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1397 | put_nfs_open_context(ctx); |
| 1398 | return ret; |
| 1399 | } |
| 1400 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1401 | 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] | 1402 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1403 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1404 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1406 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1407 | if (IS_ERR(opendata)) |
| 1408 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1409 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1410 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1411 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1412 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1413 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1416 | 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] | 1417 | { |
| 1418 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1419 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | int err; |
| 1421 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1422 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | switch (err) { |
| 1424 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1425 | case -ENOENT: |
| 1426 | case -ESTALE: |
| 1427 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1428 | case -NFS4ERR_BADSESSION: |
| 1429 | case -NFS4ERR_BADSLOT: |
| 1430 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1431 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1432 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1433 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1434 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | case -NFS4ERR_STALE_CLIENTID: |
| 1436 | case -NFS4ERR_STALE_STATEID: |
| 1437 | case -NFS4ERR_EXPIRED: |
| 1438 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1439 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1440 | goto out; |
| 1441 | case -ERESTARTSYS: |
| 1442 | /* |
| 1443 | * The show must go on: exit, but mark the |
| 1444 | * stateid as needing recovery. |
| 1445 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1446 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1447 | case -NFS4ERR_ADMIN_REVOKED: |
| 1448 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1449 | nfs_inode_find_state_and_recover(state->inode, |
| 1450 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1451 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1452 | case -EKEYEXPIRED: |
| 1453 | /* |
| 1454 | * User RPCSEC_GSS context has expired. |
| 1455 | * We cannot recover this stateid now, so |
| 1456 | * skip it and allow recovery thread to |
| 1457 | * proceed. |
| 1458 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1459 | case -ENOMEM: |
| 1460 | err = 0; |
| 1461 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | } |
| 1463 | err = nfs4_handle_exception(server, err, &exception); |
| 1464 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1465 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | return err; |
| 1467 | } |
| 1468 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1469 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1470 | { |
| 1471 | struct nfs4_opendata *data = calldata; |
| 1472 | |
| 1473 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1474 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1475 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1476 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1477 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1478 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1479 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | static void nfs4_open_confirm_release(void *calldata) |
| 1483 | { |
| 1484 | struct nfs4_opendata *data = calldata; |
| 1485 | struct nfs4_state *state = NULL; |
| 1486 | |
| 1487 | /* If this request hasn't been cancelled, do nothing */ |
| 1488 | if (data->cancelled == 0) |
| 1489 | goto out_free; |
| 1490 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1491 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1492 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1493 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1494 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1495 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1496 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1497 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1501 | .rpc_call_done = nfs4_open_confirm_done, |
| 1502 | .rpc_release = nfs4_open_confirm_release, |
| 1503 | }; |
| 1504 | |
| 1505 | /* |
| 1506 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1507 | */ |
| 1508 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1509 | { |
| 1510 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1511 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1512 | struct rpc_message msg = { |
| 1513 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1514 | .rpc_argp = &data->c_arg, |
| 1515 | .rpc_resp = &data->c_res, |
| 1516 | .rpc_cred = data->owner->so_cred, |
| 1517 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1518 | struct rpc_task_setup task_setup_data = { |
| 1519 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1520 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1521 | .callback_ops = &nfs4_open_confirm_ops, |
| 1522 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1523 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1524 | .flags = RPC_TASK_ASYNC, |
| 1525 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | int status; |
| 1527 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1528 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1529 | data->rpc_done = 0; |
| 1530 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1531 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1532 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1533 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1534 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1535 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1536 | if (status != 0) { |
| 1537 | data->cancelled = 1; |
| 1538 | smp_wmb(); |
| 1539 | } else |
| 1540 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1541 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | return status; |
| 1543 | } |
| 1544 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1545 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1547 | struct nfs4_opendata *data = calldata; |
| 1548 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1549 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1550 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1551 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1552 | /* |
| 1553 | * Check if we still need to send an OPEN call, or if we can use |
| 1554 | * a delegation instead. |
| 1555 | */ |
| 1556 | if (data->state != NULL) { |
| 1557 | struct nfs_delegation *delegation; |
| 1558 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1559 | 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] | 1560 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1561 | rcu_read_lock(); |
| 1562 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1563 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1564 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1565 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1566 | rcu_read_unlock(); |
| 1567 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1568 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1569 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1570 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1571 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1572 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1573 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1574 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1575 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1576 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1577 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1578 | &data->o_res.seq_res, |
| 1579 | task) != 0) |
| 1580 | nfs_release_seqid(data->o_arg.seqid); |
| 1581 | else |
| 1582 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1583 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1584 | unlock_no_action: |
| 1585 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1586 | out_no_action: |
| 1587 | task->tk_action = NULL; |
| 1588 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1591 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1592 | { |
| 1593 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1594 | nfs4_open_prepare(task, calldata); |
| 1595 | } |
| 1596 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1597 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1598 | { |
| 1599 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1601 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1602 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1603 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1604 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1605 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1606 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1607 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1608 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1609 | case S_IFREG: |
| 1610 | break; |
| 1611 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1612 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1613 | break; |
| 1614 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1615 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1616 | break; |
| 1617 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1618 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1619 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1620 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1621 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1622 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1623 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1624 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1625 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1626 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1627 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1628 | static void nfs4_open_release(void *calldata) |
| 1629 | { |
| 1630 | struct nfs4_opendata *data = calldata; |
| 1631 | struct nfs4_state *state = NULL; |
| 1632 | |
| 1633 | /* If this request hasn't been cancelled, do nothing */ |
| 1634 | if (data->cancelled == 0) |
| 1635 | goto out_free; |
| 1636 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1637 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1638 | goto out_free; |
| 1639 | /* In case we need an open_confirm, no cleanup! */ |
| 1640 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1641 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1642 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1643 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1644 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1645 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1646 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1650 | .rpc_call_prepare = nfs4_open_prepare, |
| 1651 | .rpc_call_done = nfs4_open_done, |
| 1652 | .rpc_release = nfs4_open_release, |
| 1653 | }; |
| 1654 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1655 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1656 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1657 | .rpc_call_done = nfs4_open_done, |
| 1658 | .rpc_release = nfs4_open_release, |
| 1659 | }; |
| 1660 | |
| 1661 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1662 | { |
| 1663 | struct inode *dir = data->dir->d_inode; |
| 1664 | struct nfs_server *server = NFS_SERVER(dir); |
| 1665 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1666 | struct nfs_openres *o_res = &data->o_res; |
| 1667 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1668 | struct rpc_message msg = { |
| 1669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1670 | .rpc_argp = o_arg, |
| 1671 | .rpc_resp = o_res, |
| 1672 | .rpc_cred = data->owner->so_cred, |
| 1673 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1674 | struct rpc_task_setup task_setup_data = { |
| 1675 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1676 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1677 | .callback_ops = &nfs4_open_ops, |
| 1678 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1679 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1680 | .flags = RPC_TASK_ASYNC, |
| 1681 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1682 | int status; |
| 1683 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1684 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1685 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1686 | data->rpc_done = 0; |
| 1687 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1688 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1689 | if (isrecover) |
| 1690 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1691 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1692 | if (IS_ERR(task)) |
| 1693 | return PTR_ERR(task); |
| 1694 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1695 | if (status != 0) { |
| 1696 | data->cancelled = 1; |
| 1697 | smp_wmb(); |
| 1698 | } else |
| 1699 | status = data->rpc_status; |
| 1700 | rpc_put_task(task); |
| 1701 | |
| 1702 | return status; |
| 1703 | } |
| 1704 | |
| 1705 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1706 | { |
| 1707 | struct inode *dir = data->dir->d_inode; |
| 1708 | struct nfs_openres *o_res = &data->o_res; |
| 1709 | int status; |
| 1710 | |
| 1711 | status = nfs4_run_open_task(data, 1); |
| 1712 | if (status != 0 || !data->rpc_done) |
| 1713 | return status; |
| 1714 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1715 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1716 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1717 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1718 | status = _nfs4_proc_open_confirm(data); |
| 1719 | if (status != 0) |
| 1720 | return status; |
| 1721 | } |
| 1722 | |
| 1723 | return status; |
| 1724 | } |
| 1725 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1726 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1727 | struct nfs4_opendata *opendata, |
| 1728 | struct nfs4_state *state, fmode_t fmode) |
| 1729 | { |
| 1730 | struct nfs_access_entry cache; |
| 1731 | u32 mask; |
| 1732 | |
| 1733 | /* access call failed or for some reason the server doesn't |
| 1734 | * support any access modes -- defer access call until later */ |
| 1735 | if (opendata->o_res.access_supported == 0) |
| 1736 | return 0; |
| 1737 | |
| 1738 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1739 | /* don't check MAY_WRITE - a newly created file may not have |
| 1740 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1741 | if (fmode & FMODE_READ) |
| 1742 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1743 | if (fmode & FMODE_EXEC) |
| 1744 | mask |= MAY_EXEC; |
| 1745 | |
| 1746 | cache.cred = cred; |
| 1747 | cache.jiffies = jiffies; |
| 1748 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1749 | nfs_access_add_cache(state->inode, &cache); |
| 1750 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1751 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1752 | return 0; |
| 1753 | |
| 1754 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1755 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1756 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1757 | } |
| 1758 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1759 | /* |
| 1760 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1761 | */ |
| 1762 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1763 | { |
| 1764 | struct inode *dir = data->dir->d_inode; |
| 1765 | struct nfs_server *server = NFS_SERVER(dir); |
| 1766 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1767 | struct nfs_openres *o_res = &data->o_res; |
| 1768 | int status; |
| 1769 | |
| 1770 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1771 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1772 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1773 | if (status != 0) { |
| 1774 | if (status == -NFS4ERR_BADNAME && |
| 1775 | !(o_arg->open_flags & O_CREAT)) |
| 1776 | return -ENOENT; |
| 1777 | return status; |
| 1778 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1779 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1780 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1781 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1782 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1783 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1784 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1785 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1787 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1789 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | } |
| 1791 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1792 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1793 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1796 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1797 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1798 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1799 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1800 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1801 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1802 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1803 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1804 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1805 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1806 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1807 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1808 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1809 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1810 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1811 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1812 | } |
| 1813 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1814 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1815 | { |
| 1816 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1817 | } |
| 1818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | /* |
| 1820 | * OPEN_EXPIRED: |
| 1821 | * reclaim state on the server after a network partition. |
| 1822 | * Assumes caller holds the appropriate lock |
| 1823 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1824 | 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] | 1825 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1826 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1827 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1829 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1830 | if (IS_ERR(opendata)) |
| 1831 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1832 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1833 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1834 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1835 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1836 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1839 | 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] | 1840 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1841 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1842 | struct nfs4_exception exception = { }; |
| 1843 | int err; |
| 1844 | |
| 1845 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1846 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1847 | switch (err) { |
| 1848 | default: |
| 1849 | goto out; |
| 1850 | case -NFS4ERR_GRACE: |
| 1851 | case -NFS4ERR_DELAY: |
| 1852 | nfs4_handle_exception(server, err, &exception); |
| 1853 | err = 0; |
| 1854 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1855 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1856 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1857 | return err; |
| 1858 | } |
| 1859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1861 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1863 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1865 | ctx = nfs4_state_find_open_context(state); |
| 1866 | if (IS_ERR(ctx)) |
| 1867 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1868 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1869 | put_nfs_open_context(ctx); |
| 1870 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1873 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1874 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1875 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1876 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1877 | nfs4_stateid *stateid = &state->stateid; |
| 1878 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1879 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1880 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1881 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1882 | return; |
| 1883 | |
| 1884 | status = nfs41_test_stateid(server, stateid); |
| 1885 | if (status != NFS_OK) { |
| 1886 | /* Free the stateid unless the server explicitly |
| 1887 | * informs us the stateid is unrecognized. */ |
| 1888 | if (status != -NFS4ERR_BAD_STATEID) |
| 1889 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1890 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1891 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1892 | write_seqlock(&state->seqlock); |
| 1893 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1894 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1895 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | /** |
| 1900 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1901 | * |
| 1902 | * @state: NFSv4 state for an inode |
| 1903 | * |
| 1904 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1905 | * Otherwise a negative NFS4ERR value is returned. |
| 1906 | */ |
| 1907 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1908 | { |
| 1909 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1910 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1911 | int status; |
| 1912 | |
| 1913 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1914 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1915 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1916 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1917 | return -NFS4ERR_BAD_STATEID; |
| 1918 | |
| 1919 | status = nfs41_test_stateid(server, stateid); |
| 1920 | if (status != NFS_OK) { |
| 1921 | /* Free the stateid unless the server explicitly |
| 1922 | * informs us the stateid is unrecognized. */ |
| 1923 | if (status != -NFS4ERR_BAD_STATEID) |
| 1924 | nfs41_free_stateid(server, stateid); |
| 1925 | |
| 1926 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1927 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1928 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1929 | } |
| 1930 | return status; |
| 1931 | } |
| 1932 | |
| 1933 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1934 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1935 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1936 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1937 | nfs41_clear_delegation_stateid(state); |
| 1938 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1939 | if (status != NFS_OK) |
| 1940 | status = nfs4_open_expired(sp, state); |
| 1941 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1942 | } |
| 1943 | #endif |
| 1944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1946 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1947 | * fields corresponding to attributes that were used to store the verifier. |
| 1948 | * Make sure we clobber those fields in the later setattr call |
| 1949 | */ |
| 1950 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1951 | { |
| 1952 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1953 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1954 | sattr->ia_valid |= ATTR_ATIME; |
| 1955 | |
| 1956 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1957 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1958 | sattr->ia_valid |= ATTR_MTIME; |
| 1959 | } |
| 1960 | |
| 1961 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1962 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1964 | static int _nfs4_do_open(struct inode *dir, |
| 1965 | struct dentry *dentry, |
| 1966 | fmode_t fmode, |
| 1967 | int flags, |
| 1968 | struct iattr *sattr, |
| 1969 | struct rpc_cred *cred, |
| 1970 | struct nfs4_state **res, |
| 1971 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | { |
| 1973 | struct nfs4_state_owner *sp; |
| 1974 | struct nfs4_state *state = NULL; |
| 1975 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1976 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1977 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | |
| 1979 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1981 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1982 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1984 | goto out_err; |
| 1985 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1986 | status = nfs4_recover_expired_lease(server); |
| 1987 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1988 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1989 | if (dentry->d_inode != NULL) |
| 1990 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1991 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1992 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1993 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1994 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1996 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1997 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1998 | if (!opendata->f_attr.mdsthreshold) |
| 1999 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2000 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2001 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2002 | if (dentry->d_inode != NULL) |
| 2003 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2004 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2005 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2007 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2009 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2010 | status = PTR_ERR(state); |
| 2011 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2012 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2013 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 2014 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2015 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2016 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 2017 | if (status != 0) |
| 2018 | goto err_opendata_put; |
| 2019 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2020 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 2021 | nfs4_exclusive_attrset(opendata, sattr); |
| 2022 | |
| 2023 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2024 | status = nfs4_do_setattr(state->inode, cred, |
| 2025 | opendata->o_res.f_attr, sattr, |
| 2026 | state); |
| 2027 | if (status == 0) |
| 2028 | nfs_setattr_update_inode(state->inode, sattr); |
| 2029 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2030 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2031 | |
| 2032 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2033 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2034 | else |
| 2035 | kfree(opendata->f_attr.mdsthreshold); |
| 2036 | opendata->f_attr.mdsthreshold = NULL; |
| 2037 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2038 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | *res = state; |
| 2041 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2042 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2043 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2044 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2045 | err_put_state_owner: |
| 2046 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | *res = NULL; |
| 2049 | return status; |
| 2050 | } |
| 2051 | |
| 2052 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2053 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2054 | struct dentry *dentry, |
| 2055 | fmode_t fmode, |
| 2056 | int flags, |
| 2057 | struct iattr *sattr, |
| 2058 | struct rpc_cred *cred, |
| 2059 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | { |
| 2061 | struct nfs4_exception exception = { }; |
| 2062 | struct nfs4_state *res; |
| 2063 | int status; |
| 2064 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2065 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2067 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2068 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | if (status == 0) |
| 2070 | break; |
| 2071 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2072 | * book-keeping w.r.t. state-changing operations |
| 2073 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2074 | * It is actually a sign of a bug on the client or on the server. |
| 2075 | * |
| 2076 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2077 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | * have unhashed the old state_owner for us, and that we can |
| 2079 | * therefore safely retry using a new one. We should still warn |
| 2080 | * the user though... |
| 2081 | */ |
| 2082 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2083 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2084 | " returned a bad sequence-id error!\n", |
| 2085 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | exception.retry = 1; |
| 2087 | continue; |
| 2088 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2089 | /* |
| 2090 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2091 | * state before it received the OPEN_CONFIRM. |
| 2092 | * Recover by retrying the request as per the discussion |
| 2093 | * on Page 181 of RFC3530. |
| 2094 | */ |
| 2095 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2096 | exception.retry = 1; |
| 2097 | continue; |
| 2098 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2099 | if (status == -EAGAIN) { |
| 2100 | /* We must have found a delegation */ |
| 2101 | exception.retry = 1; |
| 2102 | continue; |
| 2103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2105 | status, &exception)); |
| 2106 | } while (exception.retry); |
| 2107 | return res; |
| 2108 | } |
| 2109 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2110 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2111 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2112 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2114 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2116 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | .iap = sattr, |
| 2118 | .server = server, |
| 2119 | .bitmask = server->attr_bitmask, |
| 2120 | }; |
| 2121 | struct nfs_setattrres res = { |
| 2122 | .fattr = fattr, |
| 2123 | .server = server, |
| 2124 | }; |
| 2125 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2126 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2127 | .rpc_argp = &arg, |
| 2128 | .rpc_resp = &res, |
| 2129 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2131 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2132 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2134 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2136 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2137 | struct nfs_lockowner lockowner = { |
| 2138 | .l_owner = current->files, |
| 2139 | .l_pid = current->tgid, |
| 2140 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2141 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2142 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2143 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2144 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2145 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2146 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2147 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2149 | 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] | 2150 | if (status == 0 && state != NULL) |
| 2151 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2152 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2155 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2156 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2157 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2159 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2160 | struct nfs4_exception exception = { |
| 2161 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2162 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2163 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | int err; |
| 2165 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2166 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2167 | switch (err) { |
| 2168 | case -NFS4ERR_OPENMODE: |
| 2169 | if (state && !(state->state & FMODE_WRITE)) { |
| 2170 | err = -EBADF; |
| 2171 | if (sattr->ia_valid & ATTR_OPEN) |
| 2172 | err = -EACCES; |
| 2173 | goto out; |
| 2174 | } |
| 2175 | } |
| 2176 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2178 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | return err; |
| 2180 | } |
| 2181 | |
| 2182 | struct nfs4_closedata { |
| 2183 | struct inode *inode; |
| 2184 | struct nfs4_state *state; |
| 2185 | struct nfs_closeargs arg; |
| 2186 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2187 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2188 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2189 | bool roc; |
| 2190 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | }; |
| 2192 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2193 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2194 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2195 | struct nfs4_closedata *calldata = data; |
| 2196 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2197 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2198 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2199 | if (calldata->roc) |
| 2200 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2201 | nfs4_put_open_state(calldata->state); |
| 2202 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2203 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2204 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2205 | kfree(calldata); |
| 2206 | } |
| 2207 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2208 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2209 | fmode_t fmode) |
| 2210 | { |
| 2211 | spin_lock(&state->owner->so_lock); |
| 2212 | if (!(fmode & FMODE_READ)) |
| 2213 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2214 | if (!(fmode & FMODE_WRITE)) |
| 2215 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2216 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2217 | spin_unlock(&state->owner->so_lock); |
| 2218 | } |
| 2219 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2220 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2222 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2225 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2226 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2227 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2228 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | /* hmm. we are done with the inode, and in the process of freeing |
| 2230 | * the state_owner. we keep this around to process errors |
| 2231 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | switch (task->tk_status) { |
| 2233 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2234 | if (calldata->roc) |
| 2235 | pnfs_roc_set_barrier(state->inode, |
| 2236 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2237 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2238 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2239 | nfs4_close_clear_stateid_flags(state, |
| 2240 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | break; |
| 2242 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2243 | case -NFS4ERR_OLD_STATEID: |
| 2244 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2246 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2247 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2249 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2250 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2252 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2253 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2254 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2257 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2259 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2260 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2261 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2262 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2263 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2264 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2265 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2266 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2267 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2268 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2269 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2270 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2271 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2272 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2273 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2274 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2275 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2276 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2277 | } |
| 2278 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2279 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2280 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2281 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2282 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2283 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2284 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2285 | |
| 2286 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2287 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2288 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2289 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2290 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2291 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2292 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2293 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2294 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2295 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2296 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2297 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2298 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2299 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2300 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2301 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2302 | &calldata->arg.seq_args, |
| 2303 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2304 | task) != 0) |
| 2305 | nfs_release_seqid(calldata->arg.seqid); |
| 2306 | else |
| 2307 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2308 | out: |
| 2309 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2312 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2313 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2314 | .rpc_call_done = nfs4_close_done, |
| 2315 | .rpc_release = nfs4_free_closedata, |
| 2316 | }; |
| 2317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | /* |
| 2319 | * It is possible for data to be read/written from a mem-mapped file |
| 2320 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2321 | * This means that we can't safely call nfsv4 close on a file until |
| 2322 | * the inode is cleared. This in turn means that we are not good |
| 2323 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2324 | * share state even when we are done with one of the three share |
| 2325 | * stateid's in the inode. |
| 2326 | * |
| 2327 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2328 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2329 | 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] | 2330 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2331 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2333 | struct nfs4_state_owner *sp = state->owner; |
| 2334 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2335 | struct rpc_message msg = { |
| 2336 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2337 | .rpc_cred = state->owner->so_cred, |
| 2338 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2339 | struct rpc_task_setup task_setup_data = { |
| 2340 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2341 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2342 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2343 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2344 | .flags = RPC_TASK_ASYNC, |
| 2345 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2346 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2348 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2350 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2351 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2352 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2354 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2355 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2357 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2358 | if (calldata->arg.seqid == NULL) |
| 2359 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2360 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2361 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2362 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2363 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2364 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2365 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2366 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2367 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2368 | msg.rpc_argp = &calldata->arg; |
| 2369 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2370 | task_setup_data.callback_data = calldata; |
| 2371 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2372 | if (IS_ERR(task)) |
| 2373 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2374 | status = 0; |
| 2375 | if (wait) |
| 2376 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2377 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2378 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2379 | out_free_calldata: |
| 2380 | kfree(calldata); |
| 2381 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2382 | nfs4_put_open_state(state); |
| 2383 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2384 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2387 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2388 | 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] | 2389 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | struct nfs4_state *state; |
| 2391 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2392 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2393 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2394 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2395 | if (IS_ERR(state)) |
| 2396 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2397 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2398 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2401 | 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] | 2402 | { |
| 2403 | if (ctx->state == NULL) |
| 2404 | return; |
| 2405 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2406 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2407 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2408 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | |
| 2411 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2412 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2413 | struct nfs4_server_caps_arg args = { |
| 2414 | .fhandle = fhandle, |
| 2415 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | struct nfs4_server_caps_res res = {}; |
| 2417 | struct rpc_message msg = { |
| 2418 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2419 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | .rpc_resp = &res, |
| 2421 | }; |
| 2422 | int status; |
| 2423 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2424 | 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] | 2425 | if (status == 0) { |
| 2426 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2427 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2428 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2429 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2430 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2431 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2433 | server->caps |= NFS_CAP_ACLS; |
| 2434 | if (res.has_links != 0) |
| 2435 | server->caps |= NFS_CAP_HARDLINKS; |
| 2436 | if (res.has_symlinks != 0) |
| 2437 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2438 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2439 | server->caps |= NFS_CAP_FILEID; |
| 2440 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2441 | server->caps |= NFS_CAP_MODE; |
| 2442 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2443 | server->caps |= NFS_CAP_NLINK; |
| 2444 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2445 | server->caps |= NFS_CAP_OWNER; |
| 2446 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2447 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2448 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2449 | server->caps |= NFS_CAP_ATIME; |
| 2450 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2451 | server->caps |= NFS_CAP_CTIME; |
| 2452 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2453 | server->caps |= NFS_CAP_MTIME; |
| 2454 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2455 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2456 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2457 | 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] | 2458 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2459 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | return status; |
| 2463 | } |
| 2464 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2465 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | { |
| 2467 | struct nfs4_exception exception = { }; |
| 2468 | int err; |
| 2469 | do { |
| 2470 | err = nfs4_handle_exception(server, |
| 2471 | _nfs4_server_capabilities(server, fhandle), |
| 2472 | &exception); |
| 2473 | } while (exception.retry); |
| 2474 | return err; |
| 2475 | } |
| 2476 | |
| 2477 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2478 | struct nfs_fsinfo *info) |
| 2479 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | struct nfs4_lookup_root_arg args = { |
| 2481 | .bitmask = nfs4_fattr_bitmap, |
| 2482 | }; |
| 2483 | struct nfs4_lookup_res res = { |
| 2484 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2485 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | .fh = fhandle, |
| 2487 | }; |
| 2488 | struct rpc_message msg = { |
| 2489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2490 | .rpc_argp = &args, |
| 2491 | .rpc_resp = &res, |
| 2492 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2493 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2494 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2495 | 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] | 2496 | } |
| 2497 | |
| 2498 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2499 | struct nfs_fsinfo *info) |
| 2500 | { |
| 2501 | struct nfs4_exception exception = { }; |
| 2502 | int err; |
| 2503 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2504 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2505 | switch (err) { |
| 2506 | case 0: |
| 2507 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2508 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2509 | default: |
| 2510 | err = nfs4_handle_exception(server, err, &exception); |
| 2511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2513 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | return err; |
| 2515 | } |
| 2516 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2517 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2518 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2519 | { |
| 2520 | struct rpc_auth *auth; |
| 2521 | int ret; |
| 2522 | |
| 2523 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2524 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2525 | ret = -EIO; |
| 2526 | goto out; |
| 2527 | } |
| 2528 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2529 | out: |
| 2530 | return ret; |
| 2531 | } |
| 2532 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2533 | 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] | 2534 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2536 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2537 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2539 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2540 | if (len < 0) |
| 2541 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2542 | |
| 2543 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2544 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2545 | * thus has already been tried. */ |
| 2546 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2547 | continue; |
| 2548 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2549 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2550 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2551 | continue; |
| 2552 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2553 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2554 | /* |
| 2555 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2556 | * to access the mount. It could also mean that we tried to mount |
| 2557 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2558 | * existing mount programs don't handle -EACCES very well so it should |
| 2559 | * be mapped to -EPERM instead. |
| 2560 | */ |
| 2561 | if (status == -EACCES) |
| 2562 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2563 | return status; |
| 2564 | } |
| 2565 | |
| 2566 | /* |
| 2567 | * get the file handle for the "/" directory on the server |
| 2568 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2569 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2570 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2571 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2572 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2573 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2574 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2575 | /* |
| 2576 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2577 | * by nfs4_map_errors() as this function exits. |
| 2578 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2579 | 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] | 2580 | if (status == 0) |
| 2581 | status = nfs4_server_capabilities(server, fhandle); |
| 2582 | if (status == 0) |
| 2583 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2584 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2587 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2588 | struct nfs_fsinfo *info) |
| 2589 | { |
| 2590 | int error; |
| 2591 | struct nfs_fattr *fattr = info->fattr; |
| 2592 | |
| 2593 | error = nfs4_server_capabilities(server, mntfh); |
| 2594 | if (error < 0) { |
| 2595 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2596 | return error; |
| 2597 | } |
| 2598 | |
| 2599 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2600 | if (error < 0) { |
| 2601 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2602 | return error; |
| 2603 | } |
| 2604 | |
| 2605 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2606 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2607 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2608 | |
| 2609 | return error; |
| 2610 | } |
| 2611 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2612 | /* |
| 2613 | * Get locations and (maybe) other attributes of a referral. |
| 2614 | * Note that we'll actually follow the referral later when |
| 2615 | * we detect fsid mismatch in inode revalidation |
| 2616 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2617 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2618 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2619 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2620 | { |
| 2621 | int status = -ENOMEM; |
| 2622 | struct page *page = NULL; |
| 2623 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2624 | |
| 2625 | page = alloc_page(GFP_KERNEL); |
| 2626 | if (page == NULL) |
| 2627 | goto out; |
| 2628 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2629 | if (locations == NULL) |
| 2630 | goto out; |
| 2631 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2632 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2633 | if (status != 0) |
| 2634 | goto out; |
| 2635 | /* Make sure server returned a different fsid for the referral */ |
| 2636 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2637 | dprintk("%s: server did not return a different fsid for" |
| 2638 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2639 | status = -EIO; |
| 2640 | goto out; |
| 2641 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2642 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2643 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2644 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2645 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2646 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2647 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2648 | out: |
| 2649 | if (page) |
| 2650 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2651 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2652 | return status; |
| 2653 | } |
| 2654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2656 | { |
| 2657 | struct nfs4_getattr_arg args = { |
| 2658 | .fh = fhandle, |
| 2659 | .bitmask = server->attr_bitmask, |
| 2660 | }; |
| 2661 | struct nfs4_getattr_res res = { |
| 2662 | .fattr = fattr, |
| 2663 | .server = server, |
| 2664 | }; |
| 2665 | struct rpc_message msg = { |
| 2666 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2667 | .rpc_argp = &args, |
| 2668 | .rpc_resp = &res, |
| 2669 | }; |
| 2670 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2671 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2672 | 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] | 2673 | } |
| 2674 | |
| 2675 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2676 | { |
| 2677 | struct nfs4_exception exception = { }; |
| 2678 | int err; |
| 2679 | do { |
| 2680 | err = nfs4_handle_exception(server, |
| 2681 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2682 | &exception); |
| 2683 | } while (exception.retry); |
| 2684 | return err; |
| 2685 | } |
| 2686 | |
| 2687 | /* |
| 2688 | * The file is not closed if it is opened due to the a request to change |
| 2689 | * the size of the file. The open call will not be needed once the |
| 2690 | * VFS layer lookup-intents are implemented. |
| 2691 | * |
| 2692 | * Close is called when the inode is destroyed. |
| 2693 | * If we haven't opened the file for O_WRONLY, we |
| 2694 | * need to in the size_change case to obtain a stateid. |
| 2695 | * |
| 2696 | * Got race? |
| 2697 | * Because OPEN is always done by name in nfsv4, it is |
| 2698 | * possible that we opened a different file by the same |
| 2699 | * name. We can recognize this race condition, but we |
| 2700 | * can't do anything about it besides returning an error. |
| 2701 | * |
| 2702 | * This will be fixed with VFS changes (lookup-intent). |
| 2703 | */ |
| 2704 | static int |
| 2705 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2706 | struct iattr *sattr) |
| 2707 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2708 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2709 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2710 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | int status; |
| 2712 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2713 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2714 | pnfs_return_layout(inode); |
| 2715 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2716 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2718 | /* Deal with open(O_TRUNC) */ |
| 2719 | if (sattr->ia_valid & ATTR_OPEN) |
| 2720 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2721 | |
| 2722 | /* Optimization: if the end result is no change, don't RPC */ |
| 2723 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2724 | return 0; |
| 2725 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2726 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2727 | if (sattr->ia_valid & ATTR_FILE) { |
| 2728 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2729 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2730 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2731 | if (ctx) { |
| 2732 | cred = ctx->cred; |
| 2733 | state = ctx->state; |
| 2734 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2738 | if (status == 0) |
| 2739 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | return status; |
| 2741 | } |
| 2742 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2743 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2744 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2745 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2746 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2747 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2748 | int status; |
| 2749 | struct nfs4_lookup_arg args = { |
| 2750 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2751 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2752 | .name = name, |
| 2753 | }; |
| 2754 | struct nfs4_lookup_res res = { |
| 2755 | .server = server, |
| 2756 | .fattr = fattr, |
| 2757 | .fh = fhandle, |
| 2758 | }; |
| 2759 | struct rpc_message msg = { |
| 2760 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2761 | .rpc_argp = &args, |
| 2762 | .rpc_resp = &res, |
| 2763 | }; |
| 2764 | |
| 2765 | nfs_fattr_init(fattr); |
| 2766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2768 | 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] | 2769 | dprintk("NFS reply lookup: %d\n", status); |
| 2770 | return status; |
| 2771 | } |
| 2772 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2773 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2774 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2775 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2776 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2777 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2778 | fattr->nlink = 2; |
| 2779 | } |
| 2780 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2781 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2782 | struct qstr *name, struct nfs_fh *fhandle, |
| 2783 | struct nfs_fattr *fattr) |
| 2784 | { |
| 2785 | struct nfs4_exception exception = { }; |
| 2786 | struct rpc_clnt *client = *clnt; |
| 2787 | int err; |
| 2788 | do { |
| 2789 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2790 | switch (err) { |
| 2791 | case -NFS4ERR_BADNAME: |
| 2792 | err = -ENOENT; |
| 2793 | goto out; |
| 2794 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2795 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2796 | goto out; |
| 2797 | case -NFS4ERR_WRONGSEC: |
| 2798 | err = -EPERM; |
| 2799 | if (client != *clnt) |
| 2800 | goto out; |
| 2801 | |
| 2802 | client = nfs4_create_sec_client(client, dir, name); |
| 2803 | if (IS_ERR(client)) |
| 2804 | return PTR_ERR(client); |
| 2805 | |
| 2806 | exception.retry = 1; |
| 2807 | break; |
| 2808 | default: |
| 2809 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2810 | } |
| 2811 | } while (exception.retry); |
| 2812 | |
| 2813 | out: |
| 2814 | if (err == 0) |
| 2815 | *clnt = client; |
| 2816 | else if (client != *clnt) |
| 2817 | rpc_shutdown_client(client); |
| 2818 | |
| 2819 | return err; |
| 2820 | } |
| 2821 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2822 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2823 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2825 | int status; |
| 2826 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2827 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2828 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2829 | if (client != NFS_CLIENT(dir)) { |
| 2830 | rpc_shutdown_client(client); |
| 2831 | nfs_fixup_secinfo_attributes(fattr); |
| 2832 | } |
| 2833 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2836 | struct rpc_clnt * |
| 2837 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2838 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2839 | { |
| 2840 | int status; |
| 2841 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2842 | |
| 2843 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2844 | if (status < 0) { |
| 2845 | rpc_shutdown_client(client); |
| 2846 | return ERR_PTR(status); |
| 2847 | } |
| 2848 | return client; |
| 2849 | } |
| 2850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2852 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2853 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | struct nfs4_accessargs args = { |
| 2855 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2856 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2858 | struct nfs4_accessres res = { |
| 2859 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2860 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | struct rpc_message msg = { |
| 2862 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2863 | .rpc_argp = &args, |
| 2864 | .rpc_resp = &res, |
| 2865 | .rpc_cred = entry->cred, |
| 2866 | }; |
| 2867 | int mode = entry->mask; |
| 2868 | int status; |
| 2869 | |
| 2870 | /* |
| 2871 | * Determine which access bits we want to ask for... |
| 2872 | */ |
| 2873 | if (mode & MAY_READ) |
| 2874 | args.access |= NFS4_ACCESS_READ; |
| 2875 | if (S_ISDIR(inode->i_mode)) { |
| 2876 | if (mode & MAY_WRITE) |
| 2877 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2878 | if (mode & MAY_EXEC) |
| 2879 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2880 | } else { |
| 2881 | if (mode & MAY_WRITE) |
| 2882 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2883 | if (mode & MAY_EXEC) |
| 2884 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2885 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2886 | |
| 2887 | res.fattr = nfs_alloc_fattr(); |
| 2888 | if (res.fattr == NULL) |
| 2889 | return -ENOMEM; |
| 2890 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2891 | 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] | 2892 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2893 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2894 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2896 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | return status; |
| 2898 | } |
| 2899 | |
| 2900 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2901 | { |
| 2902 | struct nfs4_exception exception = { }; |
| 2903 | int err; |
| 2904 | do { |
| 2905 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2906 | _nfs4_proc_access(inode, entry), |
| 2907 | &exception); |
| 2908 | } while (exception.retry); |
| 2909 | return err; |
| 2910 | } |
| 2911 | |
| 2912 | /* |
| 2913 | * TODO: For the time being, we don't try to get any attributes |
| 2914 | * along with any of the zero-copy operations READ, READDIR, |
| 2915 | * READLINK, WRITE. |
| 2916 | * |
| 2917 | * In the case of the first three, we want to put the GETATTR |
| 2918 | * after the read-type operation -- this is because it is hard |
| 2919 | * to predict the length of a GETATTR response in v4, and thus |
| 2920 | * align the READ data correctly. This means that the GETATTR |
| 2921 | * may end up partially falling into the page cache, and we should |
| 2922 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2923 | * To do this efficiently, we need to know the total length |
| 2924 | * of data received, which doesn't seem to be available outside |
| 2925 | * of the RPC layer. |
| 2926 | * |
| 2927 | * In the case of WRITE, we also want to put the GETATTR after |
| 2928 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2929 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | * |
| 2931 | * Both of these changes to the XDR layer would in fact be quite |
| 2932 | * minor, but I decided to leave them for a subsequent patch. |
| 2933 | */ |
| 2934 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2935 | unsigned int pgbase, unsigned int pglen) |
| 2936 | { |
| 2937 | struct nfs4_readlink args = { |
| 2938 | .fh = NFS_FH(inode), |
| 2939 | .pgbase = pgbase, |
| 2940 | .pglen = pglen, |
| 2941 | .pages = &page, |
| 2942 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2943 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | struct rpc_message msg = { |
| 2945 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2946 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2947 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | }; |
| 2949 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2950 | 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] | 2951 | } |
| 2952 | |
| 2953 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2954 | unsigned int pgbase, unsigned int pglen) |
| 2955 | { |
| 2956 | struct nfs4_exception exception = { }; |
| 2957 | int err; |
| 2958 | do { |
| 2959 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2960 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2961 | &exception); |
| 2962 | } while (exception.retry); |
| 2963 | return err; |
| 2964 | } |
| 2965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2967 | * 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] | 2968 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | static int |
| 2970 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2971 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2973 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | int status = 0; |
| 2976 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2977 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2978 | if (IS_ERR(ctx)) |
| 2979 | return PTR_ERR(ctx); |
| 2980 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2981 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2982 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2983 | flags, sattr, ctx->cred, |
| 2984 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2985 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | if (IS_ERR(state)) { |
| 2987 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2988 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2990 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2991 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2992 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2994 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | return status; |
| 2996 | } |
| 2997 | |
| 2998 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2999 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3000 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3001 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3003 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3005 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3006 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3007 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3009 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3010 | .rpc_argp = &args, |
| 3011 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3013 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3014 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3015 | 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] | 3016 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3017 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | return status; |
| 3019 | } |
| 3020 | |
| 3021 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3022 | { |
| 3023 | struct nfs4_exception exception = { }; |
| 3024 | int err; |
| 3025 | do { |
| 3026 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3027 | _nfs4_proc_remove(dir, name), |
| 3028 | &exception); |
| 3029 | } while (exception.retry); |
| 3030 | return err; |
| 3031 | } |
| 3032 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3033 | 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] | 3034 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3035 | struct nfs_server *server = NFS_SERVER(dir); |
| 3036 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3037 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3039 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3041 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | } |
| 3043 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3044 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3045 | { |
| 3046 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3047 | &data->args.seq_args, |
| 3048 | &data->res.seq_res, |
| 3049 | task)) |
| 3050 | return; |
| 3051 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3054 | 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] | 3055 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3056 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3057 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3058 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3059 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3060 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3061 | return 0; |
| 3062 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3063 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3066 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3067 | { |
| 3068 | struct nfs_server *server = NFS_SERVER(dir); |
| 3069 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3070 | struct nfs_renameres *res = msg->rpc_resp; |
| 3071 | |
| 3072 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3073 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3074 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3075 | } |
| 3076 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3077 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3078 | { |
| 3079 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3080 | &data->args.seq_args, |
| 3081 | &data->res.seq_res, |
| 3082 | task)) |
| 3083 | return; |
| 3084 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3088 | struct inode *new_dir) |
| 3089 | { |
| 3090 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3091 | |
| 3092 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3093 | return 0; |
| 3094 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3095 | return 0; |
| 3096 | |
| 3097 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3098 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3099 | return 1; |
| 3100 | } |
| 3101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3103 | struct inode *new_dir, struct qstr *new_name) |
| 3104 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3105 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3106 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | .old_dir = NFS_FH(old_dir), |
| 3108 | .new_dir = NFS_FH(new_dir), |
| 3109 | .old_name = old_name, |
| 3110 | .new_name = new_name, |
| 3111 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3112 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3113 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3114 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | struct rpc_message msg = { |
| 3116 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3117 | .rpc_argp = &arg, |
| 3118 | .rpc_resp = &res, |
| 3119 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3120 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3122 | 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] | 3123 | if (!status) { |
| 3124 | update_changeattr(old_dir, &res.old_cinfo); |
| 3125 | update_changeattr(new_dir, &res.new_cinfo); |
| 3126 | } |
| 3127 | return status; |
| 3128 | } |
| 3129 | |
| 3130 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3131 | struct inode *new_dir, struct qstr *new_name) |
| 3132 | { |
| 3133 | struct nfs4_exception exception = { }; |
| 3134 | int err; |
| 3135 | do { |
| 3136 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3137 | _nfs4_proc_rename(old_dir, old_name, |
| 3138 | new_dir, new_name), |
| 3139 | &exception); |
| 3140 | } while (exception.retry); |
| 3141 | return err; |
| 3142 | } |
| 3143 | |
| 3144 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3145 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3146 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | struct nfs4_link_arg arg = { |
| 3148 | .fh = NFS_FH(inode), |
| 3149 | .dir_fh = NFS_FH(dir), |
| 3150 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3151 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3153 | struct nfs4_link_res res = { |
| 3154 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3155 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | struct rpc_message msg = { |
| 3157 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3158 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3159 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3161 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3163 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3164 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3165 | goto out; |
| 3166 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3167 | 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] | 3168 | if (!status) { |
| 3169 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3170 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3171 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3172 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3173 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | return status; |
| 3175 | } |
| 3176 | |
| 3177 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3178 | { |
| 3179 | struct nfs4_exception exception = { }; |
| 3180 | int err; |
| 3181 | do { |
| 3182 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3183 | _nfs4_proc_link(inode, dir, name), |
| 3184 | &exception); |
| 3185 | } while (exception.retry); |
| 3186 | return err; |
| 3187 | } |
| 3188 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3189 | struct nfs4_createdata { |
| 3190 | struct rpc_message msg; |
| 3191 | struct nfs4_create_arg arg; |
| 3192 | struct nfs4_create_res res; |
| 3193 | struct nfs_fh fh; |
| 3194 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3195 | }; |
| 3196 | |
| 3197 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3198 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3199 | { |
| 3200 | struct nfs4_createdata *data; |
| 3201 | |
| 3202 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3203 | if (data != NULL) { |
| 3204 | struct nfs_server *server = NFS_SERVER(dir); |
| 3205 | |
| 3206 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3207 | data->msg.rpc_argp = &data->arg; |
| 3208 | data->msg.rpc_resp = &data->res; |
| 3209 | data->arg.dir_fh = NFS_FH(dir); |
| 3210 | data->arg.server = server; |
| 3211 | data->arg.name = name; |
| 3212 | data->arg.attrs = sattr; |
| 3213 | data->arg.ftype = ftype; |
| 3214 | data->arg.bitmask = server->attr_bitmask; |
| 3215 | data->res.server = server; |
| 3216 | data->res.fh = &data->fh; |
| 3217 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3218 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3219 | } |
| 3220 | return data; |
| 3221 | } |
| 3222 | |
| 3223 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3224 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3225 | 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] | 3226 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3227 | if (status == 0) { |
| 3228 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3229 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3230 | } |
| 3231 | return status; |
| 3232 | } |
| 3233 | |
| 3234 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3235 | { |
| 3236 | kfree(data); |
| 3237 | } |
| 3238 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3239 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3240 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3242 | struct nfs4_createdata *data; |
| 3243 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3245 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3246 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3247 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3248 | status = -ENOMEM; |
| 3249 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3250 | if (data == NULL) |
| 3251 | goto out; |
| 3252 | |
| 3253 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3254 | data->arg.u.symlink.pages = &page; |
| 3255 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3257 | status = nfs4_do_create(dir, dentry, data); |
| 3258 | |
| 3259 | nfs4_free_createdata(data); |
| 3260 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | return status; |
| 3262 | } |
| 3263 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3264 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3265 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | { |
| 3267 | struct nfs4_exception exception = { }; |
| 3268 | int err; |
| 3269 | do { |
| 3270 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3271 | _nfs4_proc_symlink(dir, dentry, page, |
| 3272 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | &exception); |
| 3274 | } while (exception.retry); |
| 3275 | return err; |
| 3276 | } |
| 3277 | |
| 3278 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3279 | struct iattr *sattr) |
| 3280 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3281 | struct nfs4_createdata *data; |
| 3282 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3284 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3285 | if (data == NULL) |
| 3286 | goto out; |
| 3287 | |
| 3288 | status = nfs4_do_create(dir, dentry, data); |
| 3289 | |
| 3290 | nfs4_free_createdata(data); |
| 3291 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | return status; |
| 3293 | } |
| 3294 | |
| 3295 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3296 | struct iattr *sattr) |
| 3297 | { |
| 3298 | struct nfs4_exception exception = { }; |
| 3299 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3300 | |
| 3301 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | do { |
| 3303 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3304 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3305 | &exception); |
| 3306 | } while (exception.retry); |
| 3307 | return err; |
| 3308 | } |
| 3309 | |
| 3310 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3311 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | { |
| 3313 | struct inode *dir = dentry->d_inode; |
| 3314 | struct nfs4_readdir_arg args = { |
| 3315 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3316 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | .pgbase = 0, |
| 3318 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3319 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3320 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | }; |
| 3322 | struct nfs4_readdir_res res; |
| 3323 | struct rpc_message msg = { |
| 3324 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3325 | .rpc_argp = &args, |
| 3326 | .rpc_resp = &res, |
| 3327 | .rpc_cred = cred, |
| 3328 | }; |
| 3329 | int status; |
| 3330 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3331 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3332 | dentry->d_parent->d_name.name, |
| 3333 | dentry->d_name.name, |
| 3334 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3335 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3337 | 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] | 3338 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3339 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3340 | status += args.pgbase; |
| 3341 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3342 | |
| 3343 | nfs_invalidate_atime(dir); |
| 3344 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3345 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | return status; |
| 3347 | } |
| 3348 | |
| 3349 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3350 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | { |
| 3352 | struct nfs4_exception exception = { }; |
| 3353 | int err; |
| 3354 | do { |
| 3355 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3356 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3357 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | &exception); |
| 3359 | } while (exception.retry); |
| 3360 | return err; |
| 3361 | } |
| 3362 | |
| 3363 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3364 | struct iattr *sattr, dev_t rdev) |
| 3365 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3366 | struct nfs4_createdata *data; |
| 3367 | int mode = sattr->ia_mode; |
| 3368 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3370 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3371 | if (data == NULL) |
| 3372 | goto out; |
| 3373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3375 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3377 | data->arg.ftype = NF4BLK; |
| 3378 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3379 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | } |
| 3381 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3382 | data->arg.ftype = NF4CHR; |
| 3383 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3384 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3385 | } else if (!S_ISSOCK(mode)) { |
| 3386 | status = -EINVAL; |
| 3387 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3390 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3391 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3392 | nfs4_free_createdata(data); |
| 3393 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | return status; |
| 3395 | } |
| 3396 | |
| 3397 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3398 | struct iattr *sattr, dev_t rdev) |
| 3399 | { |
| 3400 | struct nfs4_exception exception = { }; |
| 3401 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3402 | |
| 3403 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | do { |
| 3405 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3406 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3407 | &exception); |
| 3408 | } while (exception.retry); |
| 3409 | return err; |
| 3410 | } |
| 3411 | |
| 3412 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3413 | struct nfs_fsstat *fsstat) |
| 3414 | { |
| 3415 | struct nfs4_statfs_arg args = { |
| 3416 | .fh = fhandle, |
| 3417 | .bitmask = server->attr_bitmask, |
| 3418 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3419 | struct nfs4_statfs_res res = { |
| 3420 | .fsstat = fsstat, |
| 3421 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | struct rpc_message msg = { |
| 3423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3424 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3425 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | }; |
| 3427 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3428 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3429 | 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] | 3430 | } |
| 3431 | |
| 3432 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3433 | { |
| 3434 | struct nfs4_exception exception = { }; |
| 3435 | int err; |
| 3436 | do { |
| 3437 | err = nfs4_handle_exception(server, |
| 3438 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3439 | &exception); |
| 3440 | } while (exception.retry); |
| 3441 | return err; |
| 3442 | } |
| 3443 | |
| 3444 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3445 | struct nfs_fsinfo *fsinfo) |
| 3446 | { |
| 3447 | struct nfs4_fsinfo_arg args = { |
| 3448 | .fh = fhandle, |
| 3449 | .bitmask = server->attr_bitmask, |
| 3450 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3451 | struct nfs4_fsinfo_res res = { |
| 3452 | .fsinfo = fsinfo, |
| 3453 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | struct rpc_message msg = { |
| 3455 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3456 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3457 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | }; |
| 3459 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3460 | 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] | 3461 | } |
| 3462 | |
| 3463 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3464 | { |
| 3465 | struct nfs4_exception exception = { }; |
| 3466 | int err; |
| 3467 | |
| 3468 | do { |
| 3469 | err = nfs4_handle_exception(server, |
| 3470 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3471 | &exception); |
| 3472 | } while (exception.retry); |
| 3473 | return err; |
| 3474 | } |
| 3475 | |
| 3476 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3477 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3478 | int error; |
| 3479 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3480 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3481 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3482 | if (error == 0) { |
| 3483 | /* block layout checks this! */ |
| 3484 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3485 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3486 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3487 | |
| 3488 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3492 | struct nfs_pathconf *pathconf) |
| 3493 | { |
| 3494 | struct nfs4_pathconf_arg args = { |
| 3495 | .fh = fhandle, |
| 3496 | .bitmask = server->attr_bitmask, |
| 3497 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3498 | struct nfs4_pathconf_res res = { |
| 3499 | .pathconf = pathconf, |
| 3500 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | struct rpc_message msg = { |
| 3502 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3503 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3504 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | }; |
| 3506 | |
| 3507 | /* None of the pathconf attributes are mandatory to implement */ |
| 3508 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3509 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3510 | return 0; |
| 3511 | } |
| 3512 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3513 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3514 | 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] | 3515 | } |
| 3516 | |
| 3517 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3518 | struct nfs_pathconf *pathconf) |
| 3519 | { |
| 3520 | struct nfs4_exception exception = { }; |
| 3521 | int err; |
| 3522 | |
| 3523 | do { |
| 3524 | err = nfs4_handle_exception(server, |
| 3525 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3526 | &exception); |
| 3527 | } while (exception.retry); |
| 3528 | return err; |
| 3529 | } |
| 3530 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3531 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3532 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3533 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3534 | } |
| 3535 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3536 | 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] | 3537 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3538 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3540 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3541 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3542 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3544 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3545 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3547 | renew_lease(server, data->timestamp); |
| 3548 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3551 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3552 | { |
| 3553 | |
| 3554 | dprintk("--> %s\n", __func__); |
| 3555 | |
| 3556 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3557 | return -EAGAIN; |
| 3558 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3559 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3560 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3563 | 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] | 3564 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3566 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3567 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3568 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | } |
| 3570 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3571 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3572 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3573 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3574 | &data->args.seq_args, |
| 3575 | &data->res.seq_res, |
| 3576 | task)) |
| 3577 | return; |
| 3578 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3581 | 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] | 3582 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3583 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3585 | 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] | 3586 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3587 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3589 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3591 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3592 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3593 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3596 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3597 | { |
| 3598 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3599 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3600 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3601 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3604 | static |
| 3605 | 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] | 3606 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3607 | const struct nfs_pgio_header *hdr = data->header; |
| 3608 | |
| 3609 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3610 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3611 | return false; |
| 3612 | /* Otherwise, request attributes if and only if we don't hold |
| 3613 | * a delegation |
| 3614 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3615 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3616 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3617 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3618 | 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] | 3619 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3620 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3621 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3622 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3623 | data->args.bitmask = NULL; |
| 3624 | data->res.fattr = NULL; |
| 3625 | } else |
| 3626 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3627 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3628 | if (!data->write_done_cb) |
| 3629 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3630 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | data->timestamp = jiffies; |
| 3632 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3633 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3634 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | } |
| 3636 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3637 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3638 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3639 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3640 | &data->args.seq_args, |
| 3641 | &data->res.seq_res, |
| 3642 | task)) |
| 3643 | return; |
| 3644 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3647 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3648 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3650 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3651 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | return; |
| 3654 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3655 | } |
| 3656 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3657 | 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] | 3658 | { |
| 3659 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3660 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3661 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3662 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3663 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3665 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3668 | 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] | 3669 | { |
| 3670 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3671 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3672 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3675 | 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] | 3676 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3677 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3678 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3679 | if (data->commit_done_cb == NULL) |
| 3680 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3681 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3682 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3683 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3686 | struct nfs4_renewdata { |
| 3687 | struct nfs_client *client; |
| 3688 | unsigned long timestamp; |
| 3689 | }; |
| 3690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | /* |
| 3692 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3693 | * standalone procedure for queueing an asynchronous RENEW. |
| 3694 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3695 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3696 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3697 | struct nfs4_renewdata *data = calldata; |
| 3698 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3699 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3700 | if (atomic_read(&clp->cl_count) > 1) |
| 3701 | nfs4_schedule_state_renewal(clp); |
| 3702 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3703 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3704 | } |
| 3705 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3706 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3708 | struct nfs4_renewdata *data = calldata; |
| 3709 | struct nfs_client *clp = data->client; |
| 3710 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | |
| 3712 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3713 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3714 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3715 | return; |
| 3716 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3717 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3718 | return; |
| 3719 | } |
| 3720 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3722 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | } |
| 3724 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3725 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3726 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3727 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3728 | }; |
| 3729 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3730 | 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] | 3731 | { |
| 3732 | struct rpc_message msg = { |
| 3733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3734 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3735 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3737 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3739 | if (renew_flags == 0) |
| 3740 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3741 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3742 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3743 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3744 | if (data == NULL) |
| 3745 | return -ENOMEM; |
| 3746 | data->client = clp; |
| 3747 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3749 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | } |
| 3751 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3752 | 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] | 3753 | { |
| 3754 | struct rpc_message msg = { |
| 3755 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3756 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3757 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | }; |
| 3759 | unsigned long now = jiffies; |
| 3760 | int status; |
| 3761 | |
| 3762 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3763 | if (status < 0) |
| 3764 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3765 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | return 0; |
| 3767 | } |
| 3768 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3769 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3770 | { |
| 3771 | return (server->caps & NFS_CAP_ACLS) |
| 3772 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3773 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3774 | } |
| 3775 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3776 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3777 | * 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] | 3778 | * the stack. |
| 3779 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3780 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3781 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3782 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3783 | struct page **pages, unsigned int *pgbase) |
| 3784 | { |
| 3785 | struct page *newpage, **spages; |
| 3786 | int rc = 0; |
| 3787 | size_t len; |
| 3788 | spages = pages; |
| 3789 | |
| 3790 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3791 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3792 | newpage = alloc_page(GFP_KERNEL); |
| 3793 | |
| 3794 | if (newpage == NULL) |
| 3795 | goto unwind; |
| 3796 | memcpy(page_address(newpage), buf, len); |
| 3797 | buf += len; |
| 3798 | buflen -= len; |
| 3799 | *pages++ = newpage; |
| 3800 | rc++; |
| 3801 | } while (buflen != 0); |
| 3802 | |
| 3803 | return rc; |
| 3804 | |
| 3805 | unwind: |
| 3806 | for(; rc > 0; rc--) |
| 3807 | __free_page(spages[rc-1]); |
| 3808 | return -ENOMEM; |
| 3809 | } |
| 3810 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3811 | struct nfs4_cached_acl { |
| 3812 | int cached; |
| 3813 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3814 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3815 | }; |
| 3816 | |
| 3817 | 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] | 3818 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3819 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3820 | |
| 3821 | spin_lock(&inode->i_lock); |
| 3822 | kfree(nfsi->nfs4_acl); |
| 3823 | nfsi->nfs4_acl = acl; |
| 3824 | spin_unlock(&inode->i_lock); |
| 3825 | } |
| 3826 | |
| 3827 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3828 | { |
| 3829 | nfs4_set_cached_acl(inode, NULL); |
| 3830 | } |
| 3831 | |
| 3832 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3833 | { |
| 3834 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3835 | struct nfs4_cached_acl *acl; |
| 3836 | int ret = -ENOENT; |
| 3837 | |
| 3838 | spin_lock(&inode->i_lock); |
| 3839 | acl = nfsi->nfs4_acl; |
| 3840 | if (acl == NULL) |
| 3841 | goto out; |
| 3842 | if (buf == NULL) /* user is just asking for length */ |
| 3843 | goto out_len; |
| 3844 | if (acl->cached == 0) |
| 3845 | goto out; |
| 3846 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3847 | if (acl->len > buflen) |
| 3848 | goto out; |
| 3849 | memcpy(buf, acl->data, acl->len); |
| 3850 | out_len: |
| 3851 | ret = acl->len; |
| 3852 | out: |
| 3853 | spin_unlock(&inode->i_lock); |
| 3854 | return ret; |
| 3855 | } |
| 3856 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3857 | 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] | 3858 | { |
| 3859 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3860 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3861 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3862 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3863 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3864 | if (acl == NULL) |
| 3865 | goto out; |
| 3866 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3867 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3868 | } else { |
| 3869 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3870 | if (acl == NULL) |
| 3871 | goto out; |
| 3872 | acl->cached = 0; |
| 3873 | } |
| 3874 | acl->len = acl_len; |
| 3875 | out: |
| 3876 | nfs4_set_cached_acl(inode, acl); |
| 3877 | } |
| 3878 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3879 | /* |
| 3880 | * The getxattr API returns the required buffer length when called with a |
| 3881 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3882 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3883 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3884 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3885 | * the cache. If not so, we throw away the page, and cache the required |
| 3886 | * length. The next getxattr call will then produce another round trip to |
| 3887 | * the server, this time with the input buf of the required size. |
| 3888 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3889 | 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] | 3890 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3891 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3892 | struct nfs_getaclargs args = { |
| 3893 | .fh = NFS_FH(inode), |
| 3894 | .acl_pages = pages, |
| 3895 | .acl_len = buflen, |
| 3896 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3897 | struct nfs_getaclres res = { |
| 3898 | .acl_len = buflen, |
| 3899 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3900 | struct rpc_message msg = { |
| 3901 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3902 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3903 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3904 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3905 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3906 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3907 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3908 | /* As long as we're doing a round trip to the server anyway, |
| 3909 | * let's be prepared for a page of acl data. */ |
| 3910 | if (npages == 0) |
| 3911 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3912 | if (npages > ARRAY_SIZE(pages)) |
| 3913 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3914 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3915 | for (i = 0; i < npages; i++) { |
| 3916 | pages[i] = alloc_page(GFP_KERNEL); |
| 3917 | if (!pages[i]) |
| 3918 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3919 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3920 | |
| 3921 | /* for decoding across pages */ |
| 3922 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3923 | if (!res.acl_scratch) |
| 3924 | goto out_free; |
| 3925 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3926 | args.acl_len = npages * PAGE_SIZE; |
| 3927 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3928 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3929 | 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] | 3930 | __func__, buf, buflen, npages, args.acl_len); |
| 3931 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3932 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3933 | if (ret) |
| 3934 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3935 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3936 | /* Handle the case where the passed-in buffer is too short */ |
| 3937 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3938 | /* Did the user only issue a request for the acl length? */ |
| 3939 | if (buf == NULL) |
| 3940 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3941 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3942 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3943 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3944 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3945 | if (buf) |
| 3946 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3947 | out_ok: |
| 3948 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3949 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3950 | for (i = 0; i < npages; i++) |
| 3951 | if (pages[i]) |
| 3952 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3953 | if (res.acl_scratch) |
| 3954 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3955 | return ret; |
| 3956 | } |
| 3957 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3958 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3959 | { |
| 3960 | struct nfs4_exception exception = { }; |
| 3961 | ssize_t ret; |
| 3962 | do { |
| 3963 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3964 | if (ret >= 0) |
| 3965 | break; |
| 3966 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3967 | } while (exception.retry); |
| 3968 | return ret; |
| 3969 | } |
| 3970 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3971 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3972 | { |
| 3973 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3974 | int ret; |
| 3975 | |
| 3976 | if (!nfs4_server_supports_acls(server)) |
| 3977 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3978 | ret = nfs_revalidate_inode(server, inode); |
| 3979 | if (ret < 0) |
| 3980 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3981 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3982 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3983 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3984 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3985 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3986 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3987 | return ret; |
| 3988 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3989 | } |
| 3990 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3991 | 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] | 3992 | { |
| 3993 | struct nfs_server *server = NFS_SERVER(inode); |
| 3994 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3995 | struct nfs_setaclargs arg = { |
| 3996 | .fh = NFS_FH(inode), |
| 3997 | .acl_pages = pages, |
| 3998 | .acl_len = buflen, |
| 3999 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4000 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4001 | struct rpc_message msg = { |
| 4002 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4003 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4004 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4005 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4006 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4007 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4008 | |
| 4009 | if (!nfs4_server_supports_acls(server)) |
| 4010 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4011 | if (npages > ARRAY_SIZE(pages)) |
| 4012 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4013 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4014 | if (i < 0) |
| 4015 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4016 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4017 | 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] | 4018 | |
| 4019 | /* |
| 4020 | * Free each page after tx, so the only ref left is |
| 4021 | * held by the network stack |
| 4022 | */ |
| 4023 | for (; i > 0; i--) |
| 4024 | put_page(pages[i-1]); |
| 4025 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4026 | /* |
| 4027 | * Acl update can result in inode attribute update. |
| 4028 | * so mark the attribute cache invalid. |
| 4029 | */ |
| 4030 | spin_lock(&inode->i_lock); |
| 4031 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4032 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4033 | nfs_access_zap_cache(inode); |
| 4034 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4035 | return ret; |
| 4036 | } |
| 4037 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4038 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4039 | { |
| 4040 | struct nfs4_exception exception = { }; |
| 4041 | int err; |
| 4042 | do { |
| 4043 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4044 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4045 | &exception); |
| 4046 | } while (exception.retry); |
| 4047 | return err; |
| 4048 | } |
| 4049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4051 | 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] | 4052 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4053 | struct nfs_client *clp = server->nfs_client; |
| 4054 | |
| 4055 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | return 0; |
| 4057 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4058 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4059 | case -NFS4ERR_ADMIN_REVOKED: |
| 4060 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4061 | if (state == NULL) |
| 4062 | break; |
| 4063 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4064 | case -NFS4ERR_OPENMODE: |
| 4065 | if (state == NULL) |
| 4066 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4067 | nfs4_schedule_stateid_recovery(server, state); |
| 4068 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4069 | case -NFS4ERR_EXPIRED: |
| 4070 | if (state != NULL) |
| 4071 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4073 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4074 | nfs4_schedule_lease_recovery(clp); |
| 4075 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4076 | #if defined(CONFIG_NFS_V4_1) |
| 4077 | case -NFS4ERR_BADSESSION: |
| 4078 | case -NFS4ERR_BADSLOT: |
| 4079 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4080 | case -NFS4ERR_DEADSESSION: |
| 4081 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4082 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4083 | case -NFS4ERR_SEQ_MISORDERED: |
| 4084 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4085 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4086 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4087 | task->tk_status = 0; |
| 4088 | return -EAGAIN; |
| 4089 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4091 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4092 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4093 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4095 | task->tk_status = 0; |
| 4096 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4097 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | case -NFS4ERR_OLD_STATEID: |
| 4099 | task->tk_status = 0; |
| 4100 | return -EAGAIN; |
| 4101 | } |
| 4102 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4103 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4104 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4105 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4106 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4107 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4108 | task->tk_status = 0; |
| 4109 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | } |
| 4111 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4112 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4113 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4114 | { |
| 4115 | __be32 verf[2]; |
| 4116 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4117 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4118 | /* An impossible timestamp guarantees this value |
| 4119 | * will never match a generated boot time. */ |
| 4120 | verf[0] = 0; |
| 4121 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4122 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4123 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4124 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4125 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4126 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4127 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4128 | } |
| 4129 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4130 | static unsigned int |
| 4131 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4132 | char *buf, size_t len) |
| 4133 | { |
| 4134 | unsigned int result; |
| 4135 | |
| 4136 | rcu_read_lock(); |
| 4137 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4138 | clp->cl_ipaddr, |
| 4139 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4140 | RPC_DISPLAY_ADDR), |
| 4141 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4142 | RPC_DISPLAY_PROTO)); |
| 4143 | rcu_read_unlock(); |
| 4144 | return result; |
| 4145 | } |
| 4146 | |
| 4147 | static unsigned int |
| 4148 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4149 | char *buf, size_t len) |
| 4150 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4151 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4152 | |
| 4153 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4154 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4155 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4156 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4157 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4158 | } |
| 4159 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4160 | /** |
| 4161 | * nfs4_proc_setclientid - Negotiate client ID |
| 4162 | * @clp: state data structure |
| 4163 | * @program: RPC program for NFSv4 callback service |
| 4164 | * @port: IP port number for NFS4 callback service |
| 4165 | * @cred: RPC credential to use for this call |
| 4166 | * @res: where to place the result |
| 4167 | * |
| 4168 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4169 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4170 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4171 | unsigned short port, struct rpc_cred *cred, |
| 4172 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | { |
| 4174 | nfs4_verifier sc_verifier; |
| 4175 | struct nfs4_setclientid setclientid = { |
| 4176 | .sc_verifier = &sc_verifier, |
| 4177 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4178 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | }; |
| 4180 | struct rpc_message msg = { |
| 4181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4182 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4183 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4184 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4186 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4188 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4189 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4190 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4191 | setclientid.sc_name_len = |
| 4192 | nfs4_init_uniform_client_string(clp, |
| 4193 | setclientid.sc_name, |
| 4194 | sizeof(setclientid.sc_name)); |
| 4195 | else |
| 4196 | setclientid.sc_name_len = |
| 4197 | nfs4_init_nonuniform_client_string(clp, |
| 4198 | setclientid.sc_name, |
| 4199 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4200 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4201 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4202 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4203 | sizeof(setclientid.sc_netid), |
| 4204 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4205 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4206 | rcu_read_unlock(); |
| 4207 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4208 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4210 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4211 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4212 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4213 | setclientid.sc_name_len, setclientid.sc_name); |
| 4214 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4215 | dprintk("NFS reply setclientid: %d\n", status); |
| 4216 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | } |
| 4218 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4219 | /** |
| 4220 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4221 | * @clp: state data structure |
| 4222 | * @res: result of a previous SETCLIENTID |
| 4223 | * @cred: RPC credential to use for this call |
| 4224 | * |
| 4225 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4226 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4227 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4228 | struct nfs4_setclientid_res *arg, |
| 4229 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | { |
| 4231 | struct nfs_fsinfo fsinfo; |
| 4232 | struct rpc_message msg = { |
| 4233 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4234 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4236 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | }; |
| 4238 | unsigned long now; |
| 4239 | int status; |
| 4240 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4241 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4242 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4243 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4245 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | if (status == 0) { |
| 4247 | spin_lock(&clp->cl_lock); |
| 4248 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4249 | clp->cl_last_renewal = now; |
| 4250 | spin_unlock(&clp->cl_lock); |
| 4251 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4252 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | return status; |
| 4254 | } |
| 4255 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4256 | struct nfs4_delegreturndata { |
| 4257 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4258 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4259 | struct nfs_fh fh; |
| 4260 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4261 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4262 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4263 | int rpc_status; |
| 4264 | }; |
| 4265 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4266 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4267 | { |
| 4268 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4269 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4270 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4271 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4272 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4273 | switch (task->tk_status) { |
| 4274 | case -NFS4ERR_STALE_STATEID: |
| 4275 | case -NFS4ERR_EXPIRED: |
| 4276 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4277 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4278 | break; |
| 4279 | default: |
| 4280 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4281 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4282 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4283 | return; |
| 4284 | } |
| 4285 | } |
| 4286 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | static void nfs4_delegreturn_release(void *calldata) |
| 4290 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4291 | kfree(calldata); |
| 4292 | } |
| 4293 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4294 | #if defined(CONFIG_NFS_V4_1) |
| 4295 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4296 | { |
| 4297 | struct nfs4_delegreturndata *d_data; |
| 4298 | |
| 4299 | d_data = (struct nfs4_delegreturndata *)data; |
| 4300 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4301 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4302 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4303 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4304 | return; |
| 4305 | rpc_call_start(task); |
| 4306 | } |
| 4307 | #endif /* CONFIG_NFS_V4_1 */ |
| 4308 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4309 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4310 | #if defined(CONFIG_NFS_V4_1) |
| 4311 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4312 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4313 | .rpc_call_done = nfs4_delegreturn_done, |
| 4314 | .rpc_release = nfs4_delegreturn_release, |
| 4315 | }; |
| 4316 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4317 | 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] | 4318 | { |
| 4319 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4320 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4321 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4322 | struct rpc_message msg = { |
| 4323 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4324 | .rpc_cred = cred, |
| 4325 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4326 | struct rpc_task_setup task_setup_data = { |
| 4327 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4328 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4329 | .callback_ops = &nfs4_delegreturn_ops, |
| 4330 | .flags = RPC_TASK_ASYNC, |
| 4331 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4332 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4333 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4334 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4335 | if (data == NULL) |
| 4336 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4337 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4338 | data->args.fhandle = &data->fh; |
| 4339 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4340 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4341 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4342 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4343 | data->res.fattr = &data->fattr; |
| 4344 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4345 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4346 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4347 | data->rpc_status = 0; |
| 4348 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4349 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4350 | msg.rpc_argp = &data->args; |
| 4351 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4352 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4353 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4354 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4355 | if (!issync) |
| 4356 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4357 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4358 | if (status != 0) |
| 4359 | goto out; |
| 4360 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4361 | if (status == 0) |
| 4362 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4363 | else |
| 4364 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4365 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4366 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4367 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | } |
| 4369 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4370 | 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] | 4371 | { |
| 4372 | struct nfs_server *server = NFS_SERVER(inode); |
| 4373 | struct nfs4_exception exception = { }; |
| 4374 | int err; |
| 4375 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4376 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | switch (err) { |
| 4378 | case -NFS4ERR_STALE_STATEID: |
| 4379 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | case 0: |
| 4381 | return 0; |
| 4382 | } |
| 4383 | err = nfs4_handle_exception(server, err, &exception); |
| 4384 | } while (exception.retry); |
| 4385 | return err; |
| 4386 | } |
| 4387 | |
| 4388 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4389 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4390 | |
| 4391 | /* |
| 4392 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4393 | */ |
| 4394 | static unsigned long |
| 4395 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4396 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4397 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | timeout <<= 1; |
| 4399 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4400 | return NFS4_LOCK_MAXTIMEOUT; |
| 4401 | return timeout; |
| 4402 | } |
| 4403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4405 | { |
| 4406 | struct inode *inode = state->inode; |
| 4407 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4408 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4409 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4411 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4413 | struct nfs_lockt_res res = { |
| 4414 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | }; |
| 4416 | struct rpc_message msg = { |
| 4417 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4418 | .rpc_argp = &arg, |
| 4419 | .rpc_resp = &res, |
| 4420 | .rpc_cred = state->owner->so_cred, |
| 4421 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | struct nfs4_lock_state *lsp; |
| 4423 | int status; |
| 4424 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4425 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4426 | status = nfs4_set_lock_state(state, request); |
| 4427 | if (status != 0) |
| 4428 | goto out; |
| 4429 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4430 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4431 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4432 | 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] | 4433 | switch (status) { |
| 4434 | case 0: |
| 4435 | request->fl_type = F_UNLCK; |
| 4436 | break; |
| 4437 | case -NFS4ERR_DENIED: |
| 4438 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4440 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4441 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | return status; |
| 4443 | } |
| 4444 | |
| 4445 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4446 | { |
| 4447 | struct nfs4_exception exception = { }; |
| 4448 | int err; |
| 4449 | |
| 4450 | do { |
| 4451 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4452 | _nfs4_proc_getlk(state, cmd, request), |
| 4453 | &exception); |
| 4454 | } while (exception.retry); |
| 4455 | return err; |
| 4456 | } |
| 4457 | |
| 4458 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4459 | { |
| 4460 | int res = 0; |
| 4461 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4462 | case FL_POSIX: |
| 4463 | res = posix_lock_file_wait(file, fl); |
| 4464 | break; |
| 4465 | case FL_FLOCK: |
| 4466 | res = flock_lock_file_wait(file, fl); |
| 4467 | break; |
| 4468 | default: |
| 4469 | BUG(); |
| 4470 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | return res; |
| 4472 | } |
| 4473 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4474 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4475 | struct nfs_locku_args arg; |
| 4476 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4477 | struct nfs4_lock_state *lsp; |
| 4478 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4479 | struct file_lock fl; |
| 4480 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4481 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4482 | }; |
| 4483 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4484 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4485 | struct nfs_open_context *ctx, |
| 4486 | struct nfs4_lock_state *lsp, |
| 4487 | struct nfs_seqid *seqid) |
| 4488 | { |
| 4489 | struct nfs4_unlockdata *p; |
| 4490 | struct inode *inode = lsp->ls_state->inode; |
| 4491 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4492 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4493 | if (p == NULL) |
| 4494 | return NULL; |
| 4495 | p->arg.fh = NFS_FH(inode); |
| 4496 | p->arg.fl = &p->fl; |
| 4497 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4498 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4499 | p->arg.stateid = &lsp->ls_stateid; |
| 4500 | p->lsp = lsp; |
| 4501 | atomic_inc(&lsp->ls_count); |
| 4502 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4503 | p->ctx = get_nfs_open_context(ctx); |
| 4504 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4505 | p->server = NFS_SERVER(inode); |
| 4506 | return p; |
| 4507 | } |
| 4508 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4509 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4510 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4511 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4512 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4513 | nfs4_put_lock_state(calldata->lsp); |
| 4514 | put_nfs_open_context(calldata->ctx); |
| 4515 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4518 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4519 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4520 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4521 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4522 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4523 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4524 | switch (task->tk_status) { |
| 4525 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4526 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4527 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4528 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4529 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4530 | case -NFS4ERR_BAD_STATEID: |
| 4531 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4532 | case -NFS4ERR_STALE_STATEID: |
| 4533 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4534 | break; |
| 4535 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4536 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4537 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4538 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4539 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4542 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4543 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4544 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4546 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4547 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4548 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4549 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4550 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4551 | return; |
| 4552 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4553 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4554 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4555 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4556 | &calldata->res.seq_res, |
| 4557 | task) != 0) |
| 4558 | nfs_release_seqid(calldata->arg.seqid); |
| 4559 | else |
| 4560 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | } |
| 4562 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4563 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4564 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4565 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4566 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4567 | }; |
| 4568 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4569 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4570 | struct nfs_open_context *ctx, |
| 4571 | struct nfs4_lock_state *lsp, |
| 4572 | struct nfs_seqid *seqid) |
| 4573 | { |
| 4574 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4575 | struct rpc_message msg = { |
| 4576 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4577 | .rpc_cred = ctx->cred, |
| 4578 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4579 | struct rpc_task_setup task_setup_data = { |
| 4580 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4581 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4582 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4583 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4584 | .flags = RPC_TASK_ASYNC, |
| 4585 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4586 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4587 | /* Ensure this is an unlock - when canceling a lock, the |
| 4588 | * canceled lock is passed in, and it won't be an unlock. |
| 4589 | */ |
| 4590 | fl->fl_type = F_UNLCK; |
| 4591 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4592 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4593 | if (data == NULL) { |
| 4594 | nfs_free_seqid(seqid); |
| 4595 | return ERR_PTR(-ENOMEM); |
| 4596 | } |
| 4597 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4598 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4599 | msg.rpc_argp = &data->arg; |
| 4600 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4601 | task_setup_data.callback_data = data; |
| 4602 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4603 | } |
| 4604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4606 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4607 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4608 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4609 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4610 | struct rpc_task *task; |
| 4611 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4612 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4614 | status = nfs4_set_lock_state(state, request); |
| 4615 | /* Unlock _before_ we do the RPC call */ |
| 4616 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4617 | down_read(&nfsi->rwsem); |
| 4618 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4619 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4620 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4621 | } |
| 4622 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4623 | if (status != 0) |
| 4624 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4625 | /* Is this a delegated lock? */ |
| 4626 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4627 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4628 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4629 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4630 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4631 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4632 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4633 | 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] | 4634 | status = PTR_ERR(task); |
| 4635 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4636 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4637 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4638 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4639 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4640 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4641 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4644 | struct nfs4_lockdata { |
| 4645 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4646 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4647 | struct nfs4_lock_state *lsp; |
| 4648 | struct nfs_open_context *ctx; |
| 4649 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4650 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4651 | int rpc_status; |
| 4652 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4653 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4654 | }; |
| 4655 | |
| 4656 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4657 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4658 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4659 | { |
| 4660 | struct nfs4_lockdata *p; |
| 4661 | struct inode *inode = lsp->ls_state->inode; |
| 4662 | struct nfs_server *server = NFS_SERVER(inode); |
| 4663 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4664 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4665 | if (p == NULL) |
| 4666 | return NULL; |
| 4667 | |
| 4668 | p->arg.fh = NFS_FH(inode); |
| 4669 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4670 | 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] | 4671 | if (p->arg.open_seqid == NULL) |
| 4672 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4673 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4674 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4675 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4676 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4677 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4678 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4679 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4680 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4681 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4682 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4683 | atomic_inc(&lsp->ls_count); |
| 4684 | p->ctx = get_nfs_open_context(ctx); |
| 4685 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4686 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4687 | out_free_seqid: |
| 4688 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4689 | out_free: |
| 4690 | kfree(p); |
| 4691 | return NULL; |
| 4692 | } |
| 4693 | |
| 4694 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4695 | { |
| 4696 | struct nfs4_lockdata *data = calldata; |
| 4697 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4699 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4700 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4701 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4702 | /* Do we need to do an open_to_lock_owner? */ |
| 4703 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4704 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4705 | goto out_release_lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4706 | data->arg.open_stateid = &state->stateid; |
| 4707 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4708 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4709 | } else |
| 4710 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4711 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4712 | if (nfs4_setup_sequence(data->server, |
| 4713 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4714 | &data->res.seq_res, |
| 4715 | task) == 0) { |
| 4716 | rpc_call_start(task); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4717 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4718 | } |
| 4719 | nfs_release_seqid(data->arg.open_seqid); |
| 4720 | out_release_lock_seqid: |
| 4721 | nfs_release_seqid(data->arg.lock_seqid); |
| 4722 | dprintk("%s: done!, ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4723 | } |
| 4724 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4725 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4726 | { |
| 4727 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4728 | nfs4_lock_prepare(task, calldata); |
| 4729 | } |
| 4730 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4731 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4732 | { |
| 4733 | struct nfs4_lockdata *data = calldata; |
| 4734 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4735 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4736 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4737 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4738 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4739 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4740 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4741 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4742 | if (data->rpc_status == 0) |
| 4743 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4744 | else |
| 4745 | goto out; |
| 4746 | } |
| 4747 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4748 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4749 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4750 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4751 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4752 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4753 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | static void nfs4_lock_release(void *calldata) |
| 4757 | { |
| 4758 | struct nfs4_lockdata *data = calldata; |
| 4759 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4760 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4761 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4762 | if (data->cancelled != 0) { |
| 4763 | struct rpc_task *task; |
| 4764 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4765 | data->arg.lock_seqid); |
| 4766 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4767 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4768 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4769 | } else |
| 4770 | nfs_free_seqid(data->arg.lock_seqid); |
| 4771 | nfs4_put_lock_state(data->lsp); |
| 4772 | put_nfs_open_context(data->ctx); |
| 4773 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4774 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4778 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4779 | .rpc_call_done = nfs4_lock_done, |
| 4780 | .rpc_release = nfs4_lock_release, |
| 4781 | }; |
| 4782 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4783 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4784 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4785 | .rpc_call_done = nfs4_lock_done, |
| 4786 | .rpc_release = nfs4_lock_release, |
| 4787 | }; |
| 4788 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4789 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4790 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4791 | switch (error) { |
| 4792 | case -NFS4ERR_ADMIN_REVOKED: |
| 4793 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4794 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4795 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4796 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4797 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4798 | break; |
| 4799 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4800 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4801 | case -NFS4ERR_EXPIRED: |
| 4802 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4803 | }; |
| 4804 | } |
| 4805 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4806 | 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] | 4807 | { |
| 4808 | struct nfs4_lockdata *data; |
| 4809 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4810 | struct rpc_message msg = { |
| 4811 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4812 | .rpc_cred = state->owner->so_cred, |
| 4813 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4814 | struct rpc_task_setup task_setup_data = { |
| 4815 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4816 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4817 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4818 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4819 | .flags = RPC_TASK_ASYNC, |
| 4820 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4821 | int ret; |
| 4822 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4823 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4824 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4825 | fl->fl_u.nfs4_fl.owner, |
| 4826 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4827 | if (data == NULL) |
| 4828 | return -ENOMEM; |
| 4829 | if (IS_SETLKW(cmd)) |
| 4830 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4831 | if (recovery_type > NFS_LOCK_NEW) { |
| 4832 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4833 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4834 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4835 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4836 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4837 | msg.rpc_argp = &data->arg; |
| 4838 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4839 | task_setup_data.callback_data = data; |
| 4840 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4841 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4842 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4843 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4844 | if (ret == 0) { |
| 4845 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4846 | if (ret) |
| 4847 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4848 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4849 | } else |
| 4850 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4851 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4852 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4853 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4857 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4858 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4859 | struct nfs4_exception exception = { |
| 4860 | .inode = state->inode, |
| 4861 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4862 | int err; |
| 4863 | |
| 4864 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4865 | /* Cache the lock if possible... */ |
| 4866 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4867 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4868 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4869 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4870 | break; |
| 4871 | nfs4_handle_exception(server, err, &exception); |
| 4872 | } while (exception.retry); |
| 4873 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4877 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4878 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4879 | struct nfs4_exception exception = { |
| 4880 | .inode = state->inode, |
| 4881 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4882 | int err; |
| 4883 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4884 | err = nfs4_set_lock_state(state, request); |
| 4885 | if (err != 0) |
| 4886 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4887 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4888 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4889 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4890 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4891 | switch (err) { |
| 4892 | default: |
| 4893 | goto out; |
| 4894 | case -NFS4ERR_GRACE: |
| 4895 | case -NFS4ERR_DELAY: |
| 4896 | nfs4_handle_exception(server, err, &exception); |
| 4897 | err = 0; |
| 4898 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4899 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4900 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4901 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | } |
| 4903 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4904 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4905 | /** |
| 4906 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4907 | * |
| 4908 | * @state: NFSv4 state for an inode |
| 4909 | * |
| 4910 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4911 | * Otherwise a negative NFS4ERR value is returned. |
| 4912 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4913 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4914 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4915 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4916 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4917 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4918 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4919 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4920 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4921 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4922 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4923 | /* Free the stateid unless the server |
| 4924 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4925 | if (status != -NFS4ERR_BAD_STATEID) |
| 4926 | nfs41_free_stateid(server, |
| 4927 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4928 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4929 | ret = status; |
| 4930 | } |
| 4931 | } |
| 4932 | }; |
| 4933 | |
| 4934 | return ret; |
| 4935 | } |
| 4936 | |
| 4937 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4938 | { |
| 4939 | int status = NFS_OK; |
| 4940 | |
| 4941 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4942 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4943 | if (status != NFS_OK) |
| 4944 | status = nfs4_lock_expired(state, request); |
| 4945 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4946 | } |
| 4947 | #endif |
| 4948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4950 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4951 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4952 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4953 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4955 | if ((fl_flags & FL_POSIX) && |
| 4956 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4957 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4958 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4959 | status = nfs4_set_lock_state(state, request); |
| 4960 | if (status != 0) |
| 4961 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4962 | request->fl_flags |= FL_ACCESS; |
| 4963 | status = do_vfs_lock(request->fl_file, request); |
| 4964 | if (status < 0) |
| 4965 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4966 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4967 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4968 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4969 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4970 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4971 | status = do_vfs_lock(request->fl_file, request); |
| 4972 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4973 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4974 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4975 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4976 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4977 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4978 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4979 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4980 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4981 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4982 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4983 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4984 | out: |
| 4985 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | return status; |
| 4987 | } |
| 4988 | |
| 4989 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4990 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4991 | struct nfs4_exception exception = { |
| 4992 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4993 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4994 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | int err; |
| 4996 | |
| 4997 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4998 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4999 | if (err == -NFS4ERR_DENIED) |
| 5000 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5002 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | } while (exception.retry); |
| 5004 | return err; |
| 5005 | } |
| 5006 | |
| 5007 | static int |
| 5008 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5009 | { |
| 5010 | struct nfs_open_context *ctx; |
| 5011 | struct nfs4_state *state; |
| 5012 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5013 | int status; |
| 5014 | |
| 5015 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5016 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | state = ctx->state; |
| 5018 | |
| 5019 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5020 | return -EINVAL; |
| 5021 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5022 | if (IS_GETLK(cmd)) { |
| 5023 | if (state != NULL) |
| 5024 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5025 | return 0; |
| 5026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | |
| 5028 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5029 | return -EINVAL; |
| 5030 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5031 | if (request->fl_type == F_UNLCK) { |
| 5032 | if (state != NULL) |
| 5033 | return nfs4_proc_unlck(state, cmd, request); |
| 5034 | return 0; |
| 5035 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5037 | if (state == NULL) |
| 5038 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5039 | /* |
| 5040 | * Don't rely on the VFS having checked the file open mode, |
| 5041 | * since it won't do this for flock() locks. |
| 5042 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5043 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5044 | case F_RDLCK: |
| 5045 | if (!(filp->f_mode & FMODE_READ)) |
| 5046 | return -EBADF; |
| 5047 | break; |
| 5048 | case F_WRLCK: |
| 5049 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5050 | return -EBADF; |
| 5051 | } |
| 5052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | do { |
| 5054 | status = nfs4_proc_setlk(state, cmd, request); |
| 5055 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5056 | break; |
| 5057 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5058 | status = -ERESTARTSYS; |
| 5059 | if (signalled()) |
| 5060 | break; |
| 5061 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | return status; |
| 5063 | } |
| 5064 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5065 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5066 | { |
| 5067 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5068 | struct nfs4_exception exception = { }; |
| 5069 | int err; |
| 5070 | |
| 5071 | err = nfs4_set_lock_state(state, fl); |
| 5072 | if (err != 0) |
| 5073 | goto out; |
| 5074 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5075 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5076 | switch (err) { |
| 5077 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5078 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5079 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5080 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5081 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5082 | goto out; |
| 5083 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 5084 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5085 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5086 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5087 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5088 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5089 | case -NFS4ERR_BADSESSION: |
| 5090 | case -NFS4ERR_BADSLOT: |
| 5091 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5092 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5093 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5094 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5095 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5096 | case -ERESTARTSYS: |
| 5097 | /* |
| 5098 | * The show must go on: exit, but mark the |
| 5099 | * stateid as needing recovery. |
| 5100 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5101 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5102 | case -NFS4ERR_ADMIN_REVOKED: |
| 5103 | case -NFS4ERR_BAD_STATEID: |
| 5104 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5105 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5106 | err = 0; |
| 5107 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5108 | case -EKEYEXPIRED: |
| 5109 | /* |
| 5110 | * User RPCSEC_GSS context has expired. |
| 5111 | * We cannot recover this stateid now, so |
| 5112 | * skip it and allow recovery thread to |
| 5113 | * proceed. |
| 5114 | */ |
| 5115 | err = 0; |
| 5116 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5117 | case -ENOMEM: |
| 5118 | case -NFS4ERR_DENIED: |
| 5119 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5120 | err = 0; |
| 5121 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5122 | case -NFS4ERR_DELAY: |
| 5123 | break; |
| 5124 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5125 | err = nfs4_handle_exception(server, err, &exception); |
| 5126 | } while (exception.retry); |
| 5127 | out: |
| 5128 | return err; |
| 5129 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5130 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5131 | struct nfs_release_lockowner_data { |
| 5132 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5133 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5134 | struct nfs_release_lockowner_args args; |
| 5135 | }; |
| 5136 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5137 | static void nfs4_release_lockowner_release(void *calldata) |
| 5138 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5139 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5140 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5141 | kfree(calldata); |
| 5142 | } |
| 5143 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5144 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5145 | .rpc_release = nfs4_release_lockowner_release, |
| 5146 | }; |
| 5147 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5148 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5149 | { |
| 5150 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5151 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5152 | struct rpc_message msg = { |
| 5153 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5154 | }; |
| 5155 | |
| 5156 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5157 | return -EINVAL; |
| 5158 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5159 | if (!data) |
| 5160 | return -ENOMEM; |
| 5161 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5162 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5163 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5164 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5165 | data->args.lock_owner.s_dev = server->s_dev; |
| 5166 | msg.rpc_argp = &data->args; |
| 5167 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5168 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5169 | } |
| 5170 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5171 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5172 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5173 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5174 | const void *buf, size_t buflen, |
| 5175 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5176 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5177 | if (strcmp(key, "") != 0) |
| 5178 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5179 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5180 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5181 | } |
| 5182 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5183 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5184 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5185 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5186 | if (strcmp(key, "") != 0) |
| 5187 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5188 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5189 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5190 | } |
| 5191 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5192 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5193 | size_t list_len, const char *name, |
| 5194 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5195 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5196 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5197 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5198 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5199 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5200 | |
| 5201 | if (list && len <= list_len) |
| 5202 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5203 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5204 | } |
| 5205 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5206 | /* |
| 5207 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5208 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5209 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5210 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5211 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5212 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5213 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5214 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5215 | return; |
| 5216 | |
| 5217 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5218 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5219 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5220 | fattr->nlink = 2; |
| 5221 | } |
| 5222 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5223 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5224 | const struct qstr *name, |
| 5225 | struct nfs4_fs_locations *fs_locations, |
| 5226 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5227 | { |
| 5228 | struct nfs_server *server = NFS_SERVER(dir); |
| 5229 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5230 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5231 | }; |
| 5232 | struct nfs4_fs_locations_arg args = { |
| 5233 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5234 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5235 | .page = page, |
| 5236 | .bitmask = bitmask, |
| 5237 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5238 | struct nfs4_fs_locations_res res = { |
| 5239 | .fs_locations = fs_locations, |
| 5240 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5241 | struct rpc_message msg = { |
| 5242 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5243 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5244 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5245 | }; |
| 5246 | int status; |
| 5247 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5248 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5249 | |
| 5250 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5251 | * is not supported */ |
| 5252 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5253 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5254 | else |
| 5255 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5256 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5257 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5258 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5259 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5260 | 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] | 5261 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5262 | return status; |
| 5263 | } |
| 5264 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5265 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5266 | const struct qstr *name, |
| 5267 | struct nfs4_fs_locations *fs_locations, |
| 5268 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5269 | { |
| 5270 | struct nfs4_exception exception = { }; |
| 5271 | int err; |
| 5272 | do { |
| 5273 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5274 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5275 | &exception); |
| 5276 | } while (exception.retry); |
| 5277 | return err; |
| 5278 | } |
| 5279 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5280 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5281 | { |
| 5282 | int status; |
| 5283 | struct nfs4_secinfo_arg args = { |
| 5284 | .dir_fh = NFS_FH(dir), |
| 5285 | .name = name, |
| 5286 | }; |
| 5287 | struct nfs4_secinfo_res res = { |
| 5288 | .flavors = flavors, |
| 5289 | }; |
| 5290 | struct rpc_message msg = { |
| 5291 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5292 | .rpc_argp = &args, |
| 5293 | .rpc_resp = &res, |
| 5294 | }; |
| 5295 | |
| 5296 | dprintk("NFS call secinfo %s\n", name->name); |
| 5297 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5298 | dprintk("NFS reply secinfo: %d\n", status); |
| 5299 | return status; |
| 5300 | } |
| 5301 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5302 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5303 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5304 | { |
| 5305 | struct nfs4_exception exception = { }; |
| 5306 | int err; |
| 5307 | do { |
| 5308 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5309 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5310 | &exception); |
| 5311 | } while (exception.retry); |
| 5312 | return err; |
| 5313 | } |
| 5314 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5315 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5316 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5317 | * Check the exchange flags returned by the server for invalid flags, having |
| 5318 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5319 | * DS flags set. |
| 5320 | */ |
| 5321 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5322 | { |
| 5323 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5324 | goto out_inval; |
| 5325 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5326 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5327 | goto out_inval; |
| 5328 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5329 | goto out_inval; |
| 5330 | return NFS_OK; |
| 5331 | out_inval: |
| 5332 | return -NFS4ERR_INVAL; |
| 5333 | } |
| 5334 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5335 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5336 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5337 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5338 | { |
| 5339 | if (a->server_scope_sz == b->server_scope_sz && |
| 5340 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5341 | return true; |
| 5342 | |
| 5343 | return false; |
| 5344 | } |
| 5345 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5346 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5347 | * nfs4_proc_bind_conn_to_session() |
| 5348 | * |
| 5349 | * The 4.1 client currently uses the same TCP connection for the |
| 5350 | * fore and backchannel. |
| 5351 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5352 | 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] | 5353 | { |
| 5354 | int status; |
| 5355 | struct nfs41_bind_conn_to_session_res res; |
| 5356 | struct rpc_message msg = { |
| 5357 | .rpc_proc = |
| 5358 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5359 | .rpc_argp = clp, |
| 5360 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5361 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5362 | }; |
| 5363 | |
| 5364 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5365 | |
| 5366 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5367 | if (unlikely(res.session == NULL)) { |
| 5368 | status = -ENOMEM; |
| 5369 | goto out; |
| 5370 | } |
| 5371 | |
| 5372 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5373 | if (status == 0) { |
| 5374 | if (memcmp(res.session->sess_id.data, |
| 5375 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5376 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5377 | status = -EIO; |
| 5378 | goto out_session; |
| 5379 | } |
| 5380 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5381 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5382 | __func__); |
| 5383 | status = -EIO; |
| 5384 | goto out_session; |
| 5385 | } |
| 5386 | if (res.use_conn_in_rdma_mode) { |
| 5387 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5388 | __func__); |
| 5389 | status = -EIO; |
| 5390 | goto out_session; |
| 5391 | } |
| 5392 | } |
| 5393 | out_session: |
| 5394 | kfree(res.session); |
| 5395 | out: |
| 5396 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5397 | return status; |
| 5398 | } |
| 5399 | |
| 5400 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5401 | * nfs4_proc_exchange_id() |
| 5402 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5403 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5404 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5405 | * Since the clientid has expired, all compounds using sessions |
| 5406 | * associated with the stale clientid will be returning |
| 5407 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5408 | * be in some phase of session reset. |
| 5409 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5410 | 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] | 5411 | { |
| 5412 | nfs4_verifier verifier; |
| 5413 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5414 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5415 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5416 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5417 | }; |
| 5418 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5419 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5420 | }; |
| 5421 | int status; |
| 5422 | struct rpc_message msg = { |
| 5423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5424 | .rpc_argp = &args, |
| 5425 | .rpc_resp = &res, |
| 5426 | .rpc_cred = cred, |
| 5427 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5428 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5429 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5430 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5431 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5432 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5433 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5434 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5435 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5436 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5437 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5438 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5439 | status = -ENOMEM; |
| 5440 | goto out; |
| 5441 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5442 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5443 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5444 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5445 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5446 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5447 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5448 | } |
| 5449 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5450 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5451 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5452 | status = -ENOMEM; |
| 5453 | goto out_server_scope; |
| 5454 | } |
| 5455 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5456 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5457 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5458 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5459 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5460 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5461 | clp->cl_clientid = res.clientid; |
| 5462 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5463 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5464 | clp->cl_seqid = res.seqid; |
| 5465 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5466 | kfree(clp->cl_serverowner); |
| 5467 | clp->cl_serverowner = res.server_owner; |
| 5468 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5469 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5470 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5471 | kfree(clp->cl_implid); |
| 5472 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5473 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5474 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5475 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5476 | res.server_scope)) { |
| 5477 | dprintk("%s: server_scope mismatch detected\n", |
| 5478 | __func__); |
| 5479 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5480 | kfree(clp->cl_serverscope); |
| 5481 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5482 | } |
| 5483 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5484 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5485 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5486 | goto out; |
| 5487 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5488 | } else |
| 5489 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5490 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5491 | out_server_owner: |
| 5492 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5493 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5494 | kfree(res.server_scope); |
| 5495 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5496 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5497 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5498 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5499 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5500 | clp->cl_implid->date.seconds, |
| 5501 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5502 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5503 | return status; |
| 5504 | } |
| 5505 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5506 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5507 | struct rpc_cred *cred) |
| 5508 | { |
| 5509 | struct rpc_message msg = { |
| 5510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5511 | .rpc_argp = clp, |
| 5512 | .rpc_cred = cred, |
| 5513 | }; |
| 5514 | int status; |
| 5515 | |
| 5516 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5517 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5518 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5519 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5520 | return status; |
| 5521 | } |
| 5522 | |
| 5523 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5524 | struct rpc_cred *cred) |
| 5525 | { |
| 5526 | unsigned int loop; |
| 5527 | int ret; |
| 5528 | |
| 5529 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5530 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5531 | switch (ret) { |
| 5532 | case -NFS4ERR_DELAY: |
| 5533 | case -NFS4ERR_CLIENTID_BUSY: |
| 5534 | ssleep(1); |
| 5535 | break; |
| 5536 | default: |
| 5537 | return ret; |
| 5538 | } |
| 5539 | } |
| 5540 | return 0; |
| 5541 | } |
| 5542 | |
| 5543 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5544 | { |
| 5545 | struct rpc_cred *cred; |
| 5546 | int ret = 0; |
| 5547 | |
| 5548 | if (clp->cl_mvops->minor_version < 1) |
| 5549 | goto out; |
| 5550 | if (clp->cl_exchange_flags == 0) |
| 5551 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5552 | if (clp->cl_preserve_clid) |
| 5553 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5554 | cred = nfs4_get_exchange_id_cred(clp); |
| 5555 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5556 | if (cred) |
| 5557 | put_rpccred(cred); |
| 5558 | switch (ret) { |
| 5559 | case 0: |
| 5560 | case -NFS4ERR_STALE_CLIENTID: |
| 5561 | clp->cl_exchange_flags = 0; |
| 5562 | } |
| 5563 | out: |
| 5564 | return ret; |
| 5565 | } |
| 5566 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5567 | struct nfs4_get_lease_time_data { |
| 5568 | struct nfs4_get_lease_time_args *args; |
| 5569 | struct nfs4_get_lease_time_res *res; |
| 5570 | struct nfs_client *clp; |
| 5571 | }; |
| 5572 | |
| 5573 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5574 | void *calldata) |
| 5575 | { |
| 5576 | int ret; |
| 5577 | struct nfs4_get_lease_time_data *data = |
| 5578 | (struct nfs4_get_lease_time_data *)calldata; |
| 5579 | |
| 5580 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5581 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5582 | /* just setup sequence, do not trigger session recovery |
| 5583 | since we're invoked within one */ |
| 5584 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5585 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5586 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5587 | |
Trond Myklebust | d3edcf9 | 2012-10-15 13:14:43 -0400 | [diff] [blame] | 5588 | if (ret != -EAGAIN) |
| 5589 | rpc_call_start(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5590 | dprintk("<-- %s\n", __func__); |
| 5591 | } |
| 5592 | |
| 5593 | /* |
| 5594 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5595 | * from sequence operation or clientid errors. |
| 5596 | */ |
| 5597 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5598 | { |
| 5599 | struct nfs4_get_lease_time_data *data = |
| 5600 | (struct nfs4_get_lease_time_data *)calldata; |
| 5601 | |
| 5602 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5603 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5604 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5605 | switch (task->tk_status) { |
| 5606 | case -NFS4ERR_DELAY: |
| 5607 | case -NFS4ERR_GRACE: |
| 5608 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5609 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5610 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5611 | /* fall through */ |
| 5612 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5613 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5614 | return; |
| 5615 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5616 | dprintk("<-- %s\n", __func__); |
| 5617 | } |
| 5618 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5619 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5620 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5621 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5622 | }; |
| 5623 | |
| 5624 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5625 | { |
| 5626 | struct rpc_task *task; |
| 5627 | struct nfs4_get_lease_time_args args; |
| 5628 | struct nfs4_get_lease_time_res res = { |
| 5629 | .lr_fsinfo = fsinfo, |
| 5630 | }; |
| 5631 | struct nfs4_get_lease_time_data data = { |
| 5632 | .args = &args, |
| 5633 | .res = &res, |
| 5634 | .clp = clp, |
| 5635 | }; |
| 5636 | struct rpc_message msg = { |
| 5637 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5638 | .rpc_argp = &args, |
| 5639 | .rpc_resp = &res, |
| 5640 | }; |
| 5641 | struct rpc_task_setup task_setup = { |
| 5642 | .rpc_client = clp->cl_rpcclient, |
| 5643 | .rpc_message = &msg, |
| 5644 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5645 | .callback_data = &data, |
| 5646 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5647 | }; |
| 5648 | int status; |
| 5649 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5650 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5651 | dprintk("--> %s\n", __func__); |
| 5652 | task = rpc_run_task(&task_setup); |
| 5653 | |
| 5654 | if (IS_ERR(task)) |
| 5655 | status = PTR_ERR(task); |
| 5656 | else { |
| 5657 | status = task->tk_status; |
| 5658 | rpc_put_task(task); |
| 5659 | } |
| 5660 | dprintk("<-- %s return %d\n", __func__, status); |
| 5661 | |
| 5662 | return status; |
| 5663 | } |
| 5664 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5665 | struct nfs4_slot *nfs4_alloc_slots(struct nfs4_slot_table *table, |
| 5666 | u32 max_slots, gfp_t gfp_flags) |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5667 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5668 | struct nfs4_slot *tbl; |
| 5669 | u32 i; |
| 5670 | |
| 5671 | tbl = kmalloc_array(max_slots, sizeof(*tbl), gfp_flags); |
| 5672 | if (tbl != NULL) { |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 5673 | for (i = 0; i < max_slots; i++) { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5674 | tbl[i].table = table; |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 5675 | tbl[i].slot_nr = i; |
| 5676 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5677 | } |
| 5678 | return tbl; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5682 | struct nfs4_slot *new, |
| 5683 | u32 max_slots, |
| 5684 | u32 ivalue) |
| 5685 | { |
| 5686 | struct nfs4_slot *old = NULL; |
| 5687 | u32 i; |
| 5688 | |
| 5689 | spin_lock(&tbl->slot_tbl_lock); |
| 5690 | if (new) { |
| 5691 | old = tbl->slots; |
| 5692 | tbl->slots = new; |
| 5693 | tbl->max_slots = max_slots; |
| 5694 | } |
Trond Myklebust | f9b1ef5 | 2012-10-29 16:48:40 -0400 | [diff] [blame] | 5695 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5696 | for (i = 0; i < tbl->max_slots; i++) |
| 5697 | tbl->slots[i].seq_nr = ivalue; |
| 5698 | spin_unlock(&tbl->slot_tbl_lock); |
| 5699 | kfree(old); |
| 5700 | } |
| 5701 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5702 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5703 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5704 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5705 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5706 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5707 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5708 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5709 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5710 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5711 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5712 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5713 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5714 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5715 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5716 | new = nfs4_alloc_slots(tbl, max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5717 | if (!new) |
| 5718 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5719 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5720 | ret = 0; |
| 5721 | |
| 5722 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5723 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5724 | tbl, tbl->slots, tbl->max_slots); |
| 5725 | out: |
| 5726 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5727 | return ret; |
| 5728 | } |
| 5729 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5730 | /* Destroy the slot table */ |
| 5731 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5732 | { |
| 5733 | if (session->fc_slot_table.slots != NULL) { |
| 5734 | kfree(session->fc_slot_table.slots); |
| 5735 | session->fc_slot_table.slots = NULL; |
| 5736 | } |
| 5737 | if (session->bc_slot_table.slots != NULL) { |
| 5738 | kfree(session->bc_slot_table.slots); |
| 5739 | session->bc_slot_table.slots = NULL; |
| 5740 | } |
| 5741 | return; |
| 5742 | } |
| 5743 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5744 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5745 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5746 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5747 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5748 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5749 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5750 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5751 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5752 | dprintk("--> %s\n", __func__); |
| 5753 | /* Fore channel */ |
| 5754 | tbl = &ses->fc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5755 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5756 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5757 | if (status) /* -ENOMEM */ |
| 5758 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5759 | /* Back channel */ |
| 5760 | tbl = &ses->bc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5761 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5762 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5763 | if (status && tbl->slots == NULL) |
| 5764 | /* Fore and back channel share a connection so get |
| 5765 | * both slot tables or neither */ |
| 5766 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5767 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5771 | { |
| 5772 | struct nfs4_session *session; |
| 5773 | struct nfs4_slot_table *tbl; |
| 5774 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5775 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5776 | if (!session) |
| 5777 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5778 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5779 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5780 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5781 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5782 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5783 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5784 | |
| 5785 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5786 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5787 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5788 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5789 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5790 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5791 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5792 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5793 | session->clp = clp; |
| 5794 | return session; |
| 5795 | } |
| 5796 | |
| 5797 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5798 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5799 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5800 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5801 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5802 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5803 | nfs4_proc_destroy_session(session, cred); |
| 5804 | if (cred) |
| 5805 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5806 | |
| 5807 | rcu_read_lock(); |
| 5808 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5809 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5810 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5811 | __func__, xprt); |
| 5812 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5813 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5814 | kfree(session); |
| 5815 | } |
| 5816 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5817 | /* |
| 5818 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5819 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5820 | * use them. |
| 5821 | * |
| 5822 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5823 | * always set csa_cachethis to FALSE because the current implementation |
| 5824 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5825 | */ |
| 5826 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5827 | { |
| 5828 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5829 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5830 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5831 | |
| 5832 | if (mxrqst_sz == 0) |
| 5833 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5834 | if (mxresp_sz == 0) |
| 5835 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5836 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5837 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5838 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5839 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5840 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5841 | |
| 5842 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5843 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5844 | __func__, |
| 5845 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5846 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5847 | |
| 5848 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5849 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5850 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5851 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5852 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5853 | args->bc_attrs.max_reqs = 1; |
| 5854 | |
| 5855 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5856 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5857 | __func__, |
| 5858 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5859 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5860 | args->bc_attrs.max_reqs); |
| 5861 | } |
| 5862 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5863 | 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] | 5864 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5865 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5866 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5867 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5868 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5869 | return -EINVAL; |
| 5870 | /* |
| 5871 | * Our requested max_ops is the minimum we need; we're not |
| 5872 | * prepared to break up compounds into smaller pieces than that. |
| 5873 | * So, no point even trying to continue if the server won't |
| 5874 | * cooperate: |
| 5875 | */ |
| 5876 | if (rcvd->max_ops < sent->max_ops) |
| 5877 | return -EINVAL; |
| 5878 | if (rcvd->max_reqs == 0) |
| 5879 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5880 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5881 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5882 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5883 | } |
| 5884 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5885 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5886 | { |
| 5887 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5888 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
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 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5891 | return -EINVAL; |
| 5892 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5893 | return -EINVAL; |
| 5894 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5895 | return -EINVAL; |
| 5896 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5897 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5898 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5899 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5900 | return -EINVAL; |
| 5901 | return 0; |
| 5902 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5903 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5904 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5905 | struct nfs4_session *session) |
| 5906 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5907 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5908 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5909 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5910 | if (ret) |
| 5911 | return ret; |
| 5912 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5913 | } |
| 5914 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5915 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5916 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5917 | { |
| 5918 | struct nfs4_session *session = clp->cl_session; |
| 5919 | struct nfs41_create_session_args args = { |
| 5920 | .client = clp, |
| 5921 | .cb_program = NFS4_CALLBACK, |
| 5922 | }; |
| 5923 | struct nfs41_create_session_res res = { |
| 5924 | .client = clp, |
| 5925 | }; |
| 5926 | struct rpc_message msg = { |
| 5927 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5928 | .rpc_argp = &args, |
| 5929 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5930 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5931 | }; |
| 5932 | int status; |
| 5933 | |
| 5934 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5935 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5936 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5937 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5938 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5939 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5940 | /* Verify the session's negotiated channel_attrs values */ |
| 5941 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5942 | /* Increment the clientid slot sequence id */ |
| 5943 | clp->cl_seqid++; |
| 5944 | } |
| 5945 | |
| 5946 | return status; |
| 5947 | } |
| 5948 | |
| 5949 | /* |
| 5950 | * Issues a CREATE_SESSION operation to the server. |
| 5951 | * It is the responsibility of the caller to verify the session is |
| 5952 | * expired before calling this routine. |
| 5953 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5954 | 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] | 5955 | { |
| 5956 | int status; |
| 5957 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5958 | struct nfs4_session *session = clp->cl_session; |
| 5959 | |
| 5960 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5961 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5962 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5963 | if (status) |
| 5964 | goto out; |
| 5965 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5966 | /* Init or reset the session slot tables */ |
| 5967 | status = nfs4_setup_session_slot_tables(session); |
| 5968 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5969 | if (status) |
| 5970 | goto out; |
| 5971 | |
| 5972 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5973 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5974 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5975 | out: |
| 5976 | dprintk("<-- %s\n", __func__); |
| 5977 | return status; |
| 5978 | } |
| 5979 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5980 | /* |
| 5981 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5982 | * The caller must serialize access to this routine. |
| 5983 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5984 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5985 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5986 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5987 | struct rpc_message msg = { |
| 5988 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5989 | .rpc_argp = session, |
| 5990 | .rpc_cred = cred, |
| 5991 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5992 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5993 | |
| 5994 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5995 | |
| 5996 | /* session is still being setup */ |
| 5997 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5998 | return status; |
| 5999 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6000 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6001 | |
| 6002 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6003 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6004 | "Session has been destroyed regardless...\n", status); |
| 6005 | |
| 6006 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6007 | return status; |
| 6008 | } |
| 6009 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6010 | /* |
| 6011 | * With sessions, the client is not marked ready until after a |
| 6012 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 6013 | * |
| 6014 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 6015 | * other versions of NFS can be tried. |
| 6016 | */ |
| 6017 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 6018 | { |
| 6019 | int ret; |
| 6020 | |
| 6021 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 6022 | ret = nfs4_client_recover_expired_lease(clp); |
| 6023 | if (ret) |
| 6024 | return ret; |
| 6025 | } |
| 6026 | if (clp->cl_cons_state < NFS_CS_READY) |
| 6027 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 6028 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6029 | return 0; |
| 6030 | } |
| 6031 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6032 | int nfs4_init_session(struct nfs_server *server) |
| 6033 | { |
| 6034 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6035 | struct nfs4_session *session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6036 | unsigned int target_max_rqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 6037 | unsigned int target_max_resp_sz = NFS_MAX_FILE_IO_SIZE; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6038 | |
| 6039 | if (!nfs4_has_session(clp)) |
| 6040 | return 0; |
| 6041 | |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6042 | if (server->rsize != 0) |
| 6043 | target_max_resp_sz = server->rsize; |
| 6044 | target_max_resp_sz += nfs41_maxread_overhead; |
| 6045 | |
| 6046 | if (server->wsize != 0) |
| 6047 | target_max_rqst_sz = server->wsize; |
| 6048 | target_max_rqst_sz += nfs41_maxwrite_overhead; |
| 6049 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6050 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6051 | spin_lock(&clp->cl_lock); |
| 6052 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6053 | /* Initialise targets and channel attributes */ |
| 6054 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6055 | session->fc_attrs.max_rqst_sz = target_max_rqst_sz; |
| 6056 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6057 | session->fc_attrs.max_resp_sz = target_max_resp_sz; |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6058 | } else { |
| 6059 | /* Just adjust the targets */ |
| 6060 | if (target_max_rqst_sz > session->fc_target_max_rqst_sz) { |
| 6061 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6062 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6063 | } |
| 6064 | if (target_max_resp_sz > session->fc_target_max_resp_sz) { |
| 6065 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6066 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6067 | } |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6068 | } |
| 6069 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6070 | |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6071 | if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)) |
| 6072 | nfs4_schedule_lease_recovery(clp); |
| 6073 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6074 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6075 | } |
| 6076 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6077 | 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] | 6078 | { |
| 6079 | struct nfs4_session *session = clp->cl_session; |
| 6080 | int ret; |
| 6081 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6082 | spin_lock(&clp->cl_lock); |
| 6083 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 6084 | /* |
| 6085 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 6086 | * DS lease to be equal to the MDS lease. |
| 6087 | */ |
| 6088 | clp->cl_lease_time = lease_time; |
| 6089 | clp->cl_last_renewal = jiffies; |
| 6090 | } |
| 6091 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6092 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6093 | ret = nfs41_check_session_ready(clp); |
| 6094 | if (ret) |
| 6095 | return ret; |
| 6096 | /* Test for the DS role */ |
| 6097 | if (!is_ds_client(clp)) |
| 6098 | return -ENODEV; |
| 6099 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6100 | } |
| 6101 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 6102 | |
| 6103 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6104 | /* |
| 6105 | * Renew the cl_session lease. |
| 6106 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6107 | struct nfs4_sequence_data { |
| 6108 | struct nfs_client *clp; |
| 6109 | struct nfs4_sequence_args args; |
| 6110 | struct nfs4_sequence_res res; |
| 6111 | }; |
| 6112 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6113 | static void nfs41_sequence_release(void *data) |
| 6114 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6115 | struct nfs4_sequence_data *calldata = data; |
| 6116 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6117 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6118 | if (atomic_read(&clp->cl_count) > 1) |
| 6119 | nfs4_schedule_state_renewal(clp); |
| 6120 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6121 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6122 | } |
| 6123 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6124 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6125 | { |
| 6126 | switch(task->tk_status) { |
| 6127 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6128 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6129 | return -EAGAIN; |
| 6130 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6131 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6132 | } |
| 6133 | return 0; |
| 6134 | } |
| 6135 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6136 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6137 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6138 | struct nfs4_sequence_data *calldata = data; |
| 6139 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6140 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6141 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6142 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6143 | |
| 6144 | if (task->tk_status < 0) { |
| 6145 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6146 | if (atomic_read(&clp->cl_count) == 1) |
| 6147 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6148 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6149 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6150 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6151 | return; |
| 6152 | } |
| 6153 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6154 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6155 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6156 | dprintk("<-- %s\n", __func__); |
| 6157 | } |
| 6158 | |
| 6159 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6160 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6161 | struct nfs4_sequence_data *calldata = data; |
| 6162 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6163 | struct nfs4_sequence_args *args; |
| 6164 | struct nfs4_sequence_res *res; |
| 6165 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6166 | args = task->tk_msg.rpc_argp; |
| 6167 | res = task->tk_msg.rpc_resp; |
| 6168 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6169 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6170 | return; |
| 6171 | rpc_call_start(task); |
| 6172 | } |
| 6173 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6174 | static void nfs41_sequence_prepare_privileged(struct rpc_task *task, void *data) |
| 6175 | { |
| 6176 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 6177 | nfs41_sequence_prepare(task, data); |
| 6178 | } |
| 6179 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6180 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6181 | .rpc_call_done = nfs41_sequence_call_done, |
| 6182 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6183 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6184 | }; |
| 6185 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6186 | static const struct rpc_call_ops nfs41_sequence_privileged_ops = { |
| 6187 | .rpc_call_done = nfs41_sequence_call_done, |
| 6188 | .rpc_call_prepare = nfs41_sequence_prepare_privileged, |
| 6189 | .rpc_release = nfs41_sequence_release, |
| 6190 | }; |
| 6191 | |
| 6192 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred, |
| 6193 | const struct rpc_call_ops *seq_ops) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6194 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6195 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6196 | struct rpc_message msg = { |
| 6197 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6198 | .rpc_cred = cred, |
| 6199 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6200 | struct rpc_task_setup task_setup_data = { |
| 6201 | .rpc_client = clp->cl_rpcclient, |
| 6202 | .rpc_message = &msg, |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6203 | .callback_ops = seq_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6204 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6205 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6206 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6207 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6208 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6209 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6210 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6211 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6212 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6213 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6214 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6215 | msg.rpc_argp = &calldata->args; |
| 6216 | msg.rpc_resp = &calldata->res; |
| 6217 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6218 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6219 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6220 | return rpc_run_task(&task_setup_data); |
| 6221 | } |
| 6222 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6223 | 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] | 6224 | { |
| 6225 | struct rpc_task *task; |
| 6226 | int ret = 0; |
| 6227 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6228 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6229 | return 0; |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6230 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6231 | if (IS_ERR(task)) |
| 6232 | ret = PTR_ERR(task); |
| 6233 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6234 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6235 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6236 | return ret; |
| 6237 | } |
| 6238 | |
| 6239 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6240 | { |
| 6241 | struct rpc_task *task; |
| 6242 | int ret; |
| 6243 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6244 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_privileged_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6245 | if (IS_ERR(task)) { |
| 6246 | ret = PTR_ERR(task); |
| 6247 | goto out; |
| 6248 | } |
| 6249 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6250 | if (!ret) { |
| 6251 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6252 | |
| 6253 | if (task->tk_status == 0) |
| 6254 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6255 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6256 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6257 | rpc_put_task(task); |
| 6258 | out: |
| 6259 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6260 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6261 | } |
| 6262 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6263 | struct nfs4_reclaim_complete_data { |
| 6264 | struct nfs_client *clp; |
| 6265 | struct nfs41_reclaim_complete_args arg; |
| 6266 | struct nfs41_reclaim_complete_res res; |
| 6267 | }; |
| 6268 | |
| 6269 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6270 | { |
| 6271 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6272 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6273 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6274 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6275 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6276 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6277 | return; |
| 6278 | |
| 6279 | rpc_call_start(task); |
| 6280 | } |
| 6281 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6282 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6283 | { |
| 6284 | switch(task->tk_status) { |
| 6285 | case 0: |
| 6286 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6287 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6288 | break; |
| 6289 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6290 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6291 | /* fall through */ |
| 6292 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6293 | return -EAGAIN; |
| 6294 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6295 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6296 | } |
| 6297 | return 0; |
| 6298 | } |
| 6299 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6300 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6301 | { |
| 6302 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6303 | struct nfs_client *clp = calldata->clp; |
| 6304 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6305 | |
| 6306 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6307 | if (!nfs41_sequence_done(task, res)) |
| 6308 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6309 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6310 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6311 | rpc_restart_call_prepare(task); |
| 6312 | return; |
| 6313 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6314 | dprintk("<-- %s\n", __func__); |
| 6315 | } |
| 6316 | |
| 6317 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6318 | { |
| 6319 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6320 | |
| 6321 | kfree(calldata); |
| 6322 | } |
| 6323 | |
| 6324 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6325 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6326 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6327 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6328 | }; |
| 6329 | |
| 6330 | /* |
| 6331 | * Issue a global reclaim complete. |
| 6332 | */ |
| 6333 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6334 | { |
| 6335 | struct nfs4_reclaim_complete_data *calldata; |
| 6336 | struct rpc_task *task; |
| 6337 | struct rpc_message msg = { |
| 6338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6339 | }; |
| 6340 | struct rpc_task_setup task_setup_data = { |
| 6341 | .rpc_client = clp->cl_rpcclient, |
| 6342 | .rpc_message = &msg, |
| 6343 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6344 | .flags = RPC_TASK_ASYNC, |
| 6345 | }; |
| 6346 | int status = -ENOMEM; |
| 6347 | |
| 6348 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6349 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6350 | if (calldata == NULL) |
| 6351 | goto out; |
| 6352 | calldata->clp = clp; |
| 6353 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6354 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6355 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6356 | msg.rpc_argp = &calldata->arg; |
| 6357 | msg.rpc_resp = &calldata->res; |
| 6358 | task_setup_data.callback_data = calldata; |
| 6359 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6360 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6361 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6362 | goto out; |
| 6363 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6364 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6365 | if (status == 0) |
| 6366 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6367 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6368 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6369 | out: |
| 6370 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6371 | return status; |
| 6372 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6373 | |
| 6374 | static void |
| 6375 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6376 | { |
| 6377 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6378 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6379 | |
| 6380 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6381 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6382 | * right now covering the LAYOUTGET we are about to send. |
| 6383 | * However, that is not so catastrophic, and there seems |
| 6384 | * to be no way to prevent it completely. |
| 6385 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6386 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6387 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6388 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6389 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6390 | NFS_I(lgp->args.inode)->layout, |
| 6391 | lgp->args.ctx->state)) { |
| 6392 | rpc_exit(task, NFS4_OK); |
| 6393 | return; |
| 6394 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6395 | rpc_call_start(task); |
| 6396 | } |
| 6397 | |
| 6398 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6399 | { |
| 6400 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6401 | struct inode *inode = lgp->args.inode; |
| 6402 | struct nfs_server *server = NFS_SERVER(inode); |
| 6403 | struct pnfs_layout_hdr *lo; |
| 6404 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6405 | |
| 6406 | dprintk("--> %s\n", __func__); |
| 6407 | |
| 6408 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6409 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6410 | |
| 6411 | switch (task->tk_status) { |
| 6412 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6413 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6414 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6415 | case -NFS4ERR_RECALLCONFLICT: |
| 6416 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6417 | break; |
| 6418 | case -NFS4ERR_EXPIRED: |
| 6419 | case -NFS4ERR_BAD_STATEID: |
| 6420 | spin_lock(&inode->i_lock); |
| 6421 | lo = NFS_I(inode)->layout; |
| 6422 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6423 | spin_unlock(&inode->i_lock); |
| 6424 | /* If the open stateid was bad, then recover it. */ |
| 6425 | state = lgp->args.ctx->state; |
| 6426 | } else { |
| 6427 | LIST_HEAD(head); |
| 6428 | |
| 6429 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6430 | spin_unlock(&inode->i_lock); |
| 6431 | /* Mark the bad layout state as invalid, then |
| 6432 | * retry using the open stateid. */ |
| 6433 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6434 | } |
| 6435 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6436 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6437 | rpc_restart_call_prepare(task); |
| 6438 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6439 | dprintk("<-- %s\n", __func__); |
| 6440 | } |
| 6441 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6442 | static size_t max_response_pages(struct nfs_server *server) |
| 6443 | { |
| 6444 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6445 | return nfs_page_array_len(0, max_resp_sz); |
| 6446 | } |
| 6447 | |
| 6448 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6449 | { |
| 6450 | int i; |
| 6451 | |
| 6452 | if (!pages) |
| 6453 | return; |
| 6454 | |
| 6455 | for (i = 0; i < size; i++) { |
| 6456 | if (!pages[i]) |
| 6457 | break; |
| 6458 | __free_page(pages[i]); |
| 6459 | } |
| 6460 | kfree(pages); |
| 6461 | } |
| 6462 | |
| 6463 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6464 | { |
| 6465 | struct page **pages; |
| 6466 | int i; |
| 6467 | |
| 6468 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6469 | if (!pages) { |
| 6470 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6471 | return NULL; |
| 6472 | } |
| 6473 | |
| 6474 | for (i = 0; i < size; i++) { |
| 6475 | pages[i] = alloc_page(gfp_flags); |
| 6476 | if (!pages[i]) { |
| 6477 | dprintk("%s: failed to allocate page\n", __func__); |
| 6478 | nfs4_free_pages(pages, size); |
| 6479 | return NULL; |
| 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | return pages; |
| 6484 | } |
| 6485 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6486 | static void nfs4_layoutget_release(void *calldata) |
| 6487 | { |
| 6488 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6489 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6490 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6491 | |
| 6492 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6493 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6494 | put_nfs_open_context(lgp->args.ctx); |
| 6495 | kfree(calldata); |
| 6496 | dprintk("<-- %s\n", __func__); |
| 6497 | } |
| 6498 | |
| 6499 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6500 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6501 | .rpc_call_done = nfs4_layoutget_done, |
| 6502 | .rpc_release = nfs4_layoutget_release, |
| 6503 | }; |
| 6504 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6505 | struct pnfs_layout_segment * |
| 6506 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6507 | { |
| 6508 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6509 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6510 | struct rpc_task *task; |
| 6511 | struct rpc_message msg = { |
| 6512 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6513 | .rpc_argp = &lgp->args, |
| 6514 | .rpc_resp = &lgp->res, |
| 6515 | }; |
| 6516 | struct rpc_task_setup task_setup_data = { |
| 6517 | .rpc_client = server->client, |
| 6518 | .rpc_message = &msg, |
| 6519 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6520 | .callback_data = lgp, |
| 6521 | .flags = RPC_TASK_ASYNC, |
| 6522 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6523 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6524 | int status = 0; |
| 6525 | |
| 6526 | dprintk("--> %s\n", __func__); |
| 6527 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6528 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6529 | if (!lgp->args.layout.pages) { |
| 6530 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6531 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6532 | } |
| 6533 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6534 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6535 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6536 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6537 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6538 | task = rpc_run_task(&task_setup_data); |
| 6539 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6540 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6541 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6542 | if (status == 0) |
| 6543 | status = task->tk_status; |
| 6544 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6545 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6546 | rpc_put_task(task); |
| 6547 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6548 | if (status) |
| 6549 | return ERR_PTR(status); |
| 6550 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6551 | } |
| 6552 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6553 | static void |
| 6554 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6555 | { |
| 6556 | struct nfs4_layoutreturn *lrp = calldata; |
| 6557 | |
| 6558 | dprintk("--> %s\n", __func__); |
| 6559 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6560 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6561 | return; |
| 6562 | rpc_call_start(task); |
| 6563 | } |
| 6564 | |
| 6565 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6566 | { |
| 6567 | struct nfs4_layoutreturn *lrp = calldata; |
| 6568 | struct nfs_server *server; |
| 6569 | |
| 6570 | dprintk("--> %s\n", __func__); |
| 6571 | |
| 6572 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6573 | return; |
| 6574 | |
| 6575 | server = NFS_SERVER(lrp->args.inode); |
| 6576 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6577 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6578 | return; |
| 6579 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6580 | dprintk("<-- %s\n", __func__); |
| 6581 | } |
| 6582 | |
| 6583 | static void nfs4_layoutreturn_release(void *calldata) |
| 6584 | { |
| 6585 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6586 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6587 | |
| 6588 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6589 | spin_lock(&lo->plh_inode->i_lock); |
| 6590 | if (lrp->res.lrs_present) |
| 6591 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6592 | lo->plh_block_lgets--; |
| 6593 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6594 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6595 | kfree(calldata); |
| 6596 | dprintk("<-- %s\n", __func__); |
| 6597 | } |
| 6598 | |
| 6599 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6600 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6601 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6602 | .rpc_release = nfs4_layoutreturn_release, |
| 6603 | }; |
| 6604 | |
| 6605 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6606 | { |
| 6607 | struct rpc_task *task; |
| 6608 | struct rpc_message msg = { |
| 6609 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6610 | .rpc_argp = &lrp->args, |
| 6611 | .rpc_resp = &lrp->res, |
| 6612 | }; |
| 6613 | struct rpc_task_setup task_setup_data = { |
| 6614 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6615 | .rpc_message = &msg, |
| 6616 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6617 | .callback_data = lrp, |
| 6618 | }; |
| 6619 | int status; |
| 6620 | |
| 6621 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6622 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6623 | task = rpc_run_task(&task_setup_data); |
| 6624 | if (IS_ERR(task)) |
| 6625 | return PTR_ERR(task); |
| 6626 | status = task->tk_status; |
| 6627 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6628 | rpc_put_task(task); |
| 6629 | return status; |
| 6630 | } |
| 6631 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6632 | /* |
| 6633 | * Retrieve the list of Data Server devices from the MDS. |
| 6634 | */ |
| 6635 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6636 | const struct nfs_fh *fh, |
| 6637 | struct pnfs_devicelist *devlist) |
| 6638 | { |
| 6639 | struct nfs4_getdevicelist_args args = { |
| 6640 | .fh = fh, |
| 6641 | .layoutclass = server->pnfs_curr_ld->id, |
| 6642 | }; |
| 6643 | struct nfs4_getdevicelist_res res = { |
| 6644 | .devlist = devlist, |
| 6645 | }; |
| 6646 | struct rpc_message msg = { |
| 6647 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6648 | .rpc_argp = &args, |
| 6649 | .rpc_resp = &res, |
| 6650 | }; |
| 6651 | int status; |
| 6652 | |
| 6653 | dprintk("--> %s\n", __func__); |
| 6654 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6655 | &res.seq_res, 0); |
| 6656 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6657 | return status; |
| 6658 | } |
| 6659 | |
| 6660 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6661 | const struct nfs_fh *fh, |
| 6662 | struct pnfs_devicelist *devlist) |
| 6663 | { |
| 6664 | struct nfs4_exception exception = { }; |
| 6665 | int err; |
| 6666 | |
| 6667 | do { |
| 6668 | err = nfs4_handle_exception(server, |
| 6669 | _nfs4_getdevicelist(server, fh, devlist), |
| 6670 | &exception); |
| 6671 | } while (exception.retry); |
| 6672 | |
| 6673 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6674 | err, devlist->num_devs); |
| 6675 | |
| 6676 | return err; |
| 6677 | } |
| 6678 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6679 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6680 | static int |
| 6681 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6682 | { |
| 6683 | struct nfs4_getdeviceinfo_args args = { |
| 6684 | .pdev = pdev, |
| 6685 | }; |
| 6686 | struct nfs4_getdeviceinfo_res res = { |
| 6687 | .pdev = pdev, |
| 6688 | }; |
| 6689 | struct rpc_message msg = { |
| 6690 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6691 | .rpc_argp = &args, |
| 6692 | .rpc_resp = &res, |
| 6693 | }; |
| 6694 | int status; |
| 6695 | |
| 6696 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6697 | 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] | 6698 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6699 | |
| 6700 | return status; |
| 6701 | } |
| 6702 | |
| 6703 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6704 | { |
| 6705 | struct nfs4_exception exception = { }; |
| 6706 | int err; |
| 6707 | |
| 6708 | do { |
| 6709 | err = nfs4_handle_exception(server, |
| 6710 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6711 | &exception); |
| 6712 | } while (exception.retry); |
| 6713 | return err; |
| 6714 | } |
| 6715 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6716 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6717 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6718 | { |
| 6719 | struct nfs4_layoutcommit_data *data = calldata; |
| 6720 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6721 | |
| 6722 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6723 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6724 | return; |
| 6725 | rpc_call_start(task); |
| 6726 | } |
| 6727 | |
| 6728 | static void |
| 6729 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6730 | { |
| 6731 | struct nfs4_layoutcommit_data *data = calldata; |
| 6732 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6733 | |
| 6734 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6735 | return; |
| 6736 | |
| 6737 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6738 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6739 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6740 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6741 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6742 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6743 | break; |
| 6744 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6745 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6746 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6747 | break; |
| 6748 | default: |
| 6749 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6750 | rpc_restart_call_prepare(task); |
| 6751 | return; |
| 6752 | } |
| 6753 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | static void nfs4_layoutcommit_release(void *calldata) |
| 6757 | { |
| 6758 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6759 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6760 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6761 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6762 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6763 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6764 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6765 | list_del_init(&lseg->pls_lc_list); |
| 6766 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6767 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6768 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6769 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6770 | |
| 6771 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6772 | smp_mb__after_clear_bit(); |
| 6773 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6774 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6775 | put_rpccred(data->cred); |
| 6776 | kfree(data); |
| 6777 | } |
| 6778 | |
| 6779 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6780 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6781 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6782 | .rpc_release = nfs4_layoutcommit_release, |
| 6783 | }; |
| 6784 | |
| 6785 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6786 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6787 | { |
| 6788 | struct rpc_message msg = { |
| 6789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6790 | .rpc_argp = &data->args, |
| 6791 | .rpc_resp = &data->res, |
| 6792 | .rpc_cred = data->cred, |
| 6793 | }; |
| 6794 | struct rpc_task_setup task_setup_data = { |
| 6795 | .task = &data->task, |
| 6796 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6797 | .rpc_message = &msg, |
| 6798 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6799 | .callback_data = data, |
| 6800 | .flags = RPC_TASK_ASYNC, |
| 6801 | }; |
| 6802 | struct rpc_task *task; |
| 6803 | int status = 0; |
| 6804 | |
| 6805 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6806 | "lbw: %llu inode %lu\n", |
| 6807 | data->task.tk_pid, sync, |
| 6808 | data->args.lastbytewritten, |
| 6809 | data->args.inode->i_ino); |
| 6810 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6811 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6812 | task = rpc_run_task(&task_setup_data); |
| 6813 | if (IS_ERR(task)) |
| 6814 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6815 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6816 | goto out; |
| 6817 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6818 | if (status != 0) |
| 6819 | goto out; |
| 6820 | status = task->tk_status; |
| 6821 | out: |
| 6822 | dprintk("%s: status %d\n", __func__, status); |
| 6823 | rpc_put_task(task); |
| 6824 | return status; |
| 6825 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6826 | |
| 6827 | static int |
| 6828 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6829 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6830 | { |
| 6831 | struct nfs41_secinfo_no_name_args args = { |
| 6832 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6833 | }; |
| 6834 | struct nfs4_secinfo_res res = { |
| 6835 | .flavors = flavors, |
| 6836 | }; |
| 6837 | struct rpc_message msg = { |
| 6838 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6839 | .rpc_argp = &args, |
| 6840 | .rpc_resp = &res, |
| 6841 | }; |
| 6842 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6843 | } |
| 6844 | |
| 6845 | static int |
| 6846 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6847 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6848 | { |
| 6849 | struct nfs4_exception exception = { }; |
| 6850 | int err; |
| 6851 | do { |
| 6852 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6853 | switch (err) { |
| 6854 | case 0: |
| 6855 | case -NFS4ERR_WRONGSEC: |
| 6856 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6857 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6858 | default: |
| 6859 | err = nfs4_handle_exception(server, err, &exception); |
| 6860 | } |
| 6861 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6862 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6863 | return err; |
| 6864 | } |
| 6865 | |
| 6866 | static int |
| 6867 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6868 | struct nfs_fsinfo *info) |
| 6869 | { |
| 6870 | int err; |
| 6871 | struct page *page; |
| 6872 | rpc_authflavor_t flavor; |
| 6873 | struct nfs4_secinfo_flavors *flavors; |
| 6874 | |
| 6875 | page = alloc_page(GFP_KERNEL); |
| 6876 | if (!page) { |
| 6877 | err = -ENOMEM; |
| 6878 | goto out; |
| 6879 | } |
| 6880 | |
| 6881 | flavors = page_address(page); |
| 6882 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6883 | |
| 6884 | /* |
| 6885 | * Fall back on "guess and check" method if |
| 6886 | * the server doesn't support SECINFO_NO_NAME |
| 6887 | */ |
| 6888 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6889 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6890 | goto out_freepage; |
| 6891 | } |
| 6892 | if (err) |
| 6893 | goto out_freepage; |
| 6894 | |
| 6895 | flavor = nfs_find_best_sec(flavors); |
| 6896 | if (err == 0) |
| 6897 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6898 | |
| 6899 | out_freepage: |
| 6900 | put_page(page); |
| 6901 | if (err == -EACCES) |
| 6902 | return -EPERM; |
| 6903 | out: |
| 6904 | return err; |
| 6905 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6906 | |
| 6907 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6908 | { |
| 6909 | int status; |
| 6910 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6911 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6912 | }; |
| 6913 | struct nfs41_test_stateid_res res; |
| 6914 | struct rpc_message msg = { |
| 6915 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6916 | .rpc_argp = &args, |
| 6917 | .rpc_resp = &res, |
| 6918 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6919 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6920 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6921 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6922 | 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] | 6923 | if (status != NFS_OK) { |
| 6924 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6925 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6926 | } |
| 6927 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6928 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6929 | } |
| 6930 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6931 | /** |
| 6932 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6933 | * |
| 6934 | * @server: server / transport on which to perform the operation |
| 6935 | * @stateid: state ID to test |
| 6936 | * |
| 6937 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6938 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6939 | * failed or the state ID is not currently valid. |
| 6940 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6941 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6942 | { |
| 6943 | struct nfs4_exception exception = { }; |
| 6944 | int err; |
| 6945 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6946 | err = _nfs41_test_stateid(server, stateid); |
| 6947 | if (err != -NFS4ERR_DELAY) |
| 6948 | break; |
| 6949 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6950 | } while (exception.retry); |
| 6951 | return err; |
| 6952 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6953 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6954 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6955 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6956 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6957 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6958 | }; |
| 6959 | struct nfs41_free_stateid_res res; |
| 6960 | struct rpc_message msg = { |
| 6961 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6962 | .rpc_argp = &args, |
| 6963 | .rpc_resp = &res, |
| 6964 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6965 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6966 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6967 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6968 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6969 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6970 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6971 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6972 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6973 | } |
| 6974 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6975 | /** |
| 6976 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6977 | * |
| 6978 | * @server: server / transport on which to perform the operation |
| 6979 | * @stateid: state ID to release |
| 6980 | * |
| 6981 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6982 | * negative NFS4ERR value is returned. |
| 6983 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6984 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6985 | { |
| 6986 | struct nfs4_exception exception = { }; |
| 6987 | int err; |
| 6988 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6989 | err = _nfs4_free_stateid(server, stateid); |
| 6990 | if (err != -NFS4ERR_DELAY) |
| 6991 | break; |
| 6992 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6993 | } while (exception.retry); |
| 6994 | return err; |
| 6995 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6996 | |
| 6997 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6998 | const nfs4_stateid *s2) |
| 6999 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7000 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7001 | return false; |
| 7002 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7003 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7004 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7005 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7006 | return true; |
| 7007 | |
| 7008 | return false; |
| 7009 | } |
| 7010 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7011 | #endif /* CONFIG_NFS_V4_1 */ |
| 7012 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7013 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7014 | const nfs4_stateid *s2) |
| 7015 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7016 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7020 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7021 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7022 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7023 | .recover_open = nfs4_open_reclaim, |
| 7024 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7025 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7026 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7027 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7028 | }; |
| 7029 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7030 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7031 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7032 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7033 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7034 | .recover_open = nfs4_open_reclaim, |
| 7035 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7036 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7037 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7038 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7039 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7040 | }; |
| 7041 | #endif /* CONFIG_NFS_V4_1 */ |
| 7042 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7043 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7044 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7045 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7046 | .recover_open = nfs4_open_expired, |
| 7047 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7048 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7049 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7050 | }; |
| 7051 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7052 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7053 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7054 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7055 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7056 | .recover_open = nfs41_open_expired, |
| 7057 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7058 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7059 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7060 | }; |
| 7061 | #endif /* CONFIG_NFS_V4_1 */ |
| 7062 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7063 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7064 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7065 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7066 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7067 | }; |
| 7068 | |
| 7069 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7070 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7071 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7072 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7073 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7074 | }; |
| 7075 | #endif |
| 7076 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7077 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7078 | .minor_version = 0, |
| 7079 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7080 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7081 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7082 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7083 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7084 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7085 | }; |
| 7086 | |
| 7087 | #if defined(CONFIG_NFS_V4_1) |
| 7088 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7089 | .minor_version = 1, |
| 7090 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7091 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7092 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7093 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7094 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7095 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7096 | }; |
| 7097 | #endif |
| 7098 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7099 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7100 | [0] = &nfs_v4_0_minor_ops, |
| 7101 | #if defined(CONFIG_NFS_V4_1) |
| 7102 | [1] = &nfs_v4_1_minor_ops, |
| 7103 | #endif |
| 7104 | }; |
| 7105 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7106 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7107 | .create = nfs_create, |
| 7108 | .lookup = nfs_lookup, |
| 7109 | .atomic_open = nfs_atomic_open, |
| 7110 | .link = nfs_link, |
| 7111 | .unlink = nfs_unlink, |
| 7112 | .symlink = nfs_symlink, |
| 7113 | .mkdir = nfs_mkdir, |
| 7114 | .rmdir = nfs_rmdir, |
| 7115 | .mknod = nfs_mknod, |
| 7116 | .rename = nfs_rename, |
| 7117 | .permission = nfs_permission, |
| 7118 | .getattr = nfs_getattr, |
| 7119 | .setattr = nfs_setattr, |
| 7120 | .getxattr = generic_getxattr, |
| 7121 | .setxattr = generic_setxattr, |
| 7122 | .listxattr = generic_listxattr, |
| 7123 | .removexattr = generic_removexattr, |
| 7124 | }; |
| 7125 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7126 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7127 | .permission = nfs_permission, |
| 7128 | .getattr = nfs_getattr, |
| 7129 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7130 | .getxattr = generic_getxattr, |
| 7131 | .setxattr = generic_setxattr, |
| 7132 | .listxattr = generic_listxattr, |
| 7133 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7134 | }; |
| 7135 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7136 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7137 | .version = 4, /* protocol version */ |
| 7138 | .dentry_ops = &nfs4_dentry_operations, |
| 7139 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7140 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7141 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7142 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7143 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7144 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7145 | .getattr = nfs4_proc_getattr, |
| 7146 | .setattr = nfs4_proc_setattr, |
| 7147 | .lookup = nfs4_proc_lookup, |
| 7148 | .access = nfs4_proc_access, |
| 7149 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7150 | .create = nfs4_proc_create, |
| 7151 | .remove = nfs4_proc_remove, |
| 7152 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7153 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7154 | .unlink_done = nfs4_proc_unlink_done, |
| 7155 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7156 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7157 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7158 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7159 | .link = nfs4_proc_link, |
| 7160 | .symlink = nfs4_proc_symlink, |
| 7161 | .mkdir = nfs4_proc_mkdir, |
| 7162 | .rmdir = nfs4_proc_remove, |
| 7163 | .readdir = nfs4_proc_readdir, |
| 7164 | .mknod = nfs4_proc_mknod, |
| 7165 | .statfs = nfs4_proc_statfs, |
| 7166 | .fsinfo = nfs4_proc_fsinfo, |
| 7167 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7168 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7169 | .decode_dirent = nfs4_decode_dirent, |
| 7170 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7171 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7172 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7173 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7174 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7175 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7176 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7177 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7178 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7179 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7180 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7181 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7182 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7183 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7184 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7185 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7186 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7187 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7188 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7189 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7190 | .create_server = nfs4_create_server, |
| 7191 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7192 | }; |
| 7193 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7194 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7195 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7196 | .list = nfs4_xattr_list_nfs4_acl, |
| 7197 | .get = nfs4_xattr_get_nfs4_acl, |
| 7198 | .set = nfs4_xattr_set_nfs4_acl, |
| 7199 | }; |
| 7200 | |
| 7201 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7202 | &nfs4_xattr_nfs4_acl_handler, |
| 7203 | NULL |
| 7204 | }; |
| 7205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7206 | /* |
| 7207 | * Local variables: |
| 7208 | * c-basic-offset: 8 |
| 7209 | * End: |
| 7210 | */ |