Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 55 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 56 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 57 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 58 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 60 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 62 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 63 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 64 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 65 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 66 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 75 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 76 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 77 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 79 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 80 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 81 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 82 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 83 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 84 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 85 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 86 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 87 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 88 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 91 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | if (err >= -1000) |
| 94 | return err; |
| 95 | switch (err) { |
| 96 | case -NFS4ERR_RESOURCE: |
| 97 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 98 | case -NFS4ERR_WRONGSEC: |
| 99 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 100 | case -NFS4ERR_BADOWNER: |
| 101 | case -NFS4ERR_BADNAME: |
| 102 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 103 | case -NFS4ERR_SHARE_DENIED: |
| 104 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 105 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 106 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 107 | case -NFS4ERR_ACCESS: |
| 108 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 111 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 114 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * This is our standard bitmap for GETATTR requests. |
| 119 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 120 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | FATTR4_WORD0_TYPE |
| 122 | | FATTR4_WORD0_CHANGE |
| 123 | | FATTR4_WORD0_SIZE |
| 124 | | FATTR4_WORD0_FSID |
| 125 | | FATTR4_WORD0_FILEID, |
| 126 | FATTR4_WORD1_MODE |
| 127 | | FATTR4_WORD1_NUMLINKS |
| 128 | | FATTR4_WORD1_OWNER |
| 129 | | FATTR4_WORD1_OWNER_GROUP |
| 130 | | FATTR4_WORD1_RAWDEV |
| 131 | | FATTR4_WORD1_SPACE_USED |
| 132 | | FATTR4_WORD1_TIME_ACCESS |
| 133 | | FATTR4_WORD1_TIME_METADATA |
| 134 | | FATTR4_WORD1_TIME_MODIFY |
| 135 | }; |
| 136 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 137 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 138 | FATTR4_WORD0_TYPE |
| 139 | | FATTR4_WORD0_CHANGE |
| 140 | | FATTR4_WORD0_SIZE |
| 141 | | FATTR4_WORD0_FSID |
| 142 | | FATTR4_WORD0_FILEID, |
| 143 | FATTR4_WORD1_MODE |
| 144 | | FATTR4_WORD1_NUMLINKS |
| 145 | | FATTR4_WORD1_OWNER |
| 146 | | FATTR4_WORD1_OWNER_GROUP |
| 147 | | FATTR4_WORD1_RAWDEV |
| 148 | | FATTR4_WORD1_SPACE_USED |
| 149 | | FATTR4_WORD1_TIME_ACCESS |
| 150 | | FATTR4_WORD1_TIME_METADATA |
| 151 | | FATTR4_WORD1_TIME_MODIFY, |
| 152 | FATTR4_WORD2_MDSTHRESHOLD |
| 153 | }; |
| 154 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 155 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 156 | FATTR4_WORD0_TYPE |
| 157 | | FATTR4_WORD0_CHANGE |
| 158 | | FATTR4_WORD0_FILEID, |
| 159 | }; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | const u32 nfs4_statfs_bitmap[2] = { |
| 162 | FATTR4_WORD0_FILES_AVAIL |
| 163 | | FATTR4_WORD0_FILES_FREE |
| 164 | | FATTR4_WORD0_FILES_TOTAL, |
| 165 | FATTR4_WORD1_SPACE_AVAIL |
| 166 | | FATTR4_WORD1_SPACE_FREE |
| 167 | | FATTR4_WORD1_SPACE_TOTAL |
| 168 | }; |
| 169 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 170 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | FATTR4_WORD0_MAXLINK |
| 172 | | FATTR4_WORD0_MAXNAME, |
| 173 | 0 |
| 174 | }; |
| 175 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 176 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | | FATTR4_WORD0_MAXREAD |
| 178 | | FATTR4_WORD0_MAXWRITE |
| 179 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 180 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 181 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 182 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 185 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID |
| 191 | | FATTR4_WORD0_FS_LOCATIONS, |
| 192 | FATTR4_WORD1_MODE |
| 193 | | FATTR4_WORD1_NUMLINKS |
| 194 | | FATTR4_WORD1_OWNER |
| 195 | | FATTR4_WORD1_OWNER_GROUP |
| 196 | | FATTR4_WORD1_RAWDEV |
| 197 | | FATTR4_WORD1_SPACE_USED |
| 198 | | FATTR4_WORD1_TIME_ACCESS |
| 199 | | FATTR4_WORD1_TIME_METADATA |
| 200 | | FATTR4_WORD1_TIME_MODIFY |
| 201 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 202 | }; |
| 203 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 204 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | struct nfs4_readdir_arg *readdir) |
| 206 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 207 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 210 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | readdir->cookie = 0; |
| 216 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 217 | if (cookie == 2) |
| 218 | return; |
| 219 | |
| 220 | /* |
| 221 | * NFSv4 servers do not return entries for '.' and '..' |
| 222 | * Therefore, we fake these entries here. We let '.' |
| 223 | * have cookie 0 and '..' have cookie 1. Note that |
| 224 | * when talking to the server, we always send cookie 0 |
| 225 | * instead of 1 or 2. |
| 226 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 227 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | if (cookie == 0) { |
| 230 | *p++ = xdr_one; /* next */ |
| 231 | *p++ = xdr_zero; /* cookie, first word */ |
| 232 | *p++ = xdr_one; /* cookie, second word */ |
| 233 | *p++ = xdr_one; /* entry len */ |
| 234 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 235 | p++; |
| 236 | *p++ = xdr_one; /* bitmap length */ |
| 237 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 238 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 239 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | *p++ = xdr_one; /* next */ |
| 243 | *p++ = xdr_zero; /* cookie, first word */ |
| 244 | *p++ = xdr_two; /* cookie, second word */ |
| 245 | *p++ = xdr_two; /* entry len */ |
| 246 | memcpy(p, "..\0\0", 4); /* entry */ |
| 247 | p++; |
| 248 | *p++ = xdr_one; /* bitmap length */ |
| 249 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 250 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 251 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | readdir->pgbase = (char *)p - (char *)start; |
| 254 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 255 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 258 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 259 | { |
| 260 | int res; |
| 261 | |
| 262 | might_sleep(); |
| 263 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 264 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 265 | nfs_wait_bit_killable, TASK_KILLABLE); |
Chuck Lever | 46a87b8 | 2012-07-11 16:30:41 -0400 | [diff] [blame] | 266 | if (res) |
| 267 | return res; |
| 268 | |
| 269 | if (clp->cl_cons_state < 0) |
| 270 | return clp->cl_cons_state; |
| 271 | return 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 275 | { |
| 276 | int res = 0; |
| 277 | |
| 278 | might_sleep(); |
| 279 | |
| 280 | if (*timeout <= 0) |
| 281 | *timeout = NFS4_POLL_RETRY_MIN; |
| 282 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 283 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 284 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 285 | if (fatal_signal_pending(current)) |
| 286 | res = -ERESTARTSYS; |
| 287 | *timeout <<= 1; |
| 288 | return res; |
| 289 | } |
| 290 | |
| 291 | /* This is the error handling routine for processes that are allowed |
| 292 | * to sleep. |
| 293 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 294 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 295 | { |
| 296 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 297 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 298 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 299 | int ret = errorcode; |
| 300 | |
| 301 | exception->retry = 0; |
| 302 | switch(errorcode) { |
| 303 | case 0: |
| 304 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 305 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 306 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 307 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 308 | exception->retry = 1; |
| 309 | return 0; |
| 310 | } |
| 311 | if (state == NULL) |
| 312 | break; |
| 313 | nfs4_schedule_stateid_recovery(server, state); |
| 314 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 315 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 316 | case -NFS4ERR_ADMIN_REVOKED: |
| 317 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 318 | if (state == NULL) |
| 319 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 320 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 321 | nfs4_schedule_stateid_recovery(server, state); |
| 322 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 323 | case -NFS4ERR_EXPIRED: |
| 324 | if (state != NULL) |
| 325 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 327 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 328 | nfs4_schedule_lease_recovery(clp); |
| 329 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 330 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 331 | case -NFS4ERR_BADSESSION: |
| 332 | case -NFS4ERR_BADSLOT: |
| 333 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 334 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 335 | case -NFS4ERR_DEADSESSION: |
| 336 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 337 | case -NFS4ERR_SEQ_MISORDERED: |
| 338 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 339 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 340 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 341 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 342 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 343 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 344 | if (exception->timeout > HZ) { |
| 345 | /* We have retried a decent amount, time to |
| 346 | * fail |
| 347 | */ |
| 348 | ret = -EBUSY; |
| 349 | break; |
| 350 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 351 | case -NFS4ERR_GRACE: |
| 352 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 353 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 354 | ret = nfs4_delay(server->client, &exception->timeout); |
| 355 | if (ret != 0) |
| 356 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 357 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 358 | case -NFS4ERR_OLD_STATEID: |
| 359 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 360 | break; |
| 361 | case -NFS4ERR_BADOWNER: |
| 362 | /* The following works around a Linux server bug! */ |
| 363 | case -NFS4ERR_BADNAME: |
| 364 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 365 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 366 | exception->retry = 1; |
| 367 | printk(KERN_WARNING "NFS: v4 server %s " |
| 368 | "does not accept raw " |
| 369 | "uid/gids. " |
| 370 | "Reenabling the idmapper.\n", |
| 371 | server->nfs_client->cl_hostname); |
| 372 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 373 | } |
| 374 | /* We failed to handle the error */ |
| 375 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 376 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 377 | ret = nfs4_wait_clnt_recover(clp); |
| 378 | if (ret == 0) |
| 379 | exception->retry = 1; |
| 380 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 384 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | spin_lock(&clp->cl_lock); |
| 387 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 388 | clp->cl_last_renewal = timestamp; |
| 389 | spin_unlock(&clp->cl_lock); |
| 390 | } |
| 391 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 392 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 393 | { |
| 394 | do_renew_lease(server->nfs_client, timestamp); |
| 395 | } |
| 396 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 397 | #if defined(CONFIG_NFS_V4_1) |
| 398 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 399 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 400 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 401 | * |
| 402 | * freeing a slot is trivially done by clearing its respective bit |
| 403 | * in the bitmap. |
| 404 | * If the freed slotid equals highest_used_slotid we want to update it |
| 405 | * so that the server would be able to size down the slot table if needed, |
| 406 | * otherwise we know that the highest_used_slotid is still in use. |
| 407 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 408 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 409 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 410 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 411 | * |
| 412 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 413 | */ |
| 414 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 415 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 416 | { |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 417 | /* clear used bit in bitmap */ |
| 418 | __clear_bit(slotid, tbl->used_slots); |
| 419 | |
| 420 | /* update highest_used_slotid when it is freed */ |
| 421 | if (slotid == tbl->highest_used_slotid) { |
| 422 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 423 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 424 | tbl->highest_used_slotid = slotid; |
| 425 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 426 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 427 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 428 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 429 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 430 | } |
| 431 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 432 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 433 | { |
| 434 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 435 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 438 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 439 | * Signal state manager thread if session fore channel is drained |
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 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 442 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 443 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 444 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 445 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 446 | return; |
| 447 | } |
| 448 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 449 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 450 | return; |
| 451 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 452 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 453 | complete(&ses->fc_slot_table.complete); |
| 454 | } |
| 455 | |
| 456 | /* |
| 457 | * Signal state manager thread if session back channel is drained |
| 458 | */ |
| 459 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 460 | { |
| 461 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 462 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 463 | return; |
| 464 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 465 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 466 | } |
| 467 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 468 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 469 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 470 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 471 | struct nfs4_slot_table *tbl; |
| 472 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 473 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 474 | /* just wake up the next guy waiting since |
| 475 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 476 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 477 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 478 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 479 | tbl = res->sr_slot->table; |
| 480 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 481 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 482 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 483 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 484 | nfs4_check_drain_fc_complete(session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 485 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 486 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 487 | } |
| 488 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 489 | 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] | 490 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 491 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 492 | struct nfs4_slot *slot; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 493 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 494 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * sr_status remains 1 if an RPC level error occurred. The server |
| 498 | * may or may not have processed the sequence operation.. |
| 499 | * Proceed as if the server received and processed the sequence |
| 500 | * operation. |
| 501 | */ |
| 502 | if (res->sr_status == 1) |
| 503 | res->sr_status = NFS_OK; |
| 504 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 505 | /* don't increment the sequence number if the task wasn't sent */ |
| 506 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 507 | goto out; |
| 508 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 509 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 510 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 511 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 512 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | switch (res->sr_status) { |
| 514 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 515 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 516 | ++slot->seq_nr; |
| 517 | timestamp = slot->renewal_time; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 518 | clp = session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 519 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 520 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 521 | if (res->sr_status_flags != 0) |
| 522 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 523 | break; |
| 524 | case -NFS4ERR_DELAY: |
| 525 | /* The server detected a resend of the RPC call and |
| 526 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 527 | * of RFC5661. |
| 528 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 529 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 530 | __func__, |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 531 | slot - session->fc_slot_table.slots, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 532 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 533 | goto out_retry; |
| 534 | default: |
| 535 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 536 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 537 | } |
| 538 | out: |
| 539 | /* The session may be reset by one of the error handlers. */ |
| 540 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 541 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 542 | return 1; |
| 543 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 544 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 545 | goto out; |
| 546 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 547 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 550 | static int nfs4_sequence_done(struct rpc_task *task, |
| 551 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 552 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 553 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 554 | return 1; |
| 555 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 556 | } |
| 557 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 558 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 559 | * nfs4_find_slot - efficiently look for a free slot |
| 560 | * |
| 561 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 562 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 563 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 564 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 565 | * |
| 566 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 567 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 568 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 569 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 570 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 571 | u32 slotid; |
| 572 | u32 ret_id = NFS4_NO_SLOT; |
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; |
| 584 | ret_id = slotid; |
| 585 | out: |
| 586 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 587 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 588 | return ret_id; |
| 589 | } |
| 590 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 591 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 592 | struct nfs4_sequence_res *res, int cache_reply) |
| 593 | { |
| 594 | args->sa_session = NULL; |
| 595 | args->sa_cache_this = 0; |
| 596 | if (cache_reply) |
| 597 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 598 | res->sr_slot = NULL; |
| 599 | } |
| 600 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 601 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 602 | struct nfs4_sequence_args *args, |
| 603 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | struct rpc_task *task) |
| 605 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 606 | struct nfs4_slot *slot; |
| 607 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 608 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 609 | |
| 610 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 611 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 612 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | return 0; |
| 614 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 615 | tbl = &session->fc_slot_table; |
| 616 | |
| 617 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 618 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 619 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 620 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 621 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 622 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 623 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 624 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 625 | } |
| 626 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 627 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 628 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 629 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 630 | spin_unlock(&tbl->slot_tbl_lock); |
| 631 | dprintk("%s enforce FIFO order\n", __func__); |
| 632 | return -EAGAIN; |
| 633 | } |
| 634 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 635 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 636 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 637 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 638 | spin_unlock(&tbl->slot_tbl_lock); |
| 639 | dprintk("<-- %s: no free slots\n", __func__); |
| 640 | return -EAGAIN; |
| 641 | } |
| 642 | spin_unlock(&tbl->slot_tbl_lock); |
| 643 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 644 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 645 | slot = tbl->slots + slotid; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 646 | slot->renewal_time = jiffies; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 647 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 648 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 649 | |
| 650 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 651 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 652 | res->sr_slot = slot; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 653 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 654 | /* |
| 655 | * sr_status is only set in decode_sequence, and so will remain |
| 656 | * set to 1 if an rpc level failure occurs. |
| 657 | */ |
| 658 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 659 | return 0; |
| 660 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 661 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 662 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 663 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 664 | struct nfs4_sequence_args *args, |
| 665 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 666 | struct rpc_task *task) |
| 667 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 668 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | int ret = 0; |
| 670 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 671 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 672 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 673 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 674 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 675 | __func__, session->clp, session, res->sr_slot ? |
| 676 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 677 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 678 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 679 | out: |
| 680 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 685 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | struct nfs4_sequence_args *seq_args; |
| 687 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 688 | }; |
| 689 | |
| 690 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 691 | { |
| 692 | struct nfs41_call_sync_data *data = calldata; |
| 693 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 694 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 695 | |
| 696 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 697 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 698 | return; |
| 699 | rpc_call_start(task); |
| 700 | } |
| 701 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 702 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 703 | { |
| 704 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 705 | nfs41_call_sync_prepare(task, calldata); |
| 706 | } |
| 707 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 708 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 709 | { |
| 710 | struct nfs41_call_sync_data *data = calldata; |
| 711 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 712 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 715 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 716 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 717 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 718 | }; |
| 719 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 720 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 721 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 722 | .rpc_call_done = nfs41_call_sync_done, |
| 723 | }; |
| 724 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 725 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 726 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 727 | struct rpc_message *msg, |
| 728 | struct nfs4_sequence_args *args, |
| 729 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 730 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 731 | { |
| 732 | int ret; |
| 733 | struct rpc_task *task; |
| 734 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 735 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 736 | .seq_args = args, |
| 737 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 738 | }; |
| 739 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 740 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 741 | .rpc_message = msg, |
| 742 | .callback_ops = &nfs41_call_sync_ops, |
| 743 | .callback_data = &data |
| 744 | }; |
| 745 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 746 | if (privileged) |
| 747 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 748 | task = rpc_run_task(&task_setup); |
| 749 | if (IS_ERR(task)) |
| 750 | ret = PTR_ERR(task); |
| 751 | else { |
| 752 | ret = task->tk_status; |
| 753 | rpc_put_task(task); |
| 754 | } |
| 755 | return ret; |
| 756 | } |
| 757 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 758 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 759 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 760 | struct rpc_message *msg, |
| 761 | struct nfs4_sequence_args *args, |
| 762 | struct nfs4_sequence_res *res, |
| 763 | int cache_reply) |
| 764 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 765 | nfs41_init_sequence(args, res, cache_reply); |
| 766 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 769 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 770 | static inline |
| 771 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 772 | struct nfs4_sequence_res *res, int cache_reply) |
| 773 | { |
| 774 | } |
| 775 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 776 | static int nfs4_sequence_done(struct rpc_task *task, |
| 777 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 778 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 779 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 780 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 781 | #endif /* CONFIG_NFS_V4_1 */ |
| 782 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 783 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 784 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 785 | struct rpc_message *msg, |
| 786 | struct nfs4_sequence_args *args, |
| 787 | struct nfs4_sequence_res *res, |
| 788 | int cache_reply) |
| 789 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 790 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 791 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 792 | } |
| 793 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 794 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 795 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 796 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 797 | struct rpc_message *msg, |
| 798 | struct nfs4_sequence_args *args, |
| 799 | struct nfs4_sequence_res *res, |
| 800 | int cache_reply) |
| 801 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 802 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 803 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 804 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 805 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 806 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 808 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 810 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 811 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 812 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 813 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 814 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 815 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 819 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | struct nfs_openargs o_arg; |
| 821 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 822 | struct nfs_open_confirmargs c_arg; |
| 823 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 824 | struct nfs4_string owner_name; |
| 825 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 828 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 830 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 831 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 832 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 833 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 834 | int rpc_status; |
| 835 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 836 | }; |
| 837 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 838 | |
| 839 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 840 | { |
| 841 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 842 | p->o_res.seqid = p->o_arg.seqid; |
| 843 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 844 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 845 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 846 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 847 | 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] | 848 | } |
| 849 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 850 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 851 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 852 | const struct iattr *attrs, |
| 853 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 854 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 855 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 856 | struct inode *dir = parent->d_inode; |
| 857 | struct nfs_server *server = NFS_SERVER(dir); |
| 858 | struct nfs4_opendata *p; |
| 859 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 860 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 861 | if (p == NULL) |
| 862 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 863 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 864 | if (p->o_arg.seqid == NULL) |
| 865 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 866 | nfs_sb_active(dentry->d_sb); |
| 867 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 868 | p->dir = parent; |
| 869 | p->owner = sp; |
| 870 | atomic_inc(&sp->so_count); |
| 871 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 872 | p->o_arg.open_flags = flags; |
| 873 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 874 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 875 | * will return permission denied for all bits until close */ |
| 876 | if (!(flags & O_EXCL)) { |
| 877 | /* ask server to check for all possible rights as results |
| 878 | * are cached */ |
| 879 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 880 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 881 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 882 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 883 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 884 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 885 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 886 | p->o_arg.server = server; |
| 887 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 888 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 889 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 890 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 891 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 892 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 893 | p->o_arg.u.attrs = &p->attrs; |
| 894 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 895 | |
| 896 | verf[0] = jiffies; |
| 897 | verf[1] = current->pid; |
| 898 | memcpy(p->o_arg.u.verifier.data, verf, |
| 899 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 900 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 901 | p->c_arg.fh = &p->o_res.fh; |
| 902 | p->c_arg.stateid = &p->o_res.stateid; |
| 903 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 904 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 905 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 906 | return p; |
| 907 | err_free: |
| 908 | kfree(p); |
| 909 | err: |
| 910 | dput(parent); |
| 911 | return NULL; |
| 912 | } |
| 913 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 914 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 915 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 916 | struct nfs4_opendata *p = container_of(kref, |
| 917 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 918 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 919 | |
| 920 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 921 | if (p->state != NULL) |
| 922 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 923 | nfs4_put_state_owner(p->owner); |
| 924 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 925 | dput(p->dentry); |
| 926 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 927 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 928 | kfree(p); |
| 929 | } |
| 930 | |
| 931 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 932 | { |
| 933 | if (p != NULL) |
| 934 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 935 | } |
| 936 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 937 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 938 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 939 | int ret; |
| 940 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 941 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 942 | return ret; |
| 943 | } |
| 944 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 945 | 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] | 946 | { |
| 947 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 948 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 949 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 950 | goto out; |
| 951 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 952 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 953 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 954 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 955 | break; |
| 956 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 957 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 958 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 959 | break; |
| 960 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 961 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 962 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 963 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 964 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 965 | return ret; |
| 966 | } |
| 967 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 968 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 969 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 970 | if (delegation == NULL) |
| 971 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 972 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 973 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 974 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 975 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 976 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 977 | return 1; |
| 978 | } |
| 979 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 980 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 981 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 982 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 983 | case FMODE_WRITE: |
| 984 | state->n_wronly++; |
| 985 | break; |
| 986 | case FMODE_READ: |
| 987 | state->n_rdonly++; |
| 988 | break; |
| 989 | case FMODE_READ|FMODE_WRITE: |
| 990 | state->n_rdwr++; |
| 991 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 992 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 993 | } |
| 994 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 995 | 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] | 996 | { |
| 997 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 998 | nfs4_stateid_copy(&state->stateid, stateid); |
| 999 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1001 | case FMODE_READ: |
| 1002 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1003 | break; |
| 1004 | case FMODE_WRITE: |
| 1005 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1006 | break; |
| 1007 | case FMODE_READ|FMODE_WRITE: |
| 1008 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1009 | } |
| 1010 | } |
| 1011 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1012 | 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] | 1013 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1014 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1015 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1016 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1019 | 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] | 1020 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1021 | /* |
| 1022 | * Protect the call to nfs4_state_set_mode_locked and |
| 1023 | * serialise the stateid update |
| 1024 | */ |
| 1025 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1026 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1027 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1028 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1029 | } |
| 1030 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1032 | write_sequnlock(&state->seqlock); |
| 1033 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1034 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1035 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1038 | 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] | 1039 | { |
| 1040 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1041 | struct nfs_delegation *deleg_cur; |
| 1042 | int ret = 0; |
| 1043 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1044 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1045 | |
| 1046 | rcu_read_lock(); |
| 1047 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1048 | if (deleg_cur == NULL) |
| 1049 | goto no_delegation; |
| 1050 | |
| 1051 | spin_lock(&deleg_cur->lock); |
| 1052 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | goto no_delegation_unlock; |
| 1055 | |
| 1056 | if (delegation == NULL) |
| 1057 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1058 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1059 | goto no_delegation_unlock; |
| 1060 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1061 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1062 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1063 | ret = 1; |
| 1064 | no_delegation_unlock: |
| 1065 | spin_unlock(&deleg_cur->lock); |
| 1066 | no_delegation: |
| 1067 | rcu_read_unlock(); |
| 1068 | |
| 1069 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1070 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1071 | ret = 1; |
| 1072 | } |
| 1073 | |
| 1074 | return ret; |
| 1075 | } |
| 1076 | |
| 1077 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1078 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1079 | { |
| 1080 | struct nfs_delegation *delegation; |
| 1081 | |
| 1082 | rcu_read_lock(); |
| 1083 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1084 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1085 | rcu_read_unlock(); |
| 1086 | return; |
| 1087 | } |
| 1088 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1089 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1092 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1093 | { |
| 1094 | struct nfs4_state *state = opendata->state; |
| 1095 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1096 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1097 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1098 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1099 | nfs4_stateid stateid; |
| 1100 | int ret = -EAGAIN; |
| 1101 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1102 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1103 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1104 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1105 | if (can_open_cached(state, fmode, open_mode)) { |
| 1106 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1107 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1108 | goto out_return_state; |
| 1109 | } |
| 1110 | spin_unlock(&state->owner->so_lock); |
| 1111 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1112 | rcu_read_lock(); |
| 1113 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1114 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1115 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1116 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1117 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1118 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1119 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1120 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1121 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1122 | if (ret != 0) |
| 1123 | goto out; |
| 1124 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1125 | |
| 1126 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1127 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1128 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1129 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1130 | out: |
| 1131 | return ERR_PTR(ret); |
| 1132 | out_return_state: |
| 1133 | atomic_inc(&state->count); |
| 1134 | return state; |
| 1135 | } |
| 1136 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1137 | static void |
| 1138 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1139 | { |
| 1140 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1141 | struct nfs_delegation *delegation; |
| 1142 | int delegation_flags = 0; |
| 1143 | |
| 1144 | rcu_read_lock(); |
| 1145 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1146 | if (delegation) |
| 1147 | delegation_flags = delegation->flags; |
| 1148 | rcu_read_unlock(); |
| 1149 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1150 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1151 | "returning a delegation for " |
| 1152 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1153 | clp->cl_hostname); |
| 1154 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1155 | nfs_inode_set_delegation(state->inode, |
| 1156 | data->owner->so_cred, |
| 1157 | &data->o_res); |
| 1158 | else |
| 1159 | nfs_inode_reclaim_delegation(state->inode, |
| 1160 | data->owner->so_cred, |
| 1161 | &data->o_res); |
| 1162 | } |
| 1163 | |
| 1164 | /* |
| 1165 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1166 | * and update the nfs4_state. |
| 1167 | */ |
| 1168 | static struct nfs4_state * |
| 1169 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1170 | { |
| 1171 | struct inode *inode = data->state->inode; |
| 1172 | struct nfs4_state *state = data->state; |
| 1173 | int ret; |
| 1174 | |
| 1175 | if (!data->rpc_done) { |
| 1176 | ret = data->rpc_status; |
| 1177 | goto err; |
| 1178 | } |
| 1179 | |
| 1180 | ret = -ESTALE; |
| 1181 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1182 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1183 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1184 | goto err; |
| 1185 | |
| 1186 | ret = -ENOMEM; |
| 1187 | state = nfs4_get_open_state(inode, data->owner); |
| 1188 | if (state == NULL) |
| 1189 | goto err; |
| 1190 | |
| 1191 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1192 | if (ret) |
| 1193 | goto err; |
| 1194 | |
| 1195 | if (data->o_res.delegation_type != 0) |
| 1196 | nfs4_opendata_check_deleg(data, state); |
| 1197 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1198 | data->o_arg.fmode); |
| 1199 | |
| 1200 | return state; |
| 1201 | err: |
| 1202 | return ERR_PTR(ret); |
| 1203 | |
| 1204 | } |
| 1205 | |
| 1206 | static struct nfs4_state * |
| 1207 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1208 | { |
| 1209 | struct inode *inode; |
| 1210 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1211 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1212 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1213 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1214 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1215 | goto out; |
| 1216 | } |
| 1217 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1218 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1219 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1220 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1221 | 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] | 1222 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1223 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1224 | goto err; |
| 1225 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1226 | state = nfs4_get_open_state(inode, data->owner); |
| 1227 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1228 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1229 | if (data->o_res.delegation_type != 0) |
| 1230 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1231 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1232 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1233 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1234 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1235 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1236 | err_put_inode: |
| 1237 | iput(inode); |
| 1238 | err: |
| 1239 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1240 | } |
| 1241 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1242 | static struct nfs4_state * |
| 1243 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1244 | { |
| 1245 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1246 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1247 | return _nfs4_opendata_to_nfs4_state(data); |
| 1248 | } |
| 1249 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1250 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1251 | { |
| 1252 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1253 | struct nfs_open_context *ctx; |
| 1254 | |
| 1255 | spin_lock(&state->inode->i_lock); |
| 1256 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1257 | if (ctx->state != state) |
| 1258 | continue; |
| 1259 | get_nfs_open_context(ctx); |
| 1260 | spin_unlock(&state->inode->i_lock); |
| 1261 | return ctx; |
| 1262 | } |
| 1263 | spin_unlock(&state->inode->i_lock); |
| 1264 | return ERR_PTR(-ENOENT); |
| 1265 | } |
| 1266 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1267 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1268 | { |
| 1269 | struct nfs4_opendata *opendata; |
| 1270 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1271 | 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] | 1272 | if (opendata == NULL) |
| 1273 | return ERR_PTR(-ENOMEM); |
| 1274 | opendata->state = state; |
| 1275 | atomic_inc(&state->count); |
| 1276 | return opendata; |
| 1277 | } |
| 1278 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1279 | 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] | 1280 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1281 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1282 | int ret; |
| 1283 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1284 | opendata->o_arg.open_flags = 0; |
| 1285 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1286 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1287 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1288 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1289 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1290 | if (ret != 0) |
| 1291 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1292 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1293 | if (IS_ERR(newstate)) |
| 1294 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1295 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1296 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1301 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1302 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1303 | int ret; |
| 1304 | |
| 1305 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1306 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1307 | smp_rmb(); |
| 1308 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1309 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1310 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1311 | if (ret != 0) |
| 1312 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1313 | if (newstate != state) |
| 1314 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1315 | } |
| 1316 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1317 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1318 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1319 | if (ret != 0) |
| 1320 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1321 | if (newstate != state) |
| 1322 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1323 | } |
| 1324 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1325 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1326 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1327 | if (ret != 0) |
| 1328 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1329 | if (newstate != state) |
| 1330 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1331 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1332 | /* |
| 1333 | * We may have performed cached opens for all three recoveries. |
| 1334 | * Check if we need to update the current stateid. |
| 1335 | */ |
| 1336 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1337 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1338 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1339 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1340 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1341 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1342 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1343 | return 0; |
| 1344 | } |
| 1345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | /* |
| 1347 | * OPEN_RECLAIM: |
| 1348 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1350 | 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] | 1351 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1352 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1353 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1354 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | int status; |
| 1356 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1357 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1358 | if (IS_ERR(opendata)) |
| 1359 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1360 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1361 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1362 | rcu_read_lock(); |
| 1363 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1364 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1365 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1366 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1367 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1368 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1369 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | return status; |
| 1371 | } |
| 1372 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1373 | 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] | 1374 | { |
| 1375 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1376 | struct nfs4_exception exception = { }; |
| 1377 | int err; |
| 1378 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1379 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1380 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1381 | break; |
| 1382 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | } while (exception.retry); |
| 1384 | return err; |
| 1385 | } |
| 1386 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1387 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1388 | { |
| 1389 | struct nfs_open_context *ctx; |
| 1390 | int ret; |
| 1391 | |
| 1392 | ctx = nfs4_state_find_open_context(state); |
| 1393 | if (IS_ERR(ctx)) |
| 1394 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1395 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1396 | put_nfs_open_context(ctx); |
| 1397 | return ret; |
| 1398 | } |
| 1399 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1400 | 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] | 1401 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1402 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1403 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1405 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1406 | if (IS_ERR(opendata)) |
| 1407 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1408 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1409 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1410 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1411 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1412 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1415 | 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] | 1416 | { |
| 1417 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1418 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | int err; |
| 1420 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1421 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | switch (err) { |
| 1423 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1424 | case -ENOENT: |
| 1425 | case -ESTALE: |
| 1426 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1427 | case -NFS4ERR_BADSESSION: |
| 1428 | case -NFS4ERR_BADSLOT: |
| 1429 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1430 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1431 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1432 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1433 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | case -NFS4ERR_STALE_CLIENTID: |
| 1435 | case -NFS4ERR_STALE_STATEID: |
| 1436 | case -NFS4ERR_EXPIRED: |
| 1437 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1438 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1439 | goto out; |
| 1440 | case -ERESTARTSYS: |
| 1441 | /* |
| 1442 | * The show must go on: exit, but mark the |
| 1443 | * stateid as needing recovery. |
| 1444 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1445 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1446 | case -NFS4ERR_ADMIN_REVOKED: |
| 1447 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1448 | nfs_inode_find_state_and_recover(state->inode, |
| 1449 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1450 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1451 | case -EKEYEXPIRED: |
| 1452 | /* |
| 1453 | * User RPCSEC_GSS context has expired. |
| 1454 | * We cannot recover this stateid now, so |
| 1455 | * skip it and allow recovery thread to |
| 1456 | * proceed. |
| 1457 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1458 | case -ENOMEM: |
| 1459 | err = 0; |
| 1460 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | } |
| 1462 | err = nfs4_handle_exception(server, err, &exception); |
| 1463 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1464 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | return err; |
| 1466 | } |
| 1467 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1468 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1469 | { |
| 1470 | struct nfs4_opendata *data = calldata; |
| 1471 | |
| 1472 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1473 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1474 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1475 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1476 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1477 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1478 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | static void nfs4_open_confirm_release(void *calldata) |
| 1482 | { |
| 1483 | struct nfs4_opendata *data = calldata; |
| 1484 | struct nfs4_state *state = NULL; |
| 1485 | |
| 1486 | /* If this request hasn't been cancelled, do nothing */ |
| 1487 | if (data->cancelled == 0) |
| 1488 | goto out_free; |
| 1489 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1490 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1491 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1492 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1493 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1494 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1495 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1496 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1500 | .rpc_call_done = nfs4_open_confirm_done, |
| 1501 | .rpc_release = nfs4_open_confirm_release, |
| 1502 | }; |
| 1503 | |
| 1504 | /* |
| 1505 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1506 | */ |
| 1507 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1508 | { |
| 1509 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1510 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1511 | struct rpc_message msg = { |
| 1512 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1513 | .rpc_argp = &data->c_arg, |
| 1514 | .rpc_resp = &data->c_res, |
| 1515 | .rpc_cred = data->owner->so_cred, |
| 1516 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1517 | struct rpc_task_setup task_setup_data = { |
| 1518 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1519 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1520 | .callback_ops = &nfs4_open_confirm_ops, |
| 1521 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1522 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1523 | .flags = RPC_TASK_ASYNC, |
| 1524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | int status; |
| 1526 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1527 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1528 | data->rpc_done = 0; |
| 1529 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1530 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1531 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1532 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1533 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1534 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1535 | if (status != 0) { |
| 1536 | data->cancelled = 1; |
| 1537 | smp_wmb(); |
| 1538 | } else |
| 1539 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1540 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | return status; |
| 1542 | } |
| 1543 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1546 | struct nfs4_opendata *data = calldata; |
| 1547 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1548 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1549 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1550 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1551 | /* |
| 1552 | * Check if we still need to send an OPEN call, or if we can use |
| 1553 | * a delegation instead. |
| 1554 | */ |
| 1555 | if (data->state != NULL) { |
| 1556 | struct nfs_delegation *delegation; |
| 1557 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1558 | 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] | 1559 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1560 | rcu_read_lock(); |
| 1561 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1562 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1563 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1564 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1565 | rcu_read_unlock(); |
| 1566 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1567 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1568 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1569 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1570 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1571 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1572 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1573 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1574 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1575 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1576 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1577 | &data->o_res.seq_res, |
| 1578 | task) != 0) |
| 1579 | nfs_release_seqid(data->o_arg.seqid); |
| 1580 | else |
| 1581 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1582 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1583 | unlock_no_action: |
| 1584 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1585 | out_no_action: |
| 1586 | task->tk_action = NULL; |
| 1587 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1588 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1590 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1591 | { |
| 1592 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1593 | nfs4_open_prepare(task, calldata); |
| 1594 | } |
| 1595 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1596 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1597 | { |
| 1598 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1600 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1601 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1602 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1603 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1604 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1605 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1606 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1607 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1608 | case S_IFREG: |
| 1609 | break; |
| 1610 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1611 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1612 | break; |
| 1613 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1614 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1615 | break; |
| 1616 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1617 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1618 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1619 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1620 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1621 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1622 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1623 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1624 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1625 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1626 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1627 | static void nfs4_open_release(void *calldata) |
| 1628 | { |
| 1629 | struct nfs4_opendata *data = calldata; |
| 1630 | struct nfs4_state *state = NULL; |
| 1631 | |
| 1632 | /* If this request hasn't been cancelled, do nothing */ |
| 1633 | if (data->cancelled == 0) |
| 1634 | goto out_free; |
| 1635 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1636 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1637 | goto out_free; |
| 1638 | /* In case we need an open_confirm, no cleanup! */ |
| 1639 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1640 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1641 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1642 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1643 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1644 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1645 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1649 | .rpc_call_prepare = nfs4_open_prepare, |
| 1650 | .rpc_call_done = nfs4_open_done, |
| 1651 | .rpc_release = nfs4_open_release, |
| 1652 | }; |
| 1653 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1654 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1655 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1656 | .rpc_call_done = nfs4_open_done, |
| 1657 | .rpc_release = nfs4_open_release, |
| 1658 | }; |
| 1659 | |
| 1660 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1661 | { |
| 1662 | struct inode *dir = data->dir->d_inode; |
| 1663 | struct nfs_server *server = NFS_SERVER(dir); |
| 1664 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1665 | struct nfs_openres *o_res = &data->o_res; |
| 1666 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1667 | struct rpc_message msg = { |
| 1668 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1669 | .rpc_argp = o_arg, |
| 1670 | .rpc_resp = o_res, |
| 1671 | .rpc_cred = data->owner->so_cred, |
| 1672 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1673 | struct rpc_task_setup task_setup_data = { |
| 1674 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1675 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1676 | .callback_ops = &nfs4_open_ops, |
| 1677 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1678 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1679 | .flags = RPC_TASK_ASYNC, |
| 1680 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1681 | int status; |
| 1682 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1683 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1684 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1685 | data->rpc_done = 0; |
| 1686 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1687 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1688 | if (isrecover) |
| 1689 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1690 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1691 | if (IS_ERR(task)) |
| 1692 | return PTR_ERR(task); |
| 1693 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1694 | if (status != 0) { |
| 1695 | data->cancelled = 1; |
| 1696 | smp_wmb(); |
| 1697 | } else |
| 1698 | status = data->rpc_status; |
| 1699 | rpc_put_task(task); |
| 1700 | |
| 1701 | return status; |
| 1702 | } |
| 1703 | |
| 1704 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1705 | { |
| 1706 | struct inode *dir = data->dir->d_inode; |
| 1707 | struct nfs_openres *o_res = &data->o_res; |
| 1708 | int status; |
| 1709 | |
| 1710 | status = nfs4_run_open_task(data, 1); |
| 1711 | if (status != 0 || !data->rpc_done) |
| 1712 | return status; |
| 1713 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1714 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1715 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1716 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1717 | status = _nfs4_proc_open_confirm(data); |
| 1718 | if (status != 0) |
| 1719 | return status; |
| 1720 | } |
| 1721 | |
| 1722 | return status; |
| 1723 | } |
| 1724 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1725 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1726 | struct nfs4_opendata *opendata, |
| 1727 | struct nfs4_state *state, fmode_t fmode) |
| 1728 | { |
| 1729 | struct nfs_access_entry cache; |
| 1730 | u32 mask; |
| 1731 | |
| 1732 | /* access call failed or for some reason the server doesn't |
| 1733 | * support any access modes -- defer access call until later */ |
| 1734 | if (opendata->o_res.access_supported == 0) |
| 1735 | return 0; |
| 1736 | |
| 1737 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1738 | /* don't check MAY_WRITE - a newly created file may not have |
| 1739 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1740 | if (fmode & FMODE_READ) |
| 1741 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1742 | if (fmode & FMODE_EXEC) |
| 1743 | mask |= MAY_EXEC; |
| 1744 | |
| 1745 | cache.cred = cred; |
| 1746 | cache.jiffies = jiffies; |
| 1747 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1748 | nfs_access_add_cache(state->inode, &cache); |
| 1749 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1750 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1751 | return 0; |
| 1752 | |
| 1753 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1754 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1755 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1756 | } |
| 1757 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1758 | /* |
| 1759 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1760 | */ |
| 1761 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1762 | { |
| 1763 | struct inode *dir = data->dir->d_inode; |
| 1764 | struct nfs_server *server = NFS_SERVER(dir); |
| 1765 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1766 | struct nfs_openres *o_res = &data->o_res; |
| 1767 | int status; |
| 1768 | |
| 1769 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1770 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1771 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1772 | if (status != 0) { |
| 1773 | if (status == -NFS4ERR_BADNAME && |
| 1774 | !(o_arg->open_flags & O_CREAT)) |
| 1775 | return -ENOENT; |
| 1776 | return status; |
| 1777 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1778 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1779 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1780 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1781 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1782 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1783 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1784 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1786 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1788 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | } |
| 1790 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1791 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1792 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1795 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1796 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1797 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1798 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1799 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1800 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1801 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1802 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1803 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1804 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1805 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1806 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1807 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1808 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1809 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1810 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1811 | } |
| 1812 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1813 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1814 | { |
| 1815 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1816 | } |
| 1817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | /* |
| 1819 | * OPEN_EXPIRED: |
| 1820 | * reclaim state on the server after a network partition. |
| 1821 | * Assumes caller holds the appropriate lock |
| 1822 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1823 | 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] | 1824 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1825 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1826 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1828 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1829 | if (IS_ERR(opendata)) |
| 1830 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1831 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1832 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1833 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1834 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1835 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1838 | 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] | 1839 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1840 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1841 | struct nfs4_exception exception = { }; |
| 1842 | int err; |
| 1843 | |
| 1844 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1845 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1846 | switch (err) { |
| 1847 | default: |
| 1848 | goto out; |
| 1849 | case -NFS4ERR_GRACE: |
| 1850 | case -NFS4ERR_DELAY: |
| 1851 | nfs4_handle_exception(server, err, &exception); |
| 1852 | err = 0; |
| 1853 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1854 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1855 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1856 | return err; |
| 1857 | } |
| 1858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1860 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1862 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1864 | ctx = nfs4_state_find_open_context(state); |
| 1865 | if (IS_ERR(ctx)) |
| 1866 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1867 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1868 | put_nfs_open_context(ctx); |
| 1869 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1872 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1873 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1874 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1875 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1876 | nfs4_stateid *stateid = &state->stateid; |
| 1877 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1878 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1879 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1880 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1881 | return; |
| 1882 | |
| 1883 | status = nfs41_test_stateid(server, stateid); |
| 1884 | if (status != NFS_OK) { |
| 1885 | /* Free the stateid unless the server explicitly |
| 1886 | * informs us the stateid is unrecognized. */ |
| 1887 | if (status != -NFS4ERR_BAD_STATEID) |
| 1888 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1889 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1890 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1891 | write_seqlock(&state->seqlock); |
| 1892 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1893 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1894 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | /** |
| 1899 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1900 | * |
| 1901 | * @state: NFSv4 state for an inode |
| 1902 | * |
| 1903 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1904 | * Otherwise a negative NFS4ERR value is returned. |
| 1905 | */ |
| 1906 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1907 | { |
| 1908 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1909 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1910 | int status; |
| 1911 | |
| 1912 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1913 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1914 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1915 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1916 | return -NFS4ERR_BAD_STATEID; |
| 1917 | |
| 1918 | status = nfs41_test_stateid(server, stateid); |
| 1919 | if (status != NFS_OK) { |
| 1920 | /* Free the stateid unless the server explicitly |
| 1921 | * informs us the stateid is unrecognized. */ |
| 1922 | if (status != -NFS4ERR_BAD_STATEID) |
| 1923 | nfs41_free_stateid(server, stateid); |
| 1924 | |
| 1925 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1926 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1927 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1928 | } |
| 1929 | return status; |
| 1930 | } |
| 1931 | |
| 1932 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1933 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1934 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1935 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1936 | nfs41_clear_delegation_stateid(state); |
| 1937 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1938 | if (status != NFS_OK) |
| 1939 | status = nfs4_open_expired(sp, state); |
| 1940 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1941 | } |
| 1942 | #endif |
| 1943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1945 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1946 | * fields corresponding to attributes that were used to store the verifier. |
| 1947 | * Make sure we clobber those fields in the later setattr call |
| 1948 | */ |
| 1949 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1950 | { |
| 1951 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1952 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1953 | sattr->ia_valid |= ATTR_ATIME; |
| 1954 | |
| 1955 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1956 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1957 | sattr->ia_valid |= ATTR_MTIME; |
| 1958 | } |
| 1959 | |
| 1960 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1961 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1963 | static int _nfs4_do_open(struct inode *dir, |
| 1964 | struct dentry *dentry, |
| 1965 | fmode_t fmode, |
| 1966 | int flags, |
| 1967 | struct iattr *sattr, |
| 1968 | struct rpc_cred *cred, |
| 1969 | struct nfs4_state **res, |
| 1970 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | { |
| 1972 | struct nfs4_state_owner *sp; |
| 1973 | struct nfs4_state *state = NULL; |
| 1974 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1975 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1976 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
| 1978 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1980 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1981 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1983 | goto out_err; |
| 1984 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1985 | status = nfs4_recover_expired_lease(server); |
| 1986 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1987 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1988 | if (dentry->d_inode != NULL) |
| 1989 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1990 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1991 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1992 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1993 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1995 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1996 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1997 | if (!opendata->f_attr.mdsthreshold) |
| 1998 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1999 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2000 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2001 | if (dentry->d_inode != NULL) |
| 2002 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2003 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2004 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2006 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2008 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2009 | status = PTR_ERR(state); |
| 2010 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2011 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2012 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 2013 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2014 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2015 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 2016 | if (status != 0) |
| 2017 | goto err_opendata_put; |
| 2018 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2019 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 2020 | nfs4_exclusive_attrset(opendata, sattr); |
| 2021 | |
| 2022 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2023 | status = nfs4_do_setattr(state->inode, cred, |
| 2024 | opendata->o_res.f_attr, sattr, |
| 2025 | state); |
| 2026 | if (status == 0) |
| 2027 | nfs_setattr_update_inode(state->inode, sattr); |
| 2028 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2029 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2030 | |
| 2031 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2032 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2033 | else |
| 2034 | kfree(opendata->f_attr.mdsthreshold); |
| 2035 | opendata->f_attr.mdsthreshold = NULL; |
| 2036 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2037 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | *res = state; |
| 2040 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2041 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2042 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2043 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2044 | err_put_state_owner: |
| 2045 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | *res = NULL; |
| 2048 | return status; |
| 2049 | } |
| 2050 | |
| 2051 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2052 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2053 | struct dentry *dentry, |
| 2054 | fmode_t fmode, |
| 2055 | int flags, |
| 2056 | struct iattr *sattr, |
| 2057 | struct rpc_cred *cred, |
| 2058 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | { |
| 2060 | struct nfs4_exception exception = { }; |
| 2061 | struct nfs4_state *res; |
| 2062 | int status; |
| 2063 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2064 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2066 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2067 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | if (status == 0) |
| 2069 | break; |
| 2070 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2071 | * book-keeping w.r.t. state-changing operations |
| 2072 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2073 | * It is actually a sign of a bug on the client or on the server. |
| 2074 | * |
| 2075 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2076 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | * have unhashed the old state_owner for us, and that we can |
| 2078 | * therefore safely retry using a new one. We should still warn |
| 2079 | * the user though... |
| 2080 | */ |
| 2081 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2082 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2083 | " returned a bad sequence-id error!\n", |
| 2084 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | exception.retry = 1; |
| 2086 | continue; |
| 2087 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2088 | /* |
| 2089 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2090 | * state before it received the OPEN_CONFIRM. |
| 2091 | * Recover by retrying the request as per the discussion |
| 2092 | * on Page 181 of RFC3530. |
| 2093 | */ |
| 2094 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2095 | exception.retry = 1; |
| 2096 | continue; |
| 2097 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2098 | if (status == -EAGAIN) { |
| 2099 | /* We must have found a delegation */ |
| 2100 | exception.retry = 1; |
| 2101 | continue; |
| 2102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2104 | status, &exception)); |
| 2105 | } while (exception.retry); |
| 2106 | return res; |
| 2107 | } |
| 2108 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2109 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2110 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2111 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2113 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2115 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | .iap = sattr, |
| 2117 | .server = server, |
| 2118 | .bitmask = server->attr_bitmask, |
| 2119 | }; |
| 2120 | struct nfs_setattrres res = { |
| 2121 | .fattr = fattr, |
| 2122 | .server = server, |
| 2123 | }; |
| 2124 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2125 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2126 | .rpc_argp = &arg, |
| 2127 | .rpc_resp = &res, |
| 2128 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2130 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2131 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2133 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2135 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2136 | struct nfs_lockowner lockowner = { |
| 2137 | .l_owner = current->files, |
| 2138 | .l_pid = current->tgid, |
| 2139 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2140 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2141 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2142 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2143 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2144 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2145 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2146 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2148 | 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] | 2149 | if (status == 0 && state != NULL) |
| 2150 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2151 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2154 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2155 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2156 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2158 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2159 | struct nfs4_exception exception = { |
| 2160 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2161 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2162 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | int err; |
| 2164 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2165 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2166 | switch (err) { |
| 2167 | case -NFS4ERR_OPENMODE: |
| 2168 | if (state && !(state->state & FMODE_WRITE)) { |
| 2169 | err = -EBADF; |
| 2170 | if (sattr->ia_valid & ATTR_OPEN) |
| 2171 | err = -EACCES; |
| 2172 | goto out; |
| 2173 | } |
| 2174 | } |
| 2175 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2177 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | return err; |
| 2179 | } |
| 2180 | |
| 2181 | struct nfs4_closedata { |
| 2182 | struct inode *inode; |
| 2183 | struct nfs4_state *state; |
| 2184 | struct nfs_closeargs arg; |
| 2185 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2186 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2187 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2188 | bool roc; |
| 2189 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | }; |
| 2191 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2192 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2193 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2194 | struct nfs4_closedata *calldata = data; |
| 2195 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2196 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2197 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2198 | if (calldata->roc) |
| 2199 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2200 | nfs4_put_open_state(calldata->state); |
| 2201 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2202 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2203 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2204 | kfree(calldata); |
| 2205 | } |
| 2206 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2207 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2208 | fmode_t fmode) |
| 2209 | { |
| 2210 | spin_lock(&state->owner->so_lock); |
| 2211 | if (!(fmode & FMODE_READ)) |
| 2212 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2213 | if (!(fmode & FMODE_WRITE)) |
| 2214 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2215 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2216 | spin_unlock(&state->owner->so_lock); |
| 2217 | } |
| 2218 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2219 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2221 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2224 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2225 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2226 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2227 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | /* hmm. we are done with the inode, and in the process of freeing |
| 2229 | * the state_owner. we keep this around to process errors |
| 2230 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | switch (task->tk_status) { |
| 2232 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2233 | if (calldata->roc) |
| 2234 | pnfs_roc_set_barrier(state->inode, |
| 2235 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2236 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2237 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2238 | nfs4_close_clear_stateid_flags(state, |
| 2239 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | break; |
| 2241 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2242 | case -NFS4ERR_OLD_STATEID: |
| 2243 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2245 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2246 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2248 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2249 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2251 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2252 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2253 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2256 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2258 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2259 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2260 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2261 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2262 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2263 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2264 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2265 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2266 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2267 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2268 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2269 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2270 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2271 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2272 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2273 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2274 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2275 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2276 | } |
| 2277 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2278 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2279 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2280 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2281 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2282 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2283 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2284 | |
| 2285 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2286 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2287 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2288 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2289 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2290 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2291 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2292 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2293 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2294 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2295 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2296 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2297 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2298 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2299 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2300 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2301 | &calldata->arg.seq_args, |
| 2302 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2303 | task) != 0) |
| 2304 | nfs_release_seqid(calldata->arg.seqid); |
| 2305 | else |
| 2306 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2307 | out: |
| 2308 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2311 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2312 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2313 | .rpc_call_done = nfs4_close_done, |
| 2314 | .rpc_release = nfs4_free_closedata, |
| 2315 | }; |
| 2316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | /* |
| 2318 | * It is possible for data to be read/written from a mem-mapped file |
| 2319 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2320 | * This means that we can't safely call nfsv4 close on a file until |
| 2321 | * the inode is cleared. This in turn means that we are not good |
| 2322 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2323 | * share state even when we are done with one of the three share |
| 2324 | * stateid's in the inode. |
| 2325 | * |
| 2326 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2327 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2328 | 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] | 2329 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2330 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2332 | struct nfs4_state_owner *sp = state->owner; |
| 2333 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2334 | struct rpc_message msg = { |
| 2335 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2336 | .rpc_cred = state->owner->so_cred, |
| 2337 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2338 | struct rpc_task_setup task_setup_data = { |
| 2339 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2340 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2341 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2342 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2343 | .flags = RPC_TASK_ASYNC, |
| 2344 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2345 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2347 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2349 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2350 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2351 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2353 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2354 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2356 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2357 | if (calldata->arg.seqid == NULL) |
| 2358 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2359 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2360 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2361 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2362 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2363 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2364 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2365 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2366 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2367 | msg.rpc_argp = &calldata->arg; |
| 2368 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2369 | task_setup_data.callback_data = calldata; |
| 2370 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2371 | if (IS_ERR(task)) |
| 2372 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2373 | status = 0; |
| 2374 | if (wait) |
| 2375 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2376 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2377 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2378 | out_free_calldata: |
| 2379 | kfree(calldata); |
| 2380 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2381 | nfs4_put_open_state(state); |
| 2382 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2383 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2386 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2387 | 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] | 2388 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | struct nfs4_state *state; |
| 2390 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2391 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2392 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2393 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2394 | if (IS_ERR(state)) |
| 2395 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2396 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2397 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2400 | 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] | 2401 | { |
| 2402 | if (ctx->state == NULL) |
| 2403 | return; |
| 2404 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2405 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2406 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2407 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2408 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | |
| 2410 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2411 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2412 | struct nfs4_server_caps_arg args = { |
| 2413 | .fhandle = fhandle, |
| 2414 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | struct nfs4_server_caps_res res = {}; |
| 2416 | struct rpc_message msg = { |
| 2417 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2418 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | .rpc_resp = &res, |
| 2420 | }; |
| 2421 | int status; |
| 2422 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2423 | 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] | 2424 | if (status == 0) { |
| 2425 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2426 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2427 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2428 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2429 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2430 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2432 | server->caps |= NFS_CAP_ACLS; |
| 2433 | if (res.has_links != 0) |
| 2434 | server->caps |= NFS_CAP_HARDLINKS; |
| 2435 | if (res.has_symlinks != 0) |
| 2436 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2437 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2438 | server->caps |= NFS_CAP_FILEID; |
| 2439 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2440 | server->caps |= NFS_CAP_MODE; |
| 2441 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2442 | server->caps |= NFS_CAP_NLINK; |
| 2443 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2444 | server->caps |= NFS_CAP_OWNER; |
| 2445 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2446 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2447 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2448 | server->caps |= NFS_CAP_ATIME; |
| 2449 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2450 | server->caps |= NFS_CAP_CTIME; |
| 2451 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2452 | server->caps |= NFS_CAP_MTIME; |
| 2453 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2454 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2455 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2456 | 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] | 2457 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2458 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | return status; |
| 2462 | } |
| 2463 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2464 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | { |
| 2466 | struct nfs4_exception exception = { }; |
| 2467 | int err; |
| 2468 | do { |
| 2469 | err = nfs4_handle_exception(server, |
| 2470 | _nfs4_server_capabilities(server, fhandle), |
| 2471 | &exception); |
| 2472 | } while (exception.retry); |
| 2473 | return err; |
| 2474 | } |
| 2475 | |
| 2476 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2477 | struct nfs_fsinfo *info) |
| 2478 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | struct nfs4_lookup_root_arg args = { |
| 2480 | .bitmask = nfs4_fattr_bitmap, |
| 2481 | }; |
| 2482 | struct nfs4_lookup_res res = { |
| 2483 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2484 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | .fh = fhandle, |
| 2486 | }; |
| 2487 | struct rpc_message msg = { |
| 2488 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2489 | .rpc_argp = &args, |
| 2490 | .rpc_resp = &res, |
| 2491 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2492 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2493 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2494 | 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] | 2495 | } |
| 2496 | |
| 2497 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2498 | struct nfs_fsinfo *info) |
| 2499 | { |
| 2500 | struct nfs4_exception exception = { }; |
| 2501 | int err; |
| 2502 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2503 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2504 | switch (err) { |
| 2505 | case 0: |
| 2506 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2507 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2508 | default: |
| 2509 | err = nfs4_handle_exception(server, err, &exception); |
| 2510 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2512 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | return err; |
| 2514 | } |
| 2515 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2516 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2517 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2518 | { |
| 2519 | struct rpc_auth *auth; |
| 2520 | int ret; |
| 2521 | |
| 2522 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2523 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2524 | ret = -EIO; |
| 2525 | goto out; |
| 2526 | } |
| 2527 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2528 | out: |
| 2529 | return ret; |
| 2530 | } |
| 2531 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2532 | 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] | 2533 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2535 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2536 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2538 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2539 | if (len < 0) |
| 2540 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2541 | |
| 2542 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2543 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2544 | * thus has already been tried. */ |
| 2545 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2546 | continue; |
| 2547 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2548 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2549 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2550 | continue; |
| 2551 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2552 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2553 | /* |
| 2554 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2555 | * to access the mount. It could also mean that we tried to mount |
| 2556 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2557 | * existing mount programs don't handle -EACCES very well so it should |
| 2558 | * be mapped to -EPERM instead. |
| 2559 | */ |
| 2560 | if (status == -EACCES) |
| 2561 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2562 | return status; |
| 2563 | } |
| 2564 | |
| 2565 | /* |
| 2566 | * get the file handle for the "/" directory on the server |
| 2567 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2568 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2569 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2570 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2571 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2572 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2573 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2574 | /* |
| 2575 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2576 | * by nfs4_map_errors() as this function exits. |
| 2577 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2578 | 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] | 2579 | if (status == 0) |
| 2580 | status = nfs4_server_capabilities(server, fhandle); |
| 2581 | if (status == 0) |
| 2582 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2583 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2586 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2587 | struct nfs_fsinfo *info) |
| 2588 | { |
| 2589 | int error; |
| 2590 | struct nfs_fattr *fattr = info->fattr; |
| 2591 | |
| 2592 | error = nfs4_server_capabilities(server, mntfh); |
| 2593 | if (error < 0) { |
| 2594 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2595 | return error; |
| 2596 | } |
| 2597 | |
| 2598 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2599 | if (error < 0) { |
| 2600 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2601 | return error; |
| 2602 | } |
| 2603 | |
| 2604 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2605 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2606 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2607 | |
| 2608 | return error; |
| 2609 | } |
| 2610 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2611 | /* |
| 2612 | * Get locations and (maybe) other attributes of a referral. |
| 2613 | * Note that we'll actually follow the referral later when |
| 2614 | * we detect fsid mismatch in inode revalidation |
| 2615 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2616 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2617 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2618 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2619 | { |
| 2620 | int status = -ENOMEM; |
| 2621 | struct page *page = NULL; |
| 2622 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2623 | |
| 2624 | page = alloc_page(GFP_KERNEL); |
| 2625 | if (page == NULL) |
| 2626 | goto out; |
| 2627 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2628 | if (locations == NULL) |
| 2629 | goto out; |
| 2630 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2631 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2632 | if (status != 0) |
| 2633 | goto out; |
| 2634 | /* Make sure server returned a different fsid for the referral */ |
| 2635 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2636 | dprintk("%s: server did not return a different fsid for" |
| 2637 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2638 | status = -EIO; |
| 2639 | goto out; |
| 2640 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2641 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2642 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2643 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2644 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2645 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2646 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2647 | out: |
| 2648 | if (page) |
| 2649 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2650 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2651 | return status; |
| 2652 | } |
| 2653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2655 | { |
| 2656 | struct nfs4_getattr_arg args = { |
| 2657 | .fh = fhandle, |
| 2658 | .bitmask = server->attr_bitmask, |
| 2659 | }; |
| 2660 | struct nfs4_getattr_res res = { |
| 2661 | .fattr = fattr, |
| 2662 | .server = server, |
| 2663 | }; |
| 2664 | struct rpc_message msg = { |
| 2665 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2666 | .rpc_argp = &args, |
| 2667 | .rpc_resp = &res, |
| 2668 | }; |
| 2669 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2670 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2671 | 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] | 2672 | } |
| 2673 | |
| 2674 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2675 | { |
| 2676 | struct nfs4_exception exception = { }; |
| 2677 | int err; |
| 2678 | do { |
| 2679 | err = nfs4_handle_exception(server, |
| 2680 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2681 | &exception); |
| 2682 | } while (exception.retry); |
| 2683 | return err; |
| 2684 | } |
| 2685 | |
| 2686 | /* |
| 2687 | * The file is not closed if it is opened due to the a request to change |
| 2688 | * the size of the file. The open call will not be needed once the |
| 2689 | * VFS layer lookup-intents are implemented. |
| 2690 | * |
| 2691 | * Close is called when the inode is destroyed. |
| 2692 | * If we haven't opened the file for O_WRONLY, we |
| 2693 | * need to in the size_change case to obtain a stateid. |
| 2694 | * |
| 2695 | * Got race? |
| 2696 | * Because OPEN is always done by name in nfsv4, it is |
| 2697 | * possible that we opened a different file by the same |
| 2698 | * name. We can recognize this race condition, but we |
| 2699 | * can't do anything about it besides returning an error. |
| 2700 | * |
| 2701 | * This will be fixed with VFS changes (lookup-intent). |
| 2702 | */ |
| 2703 | static int |
| 2704 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2705 | struct iattr *sattr) |
| 2706 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2707 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2708 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2709 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | int status; |
| 2711 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2712 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2713 | pnfs_return_layout(inode); |
| 2714 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2715 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2717 | /* Deal with open(O_TRUNC) */ |
| 2718 | if (sattr->ia_valid & ATTR_OPEN) |
| 2719 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2720 | |
| 2721 | /* Optimization: if the end result is no change, don't RPC */ |
| 2722 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2723 | return 0; |
| 2724 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2725 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2726 | if (sattr->ia_valid & ATTR_FILE) { |
| 2727 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2728 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2729 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2730 | if (ctx) { |
| 2731 | cred = ctx->cred; |
| 2732 | state = ctx->state; |
| 2733 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2737 | if (status == 0) |
| 2738 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | return status; |
| 2740 | } |
| 2741 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2742 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2743 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2744 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2745 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2746 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2747 | int status; |
| 2748 | struct nfs4_lookup_arg args = { |
| 2749 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2750 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2751 | .name = name, |
| 2752 | }; |
| 2753 | struct nfs4_lookup_res res = { |
| 2754 | .server = server, |
| 2755 | .fattr = fattr, |
| 2756 | .fh = fhandle, |
| 2757 | }; |
| 2758 | struct rpc_message msg = { |
| 2759 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2760 | .rpc_argp = &args, |
| 2761 | .rpc_resp = &res, |
| 2762 | }; |
| 2763 | |
| 2764 | nfs_fattr_init(fattr); |
| 2765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2767 | 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] | 2768 | dprintk("NFS reply lookup: %d\n", status); |
| 2769 | return status; |
| 2770 | } |
| 2771 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2772 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2773 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2774 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2775 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2776 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2777 | fattr->nlink = 2; |
| 2778 | } |
| 2779 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2780 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2781 | struct qstr *name, struct nfs_fh *fhandle, |
| 2782 | struct nfs_fattr *fattr) |
| 2783 | { |
| 2784 | struct nfs4_exception exception = { }; |
| 2785 | struct rpc_clnt *client = *clnt; |
| 2786 | int err; |
| 2787 | do { |
| 2788 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2789 | switch (err) { |
| 2790 | case -NFS4ERR_BADNAME: |
| 2791 | err = -ENOENT; |
| 2792 | goto out; |
| 2793 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2794 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2795 | goto out; |
| 2796 | case -NFS4ERR_WRONGSEC: |
| 2797 | err = -EPERM; |
| 2798 | if (client != *clnt) |
| 2799 | goto out; |
| 2800 | |
| 2801 | client = nfs4_create_sec_client(client, dir, name); |
| 2802 | if (IS_ERR(client)) |
| 2803 | return PTR_ERR(client); |
| 2804 | |
| 2805 | exception.retry = 1; |
| 2806 | break; |
| 2807 | default: |
| 2808 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2809 | } |
| 2810 | } while (exception.retry); |
| 2811 | |
| 2812 | out: |
| 2813 | if (err == 0) |
| 2814 | *clnt = client; |
| 2815 | else if (client != *clnt) |
| 2816 | rpc_shutdown_client(client); |
| 2817 | |
| 2818 | return err; |
| 2819 | } |
| 2820 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2821 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2822 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2824 | int status; |
| 2825 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2826 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2827 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2828 | if (client != NFS_CLIENT(dir)) { |
| 2829 | rpc_shutdown_client(client); |
| 2830 | nfs_fixup_secinfo_attributes(fattr); |
| 2831 | } |
| 2832 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2835 | struct rpc_clnt * |
| 2836 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2837 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2838 | { |
| 2839 | int status; |
| 2840 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2841 | |
| 2842 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2843 | if (status < 0) { |
| 2844 | rpc_shutdown_client(client); |
| 2845 | return ERR_PTR(status); |
| 2846 | } |
| 2847 | return client; |
| 2848 | } |
| 2849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2851 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2852 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | struct nfs4_accessargs args = { |
| 2854 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2855 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2857 | struct nfs4_accessres res = { |
| 2858 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2859 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | struct rpc_message msg = { |
| 2861 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2862 | .rpc_argp = &args, |
| 2863 | .rpc_resp = &res, |
| 2864 | .rpc_cred = entry->cred, |
| 2865 | }; |
| 2866 | int mode = entry->mask; |
| 2867 | int status; |
| 2868 | |
| 2869 | /* |
| 2870 | * Determine which access bits we want to ask for... |
| 2871 | */ |
| 2872 | if (mode & MAY_READ) |
| 2873 | args.access |= NFS4_ACCESS_READ; |
| 2874 | if (S_ISDIR(inode->i_mode)) { |
| 2875 | if (mode & MAY_WRITE) |
| 2876 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2877 | if (mode & MAY_EXEC) |
| 2878 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2879 | } else { |
| 2880 | if (mode & MAY_WRITE) |
| 2881 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2882 | if (mode & MAY_EXEC) |
| 2883 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2884 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2885 | |
| 2886 | res.fattr = nfs_alloc_fattr(); |
| 2887 | if (res.fattr == NULL) |
| 2888 | return -ENOMEM; |
| 2889 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2890 | 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] | 2891 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2892 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2893 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2895 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | return status; |
| 2897 | } |
| 2898 | |
| 2899 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2900 | { |
| 2901 | struct nfs4_exception exception = { }; |
| 2902 | int err; |
| 2903 | do { |
| 2904 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2905 | _nfs4_proc_access(inode, entry), |
| 2906 | &exception); |
| 2907 | } while (exception.retry); |
| 2908 | return err; |
| 2909 | } |
| 2910 | |
| 2911 | /* |
| 2912 | * TODO: For the time being, we don't try to get any attributes |
| 2913 | * along with any of the zero-copy operations READ, READDIR, |
| 2914 | * READLINK, WRITE. |
| 2915 | * |
| 2916 | * In the case of the first three, we want to put the GETATTR |
| 2917 | * after the read-type operation -- this is because it is hard |
| 2918 | * to predict the length of a GETATTR response in v4, and thus |
| 2919 | * align the READ data correctly. This means that the GETATTR |
| 2920 | * may end up partially falling into the page cache, and we should |
| 2921 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2922 | * To do this efficiently, we need to know the total length |
| 2923 | * of data received, which doesn't seem to be available outside |
| 2924 | * of the RPC layer. |
| 2925 | * |
| 2926 | * In the case of WRITE, we also want to put the GETATTR after |
| 2927 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2928 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | * |
| 2930 | * Both of these changes to the XDR layer would in fact be quite |
| 2931 | * minor, but I decided to leave them for a subsequent patch. |
| 2932 | */ |
| 2933 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2934 | unsigned int pgbase, unsigned int pglen) |
| 2935 | { |
| 2936 | struct nfs4_readlink args = { |
| 2937 | .fh = NFS_FH(inode), |
| 2938 | .pgbase = pgbase, |
| 2939 | .pglen = pglen, |
| 2940 | .pages = &page, |
| 2941 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2942 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | struct rpc_message msg = { |
| 2944 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2945 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2946 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | }; |
| 2948 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2949 | 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] | 2950 | } |
| 2951 | |
| 2952 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2953 | unsigned int pgbase, unsigned int pglen) |
| 2954 | { |
| 2955 | struct nfs4_exception exception = { }; |
| 2956 | int err; |
| 2957 | do { |
| 2958 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2959 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2960 | &exception); |
| 2961 | } while (exception.retry); |
| 2962 | return err; |
| 2963 | } |
| 2964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2966 | * 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] | 2967 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | static int |
| 2969 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2970 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2972 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | int status = 0; |
| 2975 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2976 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2977 | if (IS_ERR(ctx)) |
| 2978 | return PTR_ERR(ctx); |
| 2979 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2980 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2981 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2982 | flags, sattr, ctx->cred, |
| 2983 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2984 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | if (IS_ERR(state)) { |
| 2986 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2987 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2989 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2990 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2991 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2993 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | return status; |
| 2995 | } |
| 2996 | |
| 2997 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2998 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2999 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3000 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3002 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3004 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3005 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3006 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3008 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3009 | .rpc_argp = &args, |
| 3010 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3012 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3013 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3014 | 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] | 3015 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3016 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | return status; |
| 3018 | } |
| 3019 | |
| 3020 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3021 | { |
| 3022 | struct nfs4_exception exception = { }; |
| 3023 | int err; |
| 3024 | do { |
| 3025 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3026 | _nfs4_proc_remove(dir, name), |
| 3027 | &exception); |
| 3028 | } while (exception.retry); |
| 3029 | return err; |
| 3030 | } |
| 3031 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3032 | 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] | 3033 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3034 | struct nfs_server *server = NFS_SERVER(dir); |
| 3035 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3036 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3038 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3040 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3043 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3044 | { |
| 3045 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3046 | &data->args.seq_args, |
| 3047 | &data->res.seq_res, |
| 3048 | task)) |
| 3049 | return; |
| 3050 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3053 | 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] | 3054 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3055 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3056 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3057 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3058 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3059 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3060 | return 0; |
| 3061 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3062 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | } |
| 3064 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3065 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3066 | { |
| 3067 | struct nfs_server *server = NFS_SERVER(dir); |
| 3068 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3069 | struct nfs_renameres *res = msg->rpc_resp; |
| 3070 | |
| 3071 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3072 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3073 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3074 | } |
| 3075 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3076 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3077 | { |
| 3078 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3079 | &data->args.seq_args, |
| 3080 | &data->res.seq_res, |
| 3081 | task)) |
| 3082 | return; |
| 3083 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3087 | struct inode *new_dir) |
| 3088 | { |
| 3089 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3090 | |
| 3091 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3092 | return 0; |
| 3093 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3094 | return 0; |
| 3095 | |
| 3096 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3097 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3098 | return 1; |
| 3099 | } |
| 3100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3102 | struct inode *new_dir, struct qstr *new_name) |
| 3103 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3104 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3105 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | .old_dir = NFS_FH(old_dir), |
| 3107 | .new_dir = NFS_FH(new_dir), |
| 3108 | .old_name = old_name, |
| 3109 | .new_name = new_name, |
| 3110 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3111 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3112 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3113 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | struct rpc_message msg = { |
| 3115 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3116 | .rpc_argp = &arg, |
| 3117 | .rpc_resp = &res, |
| 3118 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3119 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3121 | 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] | 3122 | if (!status) { |
| 3123 | update_changeattr(old_dir, &res.old_cinfo); |
| 3124 | update_changeattr(new_dir, &res.new_cinfo); |
| 3125 | } |
| 3126 | return status; |
| 3127 | } |
| 3128 | |
| 3129 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3130 | struct inode *new_dir, struct qstr *new_name) |
| 3131 | { |
| 3132 | struct nfs4_exception exception = { }; |
| 3133 | int err; |
| 3134 | do { |
| 3135 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3136 | _nfs4_proc_rename(old_dir, old_name, |
| 3137 | new_dir, new_name), |
| 3138 | &exception); |
| 3139 | } while (exception.retry); |
| 3140 | return err; |
| 3141 | } |
| 3142 | |
| 3143 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3144 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3145 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | struct nfs4_link_arg arg = { |
| 3147 | .fh = NFS_FH(inode), |
| 3148 | .dir_fh = NFS_FH(dir), |
| 3149 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3150 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3152 | struct nfs4_link_res res = { |
| 3153 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3154 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | struct rpc_message msg = { |
| 3156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3157 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3158 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3160 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3162 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3163 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3164 | goto out; |
| 3165 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3166 | 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] | 3167 | if (!status) { |
| 3168 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3169 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3170 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3171 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3172 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | return status; |
| 3174 | } |
| 3175 | |
| 3176 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3177 | { |
| 3178 | struct nfs4_exception exception = { }; |
| 3179 | int err; |
| 3180 | do { |
| 3181 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3182 | _nfs4_proc_link(inode, dir, name), |
| 3183 | &exception); |
| 3184 | } while (exception.retry); |
| 3185 | return err; |
| 3186 | } |
| 3187 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3188 | struct nfs4_createdata { |
| 3189 | struct rpc_message msg; |
| 3190 | struct nfs4_create_arg arg; |
| 3191 | struct nfs4_create_res res; |
| 3192 | struct nfs_fh fh; |
| 3193 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3194 | }; |
| 3195 | |
| 3196 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3197 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3198 | { |
| 3199 | struct nfs4_createdata *data; |
| 3200 | |
| 3201 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3202 | if (data != NULL) { |
| 3203 | struct nfs_server *server = NFS_SERVER(dir); |
| 3204 | |
| 3205 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3206 | data->msg.rpc_argp = &data->arg; |
| 3207 | data->msg.rpc_resp = &data->res; |
| 3208 | data->arg.dir_fh = NFS_FH(dir); |
| 3209 | data->arg.server = server; |
| 3210 | data->arg.name = name; |
| 3211 | data->arg.attrs = sattr; |
| 3212 | data->arg.ftype = ftype; |
| 3213 | data->arg.bitmask = server->attr_bitmask; |
| 3214 | data->res.server = server; |
| 3215 | data->res.fh = &data->fh; |
| 3216 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3217 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3218 | } |
| 3219 | return data; |
| 3220 | } |
| 3221 | |
| 3222 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3223 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3224 | 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] | 3225 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3226 | if (status == 0) { |
| 3227 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3228 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3229 | } |
| 3230 | return status; |
| 3231 | } |
| 3232 | |
| 3233 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3234 | { |
| 3235 | kfree(data); |
| 3236 | } |
| 3237 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3238 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3239 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3241 | struct nfs4_createdata *data; |
| 3242 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3244 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3245 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3246 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3247 | status = -ENOMEM; |
| 3248 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3249 | if (data == NULL) |
| 3250 | goto out; |
| 3251 | |
| 3252 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3253 | data->arg.u.symlink.pages = &page; |
| 3254 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3256 | status = nfs4_do_create(dir, dentry, data); |
| 3257 | |
| 3258 | nfs4_free_createdata(data); |
| 3259 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return status; |
| 3261 | } |
| 3262 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3263 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3264 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | { |
| 3266 | struct nfs4_exception exception = { }; |
| 3267 | int err; |
| 3268 | do { |
| 3269 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3270 | _nfs4_proc_symlink(dir, dentry, page, |
| 3271 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | &exception); |
| 3273 | } while (exception.retry); |
| 3274 | return err; |
| 3275 | } |
| 3276 | |
| 3277 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3278 | struct iattr *sattr) |
| 3279 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3280 | struct nfs4_createdata *data; |
| 3281 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3283 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3284 | if (data == NULL) |
| 3285 | goto out; |
| 3286 | |
| 3287 | status = nfs4_do_create(dir, dentry, data); |
| 3288 | |
| 3289 | nfs4_free_createdata(data); |
| 3290 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | return status; |
| 3292 | } |
| 3293 | |
| 3294 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3295 | struct iattr *sattr) |
| 3296 | { |
| 3297 | struct nfs4_exception exception = { }; |
| 3298 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3299 | |
| 3300 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | do { |
| 3302 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3303 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3304 | &exception); |
| 3305 | } while (exception.retry); |
| 3306 | return err; |
| 3307 | } |
| 3308 | |
| 3309 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3310 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | { |
| 3312 | struct inode *dir = dentry->d_inode; |
| 3313 | struct nfs4_readdir_arg args = { |
| 3314 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3315 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | .pgbase = 0, |
| 3317 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3318 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3319 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | }; |
| 3321 | struct nfs4_readdir_res res; |
| 3322 | struct rpc_message msg = { |
| 3323 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3324 | .rpc_argp = &args, |
| 3325 | .rpc_resp = &res, |
| 3326 | .rpc_cred = cred, |
| 3327 | }; |
| 3328 | int status; |
| 3329 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3330 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3331 | dentry->d_parent->d_name.name, |
| 3332 | dentry->d_name.name, |
| 3333 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3334 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3336 | 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] | 3337 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3338 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3339 | status += args.pgbase; |
| 3340 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3341 | |
| 3342 | nfs_invalidate_atime(dir); |
| 3343 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3344 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | return status; |
| 3346 | } |
| 3347 | |
| 3348 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3349 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | { |
| 3351 | struct nfs4_exception exception = { }; |
| 3352 | int err; |
| 3353 | do { |
| 3354 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3355 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3356 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | &exception); |
| 3358 | } while (exception.retry); |
| 3359 | return err; |
| 3360 | } |
| 3361 | |
| 3362 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3363 | struct iattr *sattr, dev_t rdev) |
| 3364 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3365 | struct nfs4_createdata *data; |
| 3366 | int mode = sattr->ia_mode; |
| 3367 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3369 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3370 | if (data == NULL) |
| 3371 | goto out; |
| 3372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3374 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3376 | data->arg.ftype = NF4BLK; |
| 3377 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3378 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | } |
| 3380 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3381 | data->arg.ftype = NF4CHR; |
| 3382 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3383 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3384 | } else if (!S_ISSOCK(mode)) { |
| 3385 | status = -EINVAL; |
| 3386 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3389 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3390 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3391 | nfs4_free_createdata(data); |
| 3392 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | return status; |
| 3394 | } |
| 3395 | |
| 3396 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3397 | struct iattr *sattr, dev_t rdev) |
| 3398 | { |
| 3399 | struct nfs4_exception exception = { }; |
| 3400 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3401 | |
| 3402 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | do { |
| 3404 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3405 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3406 | &exception); |
| 3407 | } while (exception.retry); |
| 3408 | return err; |
| 3409 | } |
| 3410 | |
| 3411 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3412 | struct nfs_fsstat *fsstat) |
| 3413 | { |
| 3414 | struct nfs4_statfs_arg args = { |
| 3415 | .fh = fhandle, |
| 3416 | .bitmask = server->attr_bitmask, |
| 3417 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3418 | struct nfs4_statfs_res res = { |
| 3419 | .fsstat = fsstat, |
| 3420 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | struct rpc_message msg = { |
| 3422 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3423 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3424 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | }; |
| 3426 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3427 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3428 | 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] | 3429 | } |
| 3430 | |
| 3431 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3432 | { |
| 3433 | struct nfs4_exception exception = { }; |
| 3434 | int err; |
| 3435 | do { |
| 3436 | err = nfs4_handle_exception(server, |
| 3437 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3438 | &exception); |
| 3439 | } while (exception.retry); |
| 3440 | return err; |
| 3441 | } |
| 3442 | |
| 3443 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3444 | struct nfs_fsinfo *fsinfo) |
| 3445 | { |
| 3446 | struct nfs4_fsinfo_arg args = { |
| 3447 | .fh = fhandle, |
| 3448 | .bitmask = server->attr_bitmask, |
| 3449 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3450 | struct nfs4_fsinfo_res res = { |
| 3451 | .fsinfo = fsinfo, |
| 3452 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | struct rpc_message msg = { |
| 3454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3455 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3456 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | }; |
| 3458 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3459 | 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] | 3460 | } |
| 3461 | |
| 3462 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3463 | { |
| 3464 | struct nfs4_exception exception = { }; |
| 3465 | int err; |
| 3466 | |
| 3467 | do { |
| 3468 | err = nfs4_handle_exception(server, |
| 3469 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3470 | &exception); |
| 3471 | } while (exception.retry); |
| 3472 | return err; |
| 3473 | } |
| 3474 | |
| 3475 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3476 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3477 | int error; |
| 3478 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3479 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3480 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3481 | if (error == 0) { |
| 3482 | /* block layout checks this! */ |
| 3483 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3484 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3485 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3486 | |
| 3487 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3491 | struct nfs_pathconf *pathconf) |
| 3492 | { |
| 3493 | struct nfs4_pathconf_arg args = { |
| 3494 | .fh = fhandle, |
| 3495 | .bitmask = server->attr_bitmask, |
| 3496 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3497 | struct nfs4_pathconf_res res = { |
| 3498 | .pathconf = pathconf, |
| 3499 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | struct rpc_message msg = { |
| 3501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3502 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3503 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | }; |
| 3505 | |
| 3506 | /* None of the pathconf attributes are mandatory to implement */ |
| 3507 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3508 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3509 | return 0; |
| 3510 | } |
| 3511 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3512 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3513 | 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] | 3514 | } |
| 3515 | |
| 3516 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3517 | struct nfs_pathconf *pathconf) |
| 3518 | { |
| 3519 | struct nfs4_exception exception = { }; |
| 3520 | int err; |
| 3521 | |
| 3522 | do { |
| 3523 | err = nfs4_handle_exception(server, |
| 3524 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3525 | &exception); |
| 3526 | } while (exception.retry); |
| 3527 | return err; |
| 3528 | } |
| 3529 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3530 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3531 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3532 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3533 | } |
| 3534 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3535 | 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] | 3536 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3537 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3539 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3540 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3541 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3543 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3544 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3546 | renew_lease(server, data->timestamp); |
| 3547 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3550 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3551 | { |
| 3552 | |
| 3553 | dprintk("--> %s\n", __func__); |
| 3554 | |
| 3555 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3556 | return -EAGAIN; |
| 3557 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3558 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3559 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3560 | } |
| 3561 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3562 | 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] | 3563 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3565 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3566 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3567 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3570 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3571 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3572 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3573 | &data->args.seq_args, |
| 3574 | &data->res.seq_res, |
| 3575 | task)) |
| 3576 | return; |
| 3577 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3580 | 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] | 3581 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3582 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3584 | 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] | 3585 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3586 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3588 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3590 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3591 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3592 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3595 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3596 | { |
| 3597 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3598 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3599 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3600 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3603 | static |
| 3604 | 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] | 3605 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3606 | const struct nfs_pgio_header *hdr = data->header; |
| 3607 | |
| 3608 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3609 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3610 | return false; |
| 3611 | /* Otherwise, request attributes if and only if we don't hold |
| 3612 | * a delegation |
| 3613 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3614 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3615 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3616 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3617 | 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] | 3618 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3619 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3620 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3621 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3622 | data->args.bitmask = NULL; |
| 3623 | data->res.fattr = NULL; |
| 3624 | } else |
| 3625 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3626 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3627 | if (!data->write_done_cb) |
| 3628 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3629 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | data->timestamp = jiffies; |
| 3631 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3632 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3633 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3636 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3637 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3638 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3639 | &data->args.seq_args, |
| 3640 | &data->res.seq_res, |
| 3641 | task)) |
| 3642 | return; |
| 3643 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | } |
| 3645 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3646 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3647 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3649 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3650 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | return; |
| 3653 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3654 | } |
| 3655 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3656 | 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] | 3657 | { |
| 3658 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3659 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3660 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3661 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3662 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3664 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | } |
| 3666 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3667 | 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] | 3668 | { |
| 3669 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3670 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3671 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3672 | } |
| 3673 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3674 | 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] | 3675 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3676 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3677 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3678 | if (data->commit_done_cb == NULL) |
| 3679 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3680 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3681 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3682 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3685 | struct nfs4_renewdata { |
| 3686 | struct nfs_client *client; |
| 3687 | unsigned long timestamp; |
| 3688 | }; |
| 3689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | /* |
| 3691 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3692 | * standalone procedure for queueing an asynchronous RENEW. |
| 3693 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3694 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3695 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3696 | struct nfs4_renewdata *data = calldata; |
| 3697 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3698 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3699 | if (atomic_read(&clp->cl_count) > 1) |
| 3700 | nfs4_schedule_state_renewal(clp); |
| 3701 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3702 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3703 | } |
| 3704 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3705 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3707 | struct nfs4_renewdata *data = calldata; |
| 3708 | struct nfs_client *clp = data->client; |
| 3709 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | |
| 3711 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3712 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3713 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3714 | return; |
| 3715 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3716 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3717 | return; |
| 3718 | } |
| 3719 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3721 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3724 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3725 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3726 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3727 | }; |
| 3728 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3729 | 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] | 3730 | { |
| 3731 | struct rpc_message msg = { |
| 3732 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3733 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3734 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3736 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3738 | if (renew_flags == 0) |
| 3739 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3740 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3741 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3742 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3743 | if (data == NULL) |
| 3744 | return -ENOMEM; |
| 3745 | data->client = clp; |
| 3746 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3748 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | } |
| 3750 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3751 | 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] | 3752 | { |
| 3753 | struct rpc_message msg = { |
| 3754 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3755 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3756 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | }; |
| 3758 | unsigned long now = jiffies; |
| 3759 | int status; |
| 3760 | |
| 3761 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3762 | if (status < 0) |
| 3763 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3764 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | return 0; |
| 3766 | } |
| 3767 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3768 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3769 | { |
| 3770 | return (server->caps & NFS_CAP_ACLS) |
| 3771 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3772 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3773 | } |
| 3774 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3775 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3776 | * 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] | 3777 | * the stack. |
| 3778 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3779 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3780 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3781 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3782 | struct page **pages, unsigned int *pgbase) |
| 3783 | { |
| 3784 | struct page *newpage, **spages; |
| 3785 | int rc = 0; |
| 3786 | size_t len; |
| 3787 | spages = pages; |
| 3788 | |
| 3789 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3790 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3791 | newpage = alloc_page(GFP_KERNEL); |
| 3792 | |
| 3793 | if (newpage == NULL) |
| 3794 | goto unwind; |
| 3795 | memcpy(page_address(newpage), buf, len); |
| 3796 | buf += len; |
| 3797 | buflen -= len; |
| 3798 | *pages++ = newpage; |
| 3799 | rc++; |
| 3800 | } while (buflen != 0); |
| 3801 | |
| 3802 | return rc; |
| 3803 | |
| 3804 | unwind: |
| 3805 | for(; rc > 0; rc--) |
| 3806 | __free_page(spages[rc-1]); |
| 3807 | return -ENOMEM; |
| 3808 | } |
| 3809 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3810 | struct nfs4_cached_acl { |
| 3811 | int cached; |
| 3812 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3813 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3814 | }; |
| 3815 | |
| 3816 | 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] | 3817 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3818 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3819 | |
| 3820 | spin_lock(&inode->i_lock); |
| 3821 | kfree(nfsi->nfs4_acl); |
| 3822 | nfsi->nfs4_acl = acl; |
| 3823 | spin_unlock(&inode->i_lock); |
| 3824 | } |
| 3825 | |
| 3826 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3827 | { |
| 3828 | nfs4_set_cached_acl(inode, NULL); |
| 3829 | } |
| 3830 | |
| 3831 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3832 | { |
| 3833 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3834 | struct nfs4_cached_acl *acl; |
| 3835 | int ret = -ENOENT; |
| 3836 | |
| 3837 | spin_lock(&inode->i_lock); |
| 3838 | acl = nfsi->nfs4_acl; |
| 3839 | if (acl == NULL) |
| 3840 | goto out; |
| 3841 | if (buf == NULL) /* user is just asking for length */ |
| 3842 | goto out_len; |
| 3843 | if (acl->cached == 0) |
| 3844 | goto out; |
| 3845 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3846 | if (acl->len > buflen) |
| 3847 | goto out; |
| 3848 | memcpy(buf, acl->data, acl->len); |
| 3849 | out_len: |
| 3850 | ret = acl->len; |
| 3851 | out: |
| 3852 | spin_unlock(&inode->i_lock); |
| 3853 | return ret; |
| 3854 | } |
| 3855 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3856 | 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] | 3857 | { |
| 3858 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3859 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3860 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3861 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3862 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3863 | if (acl == NULL) |
| 3864 | goto out; |
| 3865 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3866 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3867 | } else { |
| 3868 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3869 | if (acl == NULL) |
| 3870 | goto out; |
| 3871 | acl->cached = 0; |
| 3872 | } |
| 3873 | acl->len = acl_len; |
| 3874 | out: |
| 3875 | nfs4_set_cached_acl(inode, acl); |
| 3876 | } |
| 3877 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3878 | /* |
| 3879 | * The getxattr API returns the required buffer length when called with a |
| 3880 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3881 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3882 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3883 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3884 | * the cache. If not so, we throw away the page, and cache the required |
| 3885 | * length. The next getxattr call will then produce another round trip to |
| 3886 | * the server, this time with the input buf of the required size. |
| 3887 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3888 | 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] | 3889 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3890 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3891 | struct nfs_getaclargs args = { |
| 3892 | .fh = NFS_FH(inode), |
| 3893 | .acl_pages = pages, |
| 3894 | .acl_len = buflen, |
| 3895 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3896 | struct nfs_getaclres res = { |
| 3897 | .acl_len = buflen, |
| 3898 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3899 | struct rpc_message msg = { |
| 3900 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3901 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3902 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3903 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3904 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3905 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3906 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3907 | /* As long as we're doing a round trip to the server anyway, |
| 3908 | * let's be prepared for a page of acl data. */ |
| 3909 | if (npages == 0) |
| 3910 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3911 | if (npages > ARRAY_SIZE(pages)) |
| 3912 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3913 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3914 | for (i = 0; i < npages; i++) { |
| 3915 | pages[i] = alloc_page(GFP_KERNEL); |
| 3916 | if (!pages[i]) |
| 3917 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3918 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3919 | |
| 3920 | /* for decoding across pages */ |
| 3921 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3922 | if (!res.acl_scratch) |
| 3923 | goto out_free; |
| 3924 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3925 | args.acl_len = npages * PAGE_SIZE; |
| 3926 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3927 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3928 | 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] | 3929 | __func__, buf, buflen, npages, args.acl_len); |
| 3930 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3931 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3932 | if (ret) |
| 3933 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3934 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3935 | /* Handle the case where the passed-in buffer is too short */ |
| 3936 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3937 | /* Did the user only issue a request for the acl length? */ |
| 3938 | if (buf == NULL) |
| 3939 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3940 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3941 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3942 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3943 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3944 | if (buf) |
| 3945 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3946 | out_ok: |
| 3947 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3948 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3949 | for (i = 0; i < npages; i++) |
| 3950 | if (pages[i]) |
| 3951 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3952 | if (res.acl_scratch) |
| 3953 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3954 | return ret; |
| 3955 | } |
| 3956 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3957 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3958 | { |
| 3959 | struct nfs4_exception exception = { }; |
| 3960 | ssize_t ret; |
| 3961 | do { |
| 3962 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3963 | if (ret >= 0) |
| 3964 | break; |
| 3965 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3966 | } while (exception.retry); |
| 3967 | return ret; |
| 3968 | } |
| 3969 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3970 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3971 | { |
| 3972 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3973 | int ret; |
| 3974 | |
| 3975 | if (!nfs4_server_supports_acls(server)) |
| 3976 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3977 | ret = nfs_revalidate_inode(server, inode); |
| 3978 | if (ret < 0) |
| 3979 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3980 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3981 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3982 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3983 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3984 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3985 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3986 | return ret; |
| 3987 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3988 | } |
| 3989 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3990 | 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] | 3991 | { |
| 3992 | struct nfs_server *server = NFS_SERVER(inode); |
| 3993 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3994 | struct nfs_setaclargs arg = { |
| 3995 | .fh = NFS_FH(inode), |
| 3996 | .acl_pages = pages, |
| 3997 | .acl_len = buflen, |
| 3998 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3999 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4000 | struct rpc_message msg = { |
| 4001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4002 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4003 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4004 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4005 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4006 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4007 | |
| 4008 | if (!nfs4_server_supports_acls(server)) |
| 4009 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4010 | if (npages > ARRAY_SIZE(pages)) |
| 4011 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4012 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4013 | if (i < 0) |
| 4014 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4015 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4016 | 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] | 4017 | |
| 4018 | /* |
| 4019 | * Free each page after tx, so the only ref left is |
| 4020 | * held by the network stack |
| 4021 | */ |
| 4022 | for (; i > 0; i--) |
| 4023 | put_page(pages[i-1]); |
| 4024 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4025 | /* |
| 4026 | * Acl update can result in inode attribute update. |
| 4027 | * so mark the attribute cache invalid. |
| 4028 | */ |
| 4029 | spin_lock(&inode->i_lock); |
| 4030 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4031 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4032 | nfs_access_zap_cache(inode); |
| 4033 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4034 | return ret; |
| 4035 | } |
| 4036 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4037 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4038 | { |
| 4039 | struct nfs4_exception exception = { }; |
| 4040 | int err; |
| 4041 | do { |
| 4042 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4043 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4044 | &exception); |
| 4045 | } while (exception.retry); |
| 4046 | return err; |
| 4047 | } |
| 4048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4050 | 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] | 4051 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4052 | struct nfs_client *clp = server->nfs_client; |
| 4053 | |
| 4054 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | return 0; |
| 4056 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4057 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4058 | case -NFS4ERR_ADMIN_REVOKED: |
| 4059 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4060 | if (state == NULL) |
| 4061 | break; |
| 4062 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4063 | case -NFS4ERR_OPENMODE: |
| 4064 | if (state == NULL) |
| 4065 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4066 | nfs4_schedule_stateid_recovery(server, state); |
| 4067 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4068 | case -NFS4ERR_EXPIRED: |
| 4069 | if (state != NULL) |
| 4070 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4072 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4073 | nfs4_schedule_lease_recovery(clp); |
| 4074 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4075 | #if defined(CONFIG_NFS_V4_1) |
| 4076 | case -NFS4ERR_BADSESSION: |
| 4077 | case -NFS4ERR_BADSLOT: |
| 4078 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4079 | case -NFS4ERR_DEADSESSION: |
| 4080 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4081 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4082 | case -NFS4ERR_SEQ_MISORDERED: |
| 4083 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4084 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4085 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4086 | task->tk_status = 0; |
| 4087 | return -EAGAIN; |
| 4088 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4090 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4091 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4092 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4094 | task->tk_status = 0; |
| 4095 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4096 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | case -NFS4ERR_OLD_STATEID: |
| 4098 | task->tk_status = 0; |
| 4099 | return -EAGAIN; |
| 4100 | } |
| 4101 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4102 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4103 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4104 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4105 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4106 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4107 | task->tk_status = 0; |
| 4108 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | } |
| 4110 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4111 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4112 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4113 | { |
| 4114 | __be32 verf[2]; |
| 4115 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4116 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4117 | /* An impossible timestamp guarantees this value |
| 4118 | * will never match a generated boot time. */ |
| 4119 | verf[0] = 0; |
| 4120 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4121 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4122 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4123 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4124 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4125 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4126 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4127 | } |
| 4128 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4129 | static unsigned int |
| 4130 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4131 | char *buf, size_t len) |
| 4132 | { |
| 4133 | unsigned int result; |
| 4134 | |
| 4135 | rcu_read_lock(); |
| 4136 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4137 | clp->cl_ipaddr, |
| 4138 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4139 | RPC_DISPLAY_ADDR), |
| 4140 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4141 | RPC_DISPLAY_PROTO)); |
| 4142 | rcu_read_unlock(); |
| 4143 | return result; |
| 4144 | } |
| 4145 | |
| 4146 | static unsigned int |
| 4147 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4148 | char *buf, size_t len) |
| 4149 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4150 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4151 | |
| 4152 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4153 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4154 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4155 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4156 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4157 | } |
| 4158 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4159 | /** |
| 4160 | * nfs4_proc_setclientid - Negotiate client ID |
| 4161 | * @clp: state data structure |
| 4162 | * @program: RPC program for NFSv4 callback service |
| 4163 | * @port: IP port number for NFS4 callback service |
| 4164 | * @cred: RPC credential to use for this call |
| 4165 | * @res: where to place the result |
| 4166 | * |
| 4167 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4168 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4169 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4170 | unsigned short port, struct rpc_cred *cred, |
| 4171 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | { |
| 4173 | nfs4_verifier sc_verifier; |
| 4174 | struct nfs4_setclientid setclientid = { |
| 4175 | .sc_verifier = &sc_verifier, |
| 4176 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4177 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | }; |
| 4179 | struct rpc_message msg = { |
| 4180 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4181 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4182 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4183 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4185 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4187 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4188 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4189 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4190 | setclientid.sc_name_len = |
| 4191 | nfs4_init_uniform_client_string(clp, |
| 4192 | setclientid.sc_name, |
| 4193 | sizeof(setclientid.sc_name)); |
| 4194 | else |
| 4195 | setclientid.sc_name_len = |
| 4196 | nfs4_init_nonuniform_client_string(clp, |
| 4197 | setclientid.sc_name, |
| 4198 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4199 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4200 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4201 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4202 | sizeof(setclientid.sc_netid), |
| 4203 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4204 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4205 | rcu_read_unlock(); |
| 4206 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4207 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4209 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4210 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4211 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4212 | setclientid.sc_name_len, setclientid.sc_name); |
| 4213 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4214 | dprintk("NFS reply setclientid: %d\n", status); |
| 4215 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4218 | /** |
| 4219 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4220 | * @clp: state data structure |
| 4221 | * @res: result of a previous SETCLIENTID |
| 4222 | * @cred: RPC credential to use for this call |
| 4223 | * |
| 4224 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4225 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4226 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4227 | struct nfs4_setclientid_res *arg, |
| 4228 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | { |
| 4230 | struct nfs_fsinfo fsinfo; |
| 4231 | struct rpc_message msg = { |
| 4232 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4233 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4235 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | }; |
| 4237 | unsigned long now; |
| 4238 | int status; |
| 4239 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4240 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4241 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4242 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4244 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | if (status == 0) { |
| 4246 | spin_lock(&clp->cl_lock); |
| 4247 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4248 | clp->cl_last_renewal = now; |
| 4249 | spin_unlock(&clp->cl_lock); |
| 4250 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4251 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | return status; |
| 4253 | } |
| 4254 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4255 | struct nfs4_delegreturndata { |
| 4256 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4257 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4258 | struct nfs_fh fh; |
| 4259 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4260 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4261 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4262 | int rpc_status; |
| 4263 | }; |
| 4264 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4265 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4266 | { |
| 4267 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4268 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4269 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4270 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4271 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4272 | switch (task->tk_status) { |
| 4273 | case -NFS4ERR_STALE_STATEID: |
| 4274 | case -NFS4ERR_EXPIRED: |
| 4275 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4276 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4277 | break; |
| 4278 | default: |
| 4279 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4280 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4281 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4282 | return; |
| 4283 | } |
| 4284 | } |
| 4285 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | static void nfs4_delegreturn_release(void *calldata) |
| 4289 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4290 | kfree(calldata); |
| 4291 | } |
| 4292 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4293 | #if defined(CONFIG_NFS_V4_1) |
| 4294 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4295 | { |
| 4296 | struct nfs4_delegreturndata *d_data; |
| 4297 | |
| 4298 | d_data = (struct nfs4_delegreturndata *)data; |
| 4299 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4300 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4301 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4302 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4303 | return; |
| 4304 | rpc_call_start(task); |
| 4305 | } |
| 4306 | #endif /* CONFIG_NFS_V4_1 */ |
| 4307 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4308 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4309 | #if defined(CONFIG_NFS_V4_1) |
| 4310 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4311 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4312 | .rpc_call_done = nfs4_delegreturn_done, |
| 4313 | .rpc_release = nfs4_delegreturn_release, |
| 4314 | }; |
| 4315 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4316 | 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] | 4317 | { |
| 4318 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4319 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4320 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4321 | struct rpc_message msg = { |
| 4322 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4323 | .rpc_cred = cred, |
| 4324 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4325 | struct rpc_task_setup task_setup_data = { |
| 4326 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4327 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4328 | .callback_ops = &nfs4_delegreturn_ops, |
| 4329 | .flags = RPC_TASK_ASYNC, |
| 4330 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4331 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4332 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4333 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4334 | if (data == NULL) |
| 4335 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4336 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4337 | data->args.fhandle = &data->fh; |
| 4338 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4339 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4340 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4341 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4342 | data->res.fattr = &data->fattr; |
| 4343 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4344 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4345 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4346 | data->rpc_status = 0; |
| 4347 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4348 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4349 | msg.rpc_argp = &data->args; |
| 4350 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4351 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4352 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4353 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4354 | if (!issync) |
| 4355 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4356 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4357 | if (status != 0) |
| 4358 | goto out; |
| 4359 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4360 | if (status == 0) |
| 4361 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4362 | else |
| 4363 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4364 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4365 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4366 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | } |
| 4368 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4369 | 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] | 4370 | { |
| 4371 | struct nfs_server *server = NFS_SERVER(inode); |
| 4372 | struct nfs4_exception exception = { }; |
| 4373 | int err; |
| 4374 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4375 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | switch (err) { |
| 4377 | case -NFS4ERR_STALE_STATEID: |
| 4378 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | case 0: |
| 4380 | return 0; |
| 4381 | } |
| 4382 | err = nfs4_handle_exception(server, err, &exception); |
| 4383 | } while (exception.retry); |
| 4384 | return err; |
| 4385 | } |
| 4386 | |
| 4387 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4388 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4389 | |
| 4390 | /* |
| 4391 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4392 | */ |
| 4393 | static unsigned long |
| 4394 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4395 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4396 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | timeout <<= 1; |
| 4398 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4399 | return NFS4_LOCK_MAXTIMEOUT; |
| 4400 | return timeout; |
| 4401 | } |
| 4402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4404 | { |
| 4405 | struct inode *inode = state->inode; |
| 4406 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4407 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4408 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4410 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4412 | struct nfs_lockt_res res = { |
| 4413 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | }; |
| 4415 | struct rpc_message msg = { |
| 4416 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4417 | .rpc_argp = &arg, |
| 4418 | .rpc_resp = &res, |
| 4419 | .rpc_cred = state->owner->so_cred, |
| 4420 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | struct nfs4_lock_state *lsp; |
| 4422 | int status; |
| 4423 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4424 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4425 | status = nfs4_set_lock_state(state, request); |
| 4426 | if (status != 0) |
| 4427 | goto out; |
| 4428 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4429 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4430 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4431 | 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] | 4432 | switch (status) { |
| 4433 | case 0: |
| 4434 | request->fl_type = F_UNLCK; |
| 4435 | break; |
| 4436 | case -NFS4ERR_DENIED: |
| 4437 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4439 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4440 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | return status; |
| 4442 | } |
| 4443 | |
| 4444 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4445 | { |
| 4446 | struct nfs4_exception exception = { }; |
| 4447 | int err; |
| 4448 | |
| 4449 | do { |
| 4450 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4451 | _nfs4_proc_getlk(state, cmd, request), |
| 4452 | &exception); |
| 4453 | } while (exception.retry); |
| 4454 | return err; |
| 4455 | } |
| 4456 | |
| 4457 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4458 | { |
| 4459 | int res = 0; |
| 4460 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4461 | case FL_POSIX: |
| 4462 | res = posix_lock_file_wait(file, fl); |
| 4463 | break; |
| 4464 | case FL_FLOCK: |
| 4465 | res = flock_lock_file_wait(file, fl); |
| 4466 | break; |
| 4467 | default: |
| 4468 | BUG(); |
| 4469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | return res; |
| 4471 | } |
| 4472 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4473 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4474 | struct nfs_locku_args arg; |
| 4475 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4476 | struct nfs4_lock_state *lsp; |
| 4477 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4478 | struct file_lock fl; |
| 4479 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4480 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4481 | }; |
| 4482 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4483 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4484 | struct nfs_open_context *ctx, |
| 4485 | struct nfs4_lock_state *lsp, |
| 4486 | struct nfs_seqid *seqid) |
| 4487 | { |
| 4488 | struct nfs4_unlockdata *p; |
| 4489 | struct inode *inode = lsp->ls_state->inode; |
| 4490 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4491 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4492 | if (p == NULL) |
| 4493 | return NULL; |
| 4494 | p->arg.fh = NFS_FH(inode); |
| 4495 | p->arg.fl = &p->fl; |
| 4496 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4497 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4498 | p->arg.stateid = &lsp->ls_stateid; |
| 4499 | p->lsp = lsp; |
| 4500 | atomic_inc(&lsp->ls_count); |
| 4501 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4502 | p->ctx = get_nfs_open_context(ctx); |
| 4503 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4504 | p->server = NFS_SERVER(inode); |
| 4505 | return p; |
| 4506 | } |
| 4507 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4508 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4509 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4510 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4511 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4512 | nfs4_put_lock_state(calldata->lsp); |
| 4513 | put_nfs_open_context(calldata->ctx); |
| 4514 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4515 | } |
| 4516 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4517 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4518 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4519 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4520 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4521 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4522 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4523 | switch (task->tk_status) { |
| 4524 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4525 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4526 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4527 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4528 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4529 | case -NFS4ERR_BAD_STATEID: |
| 4530 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4531 | case -NFS4ERR_STALE_STATEID: |
| 4532 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4533 | break; |
| 4534 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4535 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4536 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4537 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4538 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4541 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4542 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4543 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4545 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4546 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4547 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4548 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4549 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4550 | return; |
| 4551 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4552 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4553 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4554 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4555 | &calldata->res.seq_res, |
| 4556 | task) != 0) |
| 4557 | nfs_release_seqid(calldata->arg.seqid); |
| 4558 | else |
| 4559 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | } |
| 4561 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4562 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4563 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4564 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4565 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4566 | }; |
| 4567 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4568 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4569 | struct nfs_open_context *ctx, |
| 4570 | struct nfs4_lock_state *lsp, |
| 4571 | struct nfs_seqid *seqid) |
| 4572 | { |
| 4573 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4574 | struct rpc_message msg = { |
| 4575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4576 | .rpc_cred = ctx->cred, |
| 4577 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4578 | struct rpc_task_setup task_setup_data = { |
| 4579 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4580 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4581 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4582 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4583 | .flags = RPC_TASK_ASYNC, |
| 4584 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4585 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4586 | /* Ensure this is an unlock - when canceling a lock, the |
| 4587 | * canceled lock is passed in, and it won't be an unlock. |
| 4588 | */ |
| 4589 | fl->fl_type = F_UNLCK; |
| 4590 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4591 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4592 | if (data == NULL) { |
| 4593 | nfs_free_seqid(seqid); |
| 4594 | return ERR_PTR(-ENOMEM); |
| 4595 | } |
| 4596 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4597 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4598 | msg.rpc_argp = &data->arg; |
| 4599 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4600 | task_setup_data.callback_data = data; |
| 4601 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4602 | } |
| 4603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4604 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4605 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4606 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4607 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4608 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4609 | struct rpc_task *task; |
| 4610 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4611 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4613 | status = nfs4_set_lock_state(state, request); |
| 4614 | /* Unlock _before_ we do the RPC call */ |
| 4615 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4616 | down_read(&nfsi->rwsem); |
| 4617 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4618 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4619 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4620 | } |
| 4621 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4622 | if (status != 0) |
| 4623 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4624 | /* Is this a delegated lock? */ |
| 4625 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4626 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4627 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4628 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4629 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4630 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4631 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4632 | 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] | 4633 | status = PTR_ERR(task); |
| 4634 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4635 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4636 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4637 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4638 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4639 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4640 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4643 | struct nfs4_lockdata { |
| 4644 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4645 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4646 | struct nfs4_lock_state *lsp; |
| 4647 | struct nfs_open_context *ctx; |
| 4648 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4649 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4650 | int rpc_status; |
| 4651 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4652 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4653 | }; |
| 4654 | |
| 4655 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4656 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4657 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4658 | { |
| 4659 | struct nfs4_lockdata *p; |
| 4660 | struct inode *inode = lsp->ls_state->inode; |
| 4661 | struct nfs_server *server = NFS_SERVER(inode); |
| 4662 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4663 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4664 | if (p == NULL) |
| 4665 | return NULL; |
| 4666 | |
| 4667 | p->arg.fh = NFS_FH(inode); |
| 4668 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4669 | 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] | 4670 | if (p->arg.open_seqid == NULL) |
| 4671 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4672 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4673 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4674 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4675 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4676 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4677 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4678 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4679 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4680 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4681 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4682 | atomic_inc(&lsp->ls_count); |
| 4683 | p->ctx = get_nfs_open_context(ctx); |
| 4684 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4685 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4686 | out_free_seqid: |
| 4687 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4688 | out_free: |
| 4689 | kfree(p); |
| 4690 | return NULL; |
| 4691 | } |
| 4692 | |
| 4693 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4694 | { |
| 4695 | struct nfs4_lockdata *data = calldata; |
| 4696 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4698 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4699 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4700 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4701 | /* Do we need to do an open_to_lock_owner? */ |
| 4702 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4703 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4704 | goto out_release_lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4705 | data->arg.open_stateid = &state->stateid; |
| 4706 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4707 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4708 | } else |
| 4709 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4710 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4711 | if (nfs4_setup_sequence(data->server, |
| 4712 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4713 | &data->res.seq_res, |
| 4714 | task) == 0) { |
| 4715 | rpc_call_start(task); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4716 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4717 | } |
| 4718 | nfs_release_seqid(data->arg.open_seqid); |
| 4719 | out_release_lock_seqid: |
| 4720 | nfs_release_seqid(data->arg.lock_seqid); |
| 4721 | dprintk("%s: done!, ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4722 | } |
| 4723 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4724 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4725 | { |
| 4726 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4727 | nfs4_lock_prepare(task, calldata); |
| 4728 | } |
| 4729 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4730 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4731 | { |
| 4732 | struct nfs4_lockdata *data = calldata; |
| 4733 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4734 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4735 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4736 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4737 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4738 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4739 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4740 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4741 | if (data->rpc_status == 0) |
| 4742 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4743 | else |
| 4744 | goto out; |
| 4745 | } |
| 4746 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4747 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4748 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4749 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4750 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4751 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4752 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | static void nfs4_lock_release(void *calldata) |
| 4756 | { |
| 4757 | struct nfs4_lockdata *data = calldata; |
| 4758 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4759 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4760 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4761 | if (data->cancelled != 0) { |
| 4762 | struct rpc_task *task; |
| 4763 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4764 | data->arg.lock_seqid); |
| 4765 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4766 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4767 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4768 | } else |
| 4769 | nfs_free_seqid(data->arg.lock_seqid); |
| 4770 | nfs4_put_lock_state(data->lsp); |
| 4771 | put_nfs_open_context(data->ctx); |
| 4772 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4773 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4777 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4778 | .rpc_call_done = nfs4_lock_done, |
| 4779 | .rpc_release = nfs4_lock_release, |
| 4780 | }; |
| 4781 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4782 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4783 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4784 | .rpc_call_done = nfs4_lock_done, |
| 4785 | .rpc_release = nfs4_lock_release, |
| 4786 | }; |
| 4787 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4788 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4789 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4790 | switch (error) { |
| 4791 | case -NFS4ERR_ADMIN_REVOKED: |
| 4792 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4793 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4794 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4795 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4796 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4797 | break; |
| 4798 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4799 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4800 | case -NFS4ERR_EXPIRED: |
| 4801 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4802 | }; |
| 4803 | } |
| 4804 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4805 | 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] | 4806 | { |
| 4807 | struct nfs4_lockdata *data; |
| 4808 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4809 | struct rpc_message msg = { |
| 4810 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4811 | .rpc_cred = state->owner->so_cred, |
| 4812 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4813 | struct rpc_task_setup task_setup_data = { |
| 4814 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4815 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4816 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4817 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4818 | .flags = RPC_TASK_ASYNC, |
| 4819 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4820 | int ret; |
| 4821 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4822 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4823 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4824 | fl->fl_u.nfs4_fl.owner, |
| 4825 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4826 | if (data == NULL) |
| 4827 | return -ENOMEM; |
| 4828 | if (IS_SETLKW(cmd)) |
| 4829 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4830 | if (recovery_type > NFS_LOCK_NEW) { |
| 4831 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4832 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4833 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4834 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4835 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4836 | msg.rpc_argp = &data->arg; |
| 4837 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4838 | task_setup_data.callback_data = data; |
| 4839 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4840 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4841 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4842 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4843 | if (ret == 0) { |
| 4844 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4845 | if (ret) |
| 4846 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4847 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4848 | } else |
| 4849 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4850 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4851 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4852 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4856 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4857 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4858 | struct nfs4_exception exception = { |
| 4859 | .inode = state->inode, |
| 4860 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4861 | int err; |
| 4862 | |
| 4863 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4864 | /* Cache the lock if possible... */ |
| 4865 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4866 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4867 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4868 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4869 | break; |
| 4870 | nfs4_handle_exception(server, err, &exception); |
| 4871 | } while (exception.retry); |
| 4872 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4876 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4877 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4878 | struct nfs4_exception exception = { |
| 4879 | .inode = state->inode, |
| 4880 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4881 | int err; |
| 4882 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4883 | err = nfs4_set_lock_state(state, request); |
| 4884 | if (err != 0) |
| 4885 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4886 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4887 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4888 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4889 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4890 | switch (err) { |
| 4891 | default: |
| 4892 | goto out; |
| 4893 | case -NFS4ERR_GRACE: |
| 4894 | case -NFS4ERR_DELAY: |
| 4895 | nfs4_handle_exception(server, err, &exception); |
| 4896 | err = 0; |
| 4897 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4898 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4899 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4900 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4903 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4904 | /** |
| 4905 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4906 | * |
| 4907 | * @state: NFSv4 state for an inode |
| 4908 | * |
| 4909 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4910 | * Otherwise a negative NFS4ERR value is returned. |
| 4911 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4912 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4913 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4914 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4915 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4916 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4917 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4918 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4919 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4920 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4921 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4922 | /* Free the stateid unless the server |
| 4923 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4924 | if (status != -NFS4ERR_BAD_STATEID) |
| 4925 | nfs41_free_stateid(server, |
| 4926 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4927 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4928 | ret = status; |
| 4929 | } |
| 4930 | } |
| 4931 | }; |
| 4932 | |
| 4933 | return ret; |
| 4934 | } |
| 4935 | |
| 4936 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4937 | { |
| 4938 | int status = NFS_OK; |
| 4939 | |
| 4940 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4941 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4942 | if (status != NFS_OK) |
| 4943 | status = nfs4_lock_expired(state, request); |
| 4944 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4945 | } |
| 4946 | #endif |
| 4947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4949 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4950 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4951 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4952 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4954 | if ((fl_flags & FL_POSIX) && |
| 4955 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4956 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4957 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4958 | status = nfs4_set_lock_state(state, request); |
| 4959 | if (status != 0) |
| 4960 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4961 | request->fl_flags |= FL_ACCESS; |
| 4962 | status = do_vfs_lock(request->fl_file, request); |
| 4963 | if (status < 0) |
| 4964 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4965 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4966 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4967 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4968 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4969 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4970 | status = do_vfs_lock(request->fl_file, request); |
| 4971 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4972 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4973 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4974 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4975 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4976 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4977 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4978 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4979 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4980 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4981 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4982 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4983 | out: |
| 4984 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | return status; |
| 4986 | } |
| 4987 | |
| 4988 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4989 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4990 | struct nfs4_exception exception = { |
| 4991 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4992 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4993 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | int err; |
| 4995 | |
| 4996 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4997 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4998 | if (err == -NFS4ERR_DENIED) |
| 4999 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5001 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | } while (exception.retry); |
| 5003 | return err; |
| 5004 | } |
| 5005 | |
| 5006 | static int |
| 5007 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5008 | { |
| 5009 | struct nfs_open_context *ctx; |
| 5010 | struct nfs4_state *state; |
| 5011 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5012 | int status; |
| 5013 | |
| 5014 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5015 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | state = ctx->state; |
| 5017 | |
| 5018 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5019 | return -EINVAL; |
| 5020 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5021 | if (IS_GETLK(cmd)) { |
| 5022 | if (state != NULL) |
| 5023 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5024 | return 0; |
| 5025 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | |
| 5027 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5028 | return -EINVAL; |
| 5029 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5030 | if (request->fl_type == F_UNLCK) { |
| 5031 | if (state != NULL) |
| 5032 | return nfs4_proc_unlck(state, cmd, request); |
| 5033 | return 0; |
| 5034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5036 | if (state == NULL) |
| 5037 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5038 | /* |
| 5039 | * Don't rely on the VFS having checked the file open mode, |
| 5040 | * since it won't do this for flock() locks. |
| 5041 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5042 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5043 | case F_RDLCK: |
| 5044 | if (!(filp->f_mode & FMODE_READ)) |
| 5045 | return -EBADF; |
| 5046 | break; |
| 5047 | case F_WRLCK: |
| 5048 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5049 | return -EBADF; |
| 5050 | } |
| 5051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | do { |
| 5053 | status = nfs4_proc_setlk(state, cmd, request); |
| 5054 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5055 | break; |
| 5056 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5057 | status = -ERESTARTSYS; |
| 5058 | if (signalled()) |
| 5059 | break; |
| 5060 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | return status; |
| 5062 | } |
| 5063 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5064 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5065 | { |
| 5066 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5067 | struct nfs4_exception exception = { }; |
| 5068 | int err; |
| 5069 | |
| 5070 | err = nfs4_set_lock_state(state, fl); |
| 5071 | if (err != 0) |
| 5072 | goto out; |
| 5073 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5074 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5075 | switch (err) { |
| 5076 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5077 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5078 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5079 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5080 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5081 | goto out; |
| 5082 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 5083 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5084 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5085 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5086 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5087 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5088 | case -NFS4ERR_BADSESSION: |
| 5089 | case -NFS4ERR_BADSLOT: |
| 5090 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5091 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5092 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5093 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5094 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5095 | case -ERESTARTSYS: |
| 5096 | /* |
| 5097 | * The show must go on: exit, but mark the |
| 5098 | * stateid as needing recovery. |
| 5099 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5100 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5101 | case -NFS4ERR_ADMIN_REVOKED: |
| 5102 | case -NFS4ERR_BAD_STATEID: |
| 5103 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5104 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5105 | err = 0; |
| 5106 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5107 | case -EKEYEXPIRED: |
| 5108 | /* |
| 5109 | * User RPCSEC_GSS context has expired. |
| 5110 | * We cannot recover this stateid now, so |
| 5111 | * skip it and allow recovery thread to |
| 5112 | * proceed. |
| 5113 | */ |
| 5114 | err = 0; |
| 5115 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5116 | case -ENOMEM: |
| 5117 | case -NFS4ERR_DENIED: |
| 5118 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5119 | err = 0; |
| 5120 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5121 | case -NFS4ERR_DELAY: |
| 5122 | break; |
| 5123 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5124 | err = nfs4_handle_exception(server, err, &exception); |
| 5125 | } while (exception.retry); |
| 5126 | out: |
| 5127 | return err; |
| 5128 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5129 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5130 | struct nfs_release_lockowner_data { |
| 5131 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5132 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5133 | struct nfs_release_lockowner_args args; |
| 5134 | }; |
| 5135 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5136 | static void nfs4_release_lockowner_release(void *calldata) |
| 5137 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5138 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5139 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5140 | kfree(calldata); |
| 5141 | } |
| 5142 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5143 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5144 | .rpc_release = nfs4_release_lockowner_release, |
| 5145 | }; |
| 5146 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5147 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5148 | { |
| 5149 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5150 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5151 | struct rpc_message msg = { |
| 5152 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5153 | }; |
| 5154 | |
| 5155 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5156 | return -EINVAL; |
| 5157 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5158 | if (!data) |
| 5159 | return -ENOMEM; |
| 5160 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5161 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5162 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5163 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5164 | data->args.lock_owner.s_dev = server->s_dev; |
| 5165 | msg.rpc_argp = &data->args; |
| 5166 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5167 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5168 | } |
| 5169 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5170 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5171 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5172 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5173 | const void *buf, size_t buflen, |
| 5174 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5175 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5176 | if (strcmp(key, "") != 0) |
| 5177 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5178 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5179 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5180 | } |
| 5181 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5182 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5183 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5184 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5185 | if (strcmp(key, "") != 0) |
| 5186 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5187 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5188 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5191 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5192 | size_t list_len, const char *name, |
| 5193 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5194 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5195 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5196 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5197 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5198 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5199 | |
| 5200 | if (list && len <= list_len) |
| 5201 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5202 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5205 | /* |
| 5206 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5207 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5208 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5209 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5210 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5211 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5212 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5213 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5214 | return; |
| 5215 | |
| 5216 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5217 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5218 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5219 | fattr->nlink = 2; |
| 5220 | } |
| 5221 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5222 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5223 | const struct qstr *name, |
| 5224 | struct nfs4_fs_locations *fs_locations, |
| 5225 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5226 | { |
| 5227 | struct nfs_server *server = NFS_SERVER(dir); |
| 5228 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5229 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5230 | }; |
| 5231 | struct nfs4_fs_locations_arg args = { |
| 5232 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5233 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5234 | .page = page, |
| 5235 | .bitmask = bitmask, |
| 5236 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5237 | struct nfs4_fs_locations_res res = { |
| 5238 | .fs_locations = fs_locations, |
| 5239 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5240 | struct rpc_message msg = { |
| 5241 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5242 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5243 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5244 | }; |
| 5245 | int status; |
| 5246 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5247 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5248 | |
| 5249 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5250 | * is not supported */ |
| 5251 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5252 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5253 | else |
| 5254 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5255 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5256 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5257 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5258 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5259 | 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] | 5260 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5261 | return status; |
| 5262 | } |
| 5263 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5264 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5265 | const struct qstr *name, |
| 5266 | struct nfs4_fs_locations *fs_locations, |
| 5267 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5268 | { |
| 5269 | struct nfs4_exception exception = { }; |
| 5270 | int err; |
| 5271 | do { |
| 5272 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5273 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5274 | &exception); |
| 5275 | } while (exception.retry); |
| 5276 | return err; |
| 5277 | } |
| 5278 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5279 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5280 | { |
| 5281 | int status; |
| 5282 | struct nfs4_secinfo_arg args = { |
| 5283 | .dir_fh = NFS_FH(dir), |
| 5284 | .name = name, |
| 5285 | }; |
| 5286 | struct nfs4_secinfo_res res = { |
| 5287 | .flavors = flavors, |
| 5288 | }; |
| 5289 | struct rpc_message msg = { |
| 5290 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5291 | .rpc_argp = &args, |
| 5292 | .rpc_resp = &res, |
| 5293 | }; |
| 5294 | |
| 5295 | dprintk("NFS call secinfo %s\n", name->name); |
| 5296 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5297 | dprintk("NFS reply secinfo: %d\n", status); |
| 5298 | return status; |
| 5299 | } |
| 5300 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5301 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5302 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5303 | { |
| 5304 | struct nfs4_exception exception = { }; |
| 5305 | int err; |
| 5306 | do { |
| 5307 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5308 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5309 | &exception); |
| 5310 | } while (exception.retry); |
| 5311 | return err; |
| 5312 | } |
| 5313 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5314 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5315 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5316 | * Check the exchange flags returned by the server for invalid flags, having |
| 5317 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5318 | * DS flags set. |
| 5319 | */ |
| 5320 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5321 | { |
| 5322 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5323 | goto out_inval; |
| 5324 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5325 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5326 | goto out_inval; |
| 5327 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5328 | goto out_inval; |
| 5329 | return NFS_OK; |
| 5330 | out_inval: |
| 5331 | return -NFS4ERR_INVAL; |
| 5332 | } |
| 5333 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5334 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5335 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5336 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5337 | { |
| 5338 | if (a->server_scope_sz == b->server_scope_sz && |
| 5339 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5340 | return true; |
| 5341 | |
| 5342 | return false; |
| 5343 | } |
| 5344 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5345 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5346 | * nfs4_proc_bind_conn_to_session() |
| 5347 | * |
| 5348 | * The 4.1 client currently uses the same TCP connection for the |
| 5349 | * fore and backchannel. |
| 5350 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5351 | 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] | 5352 | { |
| 5353 | int status; |
| 5354 | struct nfs41_bind_conn_to_session_res res; |
| 5355 | struct rpc_message msg = { |
| 5356 | .rpc_proc = |
| 5357 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5358 | .rpc_argp = clp, |
| 5359 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5360 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5361 | }; |
| 5362 | |
| 5363 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5364 | |
| 5365 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5366 | if (unlikely(res.session == NULL)) { |
| 5367 | status = -ENOMEM; |
| 5368 | goto out; |
| 5369 | } |
| 5370 | |
| 5371 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5372 | if (status == 0) { |
| 5373 | if (memcmp(res.session->sess_id.data, |
| 5374 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5375 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5376 | status = -EIO; |
| 5377 | goto out_session; |
| 5378 | } |
| 5379 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5380 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5381 | __func__); |
| 5382 | status = -EIO; |
| 5383 | goto out_session; |
| 5384 | } |
| 5385 | if (res.use_conn_in_rdma_mode) { |
| 5386 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5387 | __func__); |
| 5388 | status = -EIO; |
| 5389 | goto out_session; |
| 5390 | } |
| 5391 | } |
| 5392 | out_session: |
| 5393 | kfree(res.session); |
| 5394 | out: |
| 5395 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5396 | return status; |
| 5397 | } |
| 5398 | |
| 5399 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5400 | * nfs4_proc_exchange_id() |
| 5401 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5402 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5403 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5404 | * Since the clientid has expired, all compounds using sessions |
| 5405 | * associated with the stale clientid will be returning |
| 5406 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5407 | * be in some phase of session reset. |
| 5408 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5409 | 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] | 5410 | { |
| 5411 | nfs4_verifier verifier; |
| 5412 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5413 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5414 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5415 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5416 | }; |
| 5417 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5418 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5419 | }; |
| 5420 | int status; |
| 5421 | struct rpc_message msg = { |
| 5422 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5423 | .rpc_argp = &args, |
| 5424 | .rpc_resp = &res, |
| 5425 | .rpc_cred = cred, |
| 5426 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5427 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5428 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5429 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5430 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5431 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5432 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5433 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5434 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5435 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5436 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5437 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5438 | status = -ENOMEM; |
| 5439 | goto out; |
| 5440 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5441 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5442 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5443 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5444 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5445 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5446 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5447 | } |
| 5448 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5449 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5450 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5451 | status = -ENOMEM; |
| 5452 | goto out_server_scope; |
| 5453 | } |
| 5454 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5455 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5456 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5457 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5458 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5459 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5460 | clp->cl_clientid = res.clientid; |
| 5461 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5462 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5463 | clp->cl_seqid = res.seqid; |
| 5464 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5465 | kfree(clp->cl_serverowner); |
| 5466 | clp->cl_serverowner = res.server_owner; |
| 5467 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5468 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5469 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5470 | kfree(clp->cl_implid); |
| 5471 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5472 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5473 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5474 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5475 | res.server_scope)) { |
| 5476 | dprintk("%s: server_scope mismatch detected\n", |
| 5477 | __func__); |
| 5478 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5479 | kfree(clp->cl_serverscope); |
| 5480 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5481 | } |
| 5482 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5483 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5484 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5485 | goto out; |
| 5486 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5487 | } else |
| 5488 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5489 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5490 | out_server_owner: |
| 5491 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5492 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5493 | kfree(res.server_scope); |
| 5494 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5495 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5496 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5497 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5498 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5499 | clp->cl_implid->date.seconds, |
| 5500 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5501 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5502 | return status; |
| 5503 | } |
| 5504 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5505 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5506 | struct rpc_cred *cred) |
| 5507 | { |
| 5508 | struct rpc_message msg = { |
| 5509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5510 | .rpc_argp = clp, |
| 5511 | .rpc_cred = cred, |
| 5512 | }; |
| 5513 | int status; |
| 5514 | |
| 5515 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5516 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5517 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5518 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5519 | return status; |
| 5520 | } |
| 5521 | |
| 5522 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5523 | struct rpc_cred *cred) |
| 5524 | { |
| 5525 | unsigned int loop; |
| 5526 | int ret; |
| 5527 | |
| 5528 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5529 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5530 | switch (ret) { |
| 5531 | case -NFS4ERR_DELAY: |
| 5532 | case -NFS4ERR_CLIENTID_BUSY: |
| 5533 | ssleep(1); |
| 5534 | break; |
| 5535 | default: |
| 5536 | return ret; |
| 5537 | } |
| 5538 | } |
| 5539 | return 0; |
| 5540 | } |
| 5541 | |
| 5542 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5543 | { |
| 5544 | struct rpc_cred *cred; |
| 5545 | int ret = 0; |
| 5546 | |
| 5547 | if (clp->cl_mvops->minor_version < 1) |
| 5548 | goto out; |
| 5549 | if (clp->cl_exchange_flags == 0) |
| 5550 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5551 | if (clp->cl_preserve_clid) |
| 5552 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5553 | cred = nfs4_get_exchange_id_cred(clp); |
| 5554 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5555 | if (cred) |
| 5556 | put_rpccred(cred); |
| 5557 | switch (ret) { |
| 5558 | case 0: |
| 5559 | case -NFS4ERR_STALE_CLIENTID: |
| 5560 | clp->cl_exchange_flags = 0; |
| 5561 | } |
| 5562 | out: |
| 5563 | return ret; |
| 5564 | } |
| 5565 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5566 | struct nfs4_get_lease_time_data { |
| 5567 | struct nfs4_get_lease_time_args *args; |
| 5568 | struct nfs4_get_lease_time_res *res; |
| 5569 | struct nfs_client *clp; |
| 5570 | }; |
| 5571 | |
| 5572 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5573 | void *calldata) |
| 5574 | { |
| 5575 | int ret; |
| 5576 | struct nfs4_get_lease_time_data *data = |
| 5577 | (struct nfs4_get_lease_time_data *)calldata; |
| 5578 | |
| 5579 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5580 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5581 | /* just setup sequence, do not trigger session recovery |
| 5582 | since we're invoked within one */ |
| 5583 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5584 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5585 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5586 | |
Trond Myklebust | d3edcf9 | 2012-10-15 13:14:43 -0400 | [diff] [blame] | 5587 | if (ret != -EAGAIN) |
| 5588 | rpc_call_start(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5589 | dprintk("<-- %s\n", __func__); |
| 5590 | } |
| 5591 | |
| 5592 | /* |
| 5593 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5594 | * from sequence operation or clientid errors. |
| 5595 | */ |
| 5596 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5597 | { |
| 5598 | struct nfs4_get_lease_time_data *data = |
| 5599 | (struct nfs4_get_lease_time_data *)calldata; |
| 5600 | |
| 5601 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5602 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5603 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5604 | switch (task->tk_status) { |
| 5605 | case -NFS4ERR_DELAY: |
| 5606 | case -NFS4ERR_GRACE: |
| 5607 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5608 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5609 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5610 | /* fall through */ |
| 5611 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5612 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5613 | return; |
| 5614 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5615 | dprintk("<-- %s\n", __func__); |
| 5616 | } |
| 5617 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5618 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5619 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5620 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5621 | }; |
| 5622 | |
| 5623 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5624 | { |
| 5625 | struct rpc_task *task; |
| 5626 | struct nfs4_get_lease_time_args args; |
| 5627 | struct nfs4_get_lease_time_res res = { |
| 5628 | .lr_fsinfo = fsinfo, |
| 5629 | }; |
| 5630 | struct nfs4_get_lease_time_data data = { |
| 5631 | .args = &args, |
| 5632 | .res = &res, |
| 5633 | .clp = clp, |
| 5634 | }; |
| 5635 | struct rpc_message msg = { |
| 5636 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5637 | .rpc_argp = &args, |
| 5638 | .rpc_resp = &res, |
| 5639 | }; |
| 5640 | struct rpc_task_setup task_setup = { |
| 5641 | .rpc_client = clp->cl_rpcclient, |
| 5642 | .rpc_message = &msg, |
| 5643 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5644 | .callback_data = &data, |
| 5645 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5646 | }; |
| 5647 | int status; |
| 5648 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5649 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5650 | dprintk("--> %s\n", __func__); |
| 5651 | task = rpc_run_task(&task_setup); |
| 5652 | |
| 5653 | if (IS_ERR(task)) |
| 5654 | status = PTR_ERR(task); |
| 5655 | else { |
| 5656 | status = task->tk_status; |
| 5657 | rpc_put_task(task); |
| 5658 | } |
| 5659 | dprintk("<-- %s return %d\n", __func__, status); |
| 5660 | |
| 5661 | return status; |
| 5662 | } |
| 5663 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 5664 | struct nfs4_slot *nfs4_alloc_slots(struct nfs4_slot_table *table, |
| 5665 | u32 max_slots, gfp_t gfp_flags) |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5666 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 5667 | struct nfs4_slot *tbl; |
| 5668 | u32 i; |
| 5669 | |
| 5670 | tbl = kmalloc_array(max_slots, sizeof(*tbl), gfp_flags); |
| 5671 | if (tbl != NULL) { |
| 5672 | for (i = 0; i < max_slots; i++) |
| 5673 | tbl[i].table = table; |
| 5674 | } |
| 5675 | return tbl; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5679 | struct nfs4_slot *new, |
| 5680 | u32 max_slots, |
| 5681 | u32 ivalue) |
| 5682 | { |
| 5683 | struct nfs4_slot *old = NULL; |
| 5684 | u32 i; |
| 5685 | |
| 5686 | spin_lock(&tbl->slot_tbl_lock); |
| 5687 | if (new) { |
| 5688 | old = tbl->slots; |
| 5689 | tbl->slots = new; |
| 5690 | tbl->max_slots = max_slots; |
| 5691 | } |
Trond Myklebust | f9b1ef5 | 2012-10-29 16:48:40 -0400 | [diff] [blame] | 5692 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5693 | for (i = 0; i < tbl->max_slots; i++) |
| 5694 | tbl->slots[i].seq_nr = ivalue; |
| 5695 | spin_unlock(&tbl->slot_tbl_lock); |
| 5696 | kfree(old); |
| 5697 | } |
| 5698 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5699 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5700 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5701 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5702 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5703 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5704 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5705 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5706 | int ret = -ENOMEM; |
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 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5709 | max_reqs, tbl->max_slots); |
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 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5712 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 5713 | new = nfs4_alloc_slots(tbl, max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5714 | if (!new) |
| 5715 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5716 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5717 | ret = 0; |
| 5718 | |
| 5719 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5720 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5721 | tbl, tbl->slots, tbl->max_slots); |
| 5722 | out: |
| 5723 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5724 | return ret; |
| 5725 | } |
| 5726 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5727 | /* Destroy the slot table */ |
| 5728 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5729 | { |
| 5730 | if (session->fc_slot_table.slots != NULL) { |
| 5731 | kfree(session->fc_slot_table.slots); |
| 5732 | session->fc_slot_table.slots = NULL; |
| 5733 | } |
| 5734 | if (session->bc_slot_table.slots != NULL) { |
| 5735 | kfree(session->bc_slot_table.slots); |
| 5736 | session->bc_slot_table.slots = NULL; |
| 5737 | } |
| 5738 | return; |
| 5739 | } |
| 5740 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5741 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5742 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5743 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5744 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5745 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5746 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5747 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5748 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5749 | dprintk("--> %s\n", __func__); |
| 5750 | /* Fore channel */ |
| 5751 | tbl = &ses->fc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 5752 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5753 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5754 | if (status) /* -ENOMEM */ |
| 5755 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5756 | /* Back channel */ |
| 5757 | tbl = &ses->bc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame^] | 5758 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5759 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5760 | if (status && tbl->slots == NULL) |
| 5761 | /* Fore and back channel share a connection so get |
| 5762 | * both slot tables or neither */ |
| 5763 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5764 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5768 | { |
| 5769 | struct nfs4_session *session; |
| 5770 | struct nfs4_slot_table *tbl; |
| 5771 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5772 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5773 | if (!session) |
| 5774 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5775 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5776 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5777 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5778 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5779 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5780 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5781 | |
| 5782 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5783 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5784 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5785 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5786 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5787 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5788 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5789 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5790 | session->clp = clp; |
| 5791 | return session; |
| 5792 | } |
| 5793 | |
| 5794 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5795 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5796 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5797 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5798 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5799 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5800 | nfs4_proc_destroy_session(session, cred); |
| 5801 | if (cred) |
| 5802 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5803 | |
| 5804 | rcu_read_lock(); |
| 5805 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5806 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5807 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5808 | __func__, xprt); |
| 5809 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5810 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5811 | kfree(session); |
| 5812 | } |
| 5813 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5814 | /* |
| 5815 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5816 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5817 | * use them. |
| 5818 | * |
| 5819 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5820 | * always set csa_cachethis to FALSE because the current implementation |
| 5821 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5822 | */ |
| 5823 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5824 | { |
| 5825 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5826 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5827 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5828 | |
| 5829 | if (mxrqst_sz == 0) |
| 5830 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5831 | if (mxresp_sz == 0) |
| 5832 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5833 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5834 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5835 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5836 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5837 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5838 | |
| 5839 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5840 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5841 | __func__, |
| 5842 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5843 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5844 | |
| 5845 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5846 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5847 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5848 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5849 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5850 | args->bc_attrs.max_reqs = 1; |
| 5851 | |
| 5852 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5853 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5854 | __func__, |
| 5855 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5856 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5857 | args->bc_attrs.max_reqs); |
| 5858 | } |
| 5859 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5860 | 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] | 5861 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5862 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5863 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5864 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5865 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5866 | return -EINVAL; |
| 5867 | /* |
| 5868 | * Our requested max_ops is the minimum we need; we're not |
| 5869 | * prepared to break up compounds into smaller pieces than that. |
| 5870 | * So, no point even trying to continue if the server won't |
| 5871 | * cooperate: |
| 5872 | */ |
| 5873 | if (rcvd->max_ops < sent->max_ops) |
| 5874 | return -EINVAL; |
| 5875 | if (rcvd->max_reqs == 0) |
| 5876 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5877 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5878 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5879 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5880 | } |
| 5881 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5882 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5883 | { |
| 5884 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5885 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5886 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5887 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5888 | return -EINVAL; |
| 5889 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5890 | return -EINVAL; |
| 5891 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5892 | return -EINVAL; |
| 5893 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5894 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5895 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5896 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5897 | return -EINVAL; |
| 5898 | return 0; |
| 5899 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5900 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5901 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5902 | struct nfs4_session *session) |
| 5903 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5904 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5905 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5906 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5907 | if (ret) |
| 5908 | return ret; |
| 5909 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5910 | } |
| 5911 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5912 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5913 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5914 | { |
| 5915 | struct nfs4_session *session = clp->cl_session; |
| 5916 | struct nfs41_create_session_args args = { |
| 5917 | .client = clp, |
| 5918 | .cb_program = NFS4_CALLBACK, |
| 5919 | }; |
| 5920 | struct nfs41_create_session_res res = { |
| 5921 | .client = clp, |
| 5922 | }; |
| 5923 | struct rpc_message msg = { |
| 5924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5925 | .rpc_argp = &args, |
| 5926 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5927 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5928 | }; |
| 5929 | int status; |
| 5930 | |
| 5931 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5932 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5933 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5934 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5935 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5936 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5937 | /* Verify the session's negotiated channel_attrs values */ |
| 5938 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5939 | /* Increment the clientid slot sequence id */ |
| 5940 | clp->cl_seqid++; |
| 5941 | } |
| 5942 | |
| 5943 | return status; |
| 5944 | } |
| 5945 | |
| 5946 | /* |
| 5947 | * Issues a CREATE_SESSION operation to the server. |
| 5948 | * It is the responsibility of the caller to verify the session is |
| 5949 | * expired before calling this routine. |
| 5950 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5951 | 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] | 5952 | { |
| 5953 | int status; |
| 5954 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5955 | struct nfs4_session *session = clp->cl_session; |
| 5956 | |
| 5957 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5958 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5959 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5960 | if (status) |
| 5961 | goto out; |
| 5962 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5963 | /* Init or reset the session slot tables */ |
| 5964 | status = nfs4_setup_session_slot_tables(session); |
| 5965 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5966 | if (status) |
| 5967 | goto out; |
| 5968 | |
| 5969 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5970 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5971 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5972 | out: |
| 5973 | dprintk("<-- %s\n", __func__); |
| 5974 | return status; |
| 5975 | } |
| 5976 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5977 | /* |
| 5978 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5979 | * The caller must serialize access to this routine. |
| 5980 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5981 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5982 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5983 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5984 | struct rpc_message msg = { |
| 5985 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5986 | .rpc_argp = session, |
| 5987 | .rpc_cred = cred, |
| 5988 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5989 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5990 | |
| 5991 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5992 | |
| 5993 | /* session is still being setup */ |
| 5994 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5995 | return status; |
| 5996 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5997 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5998 | |
| 5999 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6000 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6001 | "Session has been destroyed regardless...\n", status); |
| 6002 | |
| 6003 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6004 | return status; |
| 6005 | } |
| 6006 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6007 | /* |
| 6008 | * With sessions, the client is not marked ready until after a |
| 6009 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 6010 | * |
| 6011 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 6012 | * other versions of NFS can be tried. |
| 6013 | */ |
| 6014 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 6015 | { |
| 6016 | int ret; |
| 6017 | |
| 6018 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 6019 | ret = nfs4_client_recover_expired_lease(clp); |
| 6020 | if (ret) |
| 6021 | return ret; |
| 6022 | } |
| 6023 | if (clp->cl_cons_state < NFS_CS_READY) |
| 6024 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 6025 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6026 | return 0; |
| 6027 | } |
| 6028 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6029 | int nfs4_init_session(struct nfs_server *server) |
| 6030 | { |
| 6031 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6032 | struct nfs4_session *session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6033 | unsigned int target_max_rqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 6034 | unsigned int target_max_resp_sz = NFS_MAX_FILE_IO_SIZE; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6035 | |
| 6036 | if (!nfs4_has_session(clp)) |
| 6037 | return 0; |
| 6038 | |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6039 | if (server->rsize != 0) |
| 6040 | target_max_resp_sz = server->rsize; |
| 6041 | target_max_resp_sz += nfs41_maxread_overhead; |
| 6042 | |
| 6043 | if (server->wsize != 0) |
| 6044 | target_max_rqst_sz = server->wsize; |
| 6045 | target_max_rqst_sz += nfs41_maxwrite_overhead; |
| 6046 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6047 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6048 | spin_lock(&clp->cl_lock); |
| 6049 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6050 | /* Initialise targets and channel attributes */ |
| 6051 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6052 | session->fc_attrs.max_rqst_sz = target_max_rqst_sz; |
| 6053 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6054 | session->fc_attrs.max_resp_sz = target_max_resp_sz; |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6055 | } else { |
| 6056 | /* Just adjust the targets */ |
| 6057 | if (target_max_rqst_sz > session->fc_target_max_rqst_sz) { |
| 6058 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6059 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6060 | } |
| 6061 | if (target_max_resp_sz > session->fc_target_max_resp_sz) { |
| 6062 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6063 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6064 | } |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6065 | } |
| 6066 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6067 | |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6068 | if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)) |
| 6069 | nfs4_schedule_lease_recovery(clp); |
| 6070 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6071 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6072 | } |
| 6073 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6074 | 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] | 6075 | { |
| 6076 | struct nfs4_session *session = clp->cl_session; |
| 6077 | int ret; |
| 6078 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6079 | spin_lock(&clp->cl_lock); |
| 6080 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 6081 | /* |
| 6082 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 6083 | * DS lease to be equal to the MDS lease. |
| 6084 | */ |
| 6085 | clp->cl_lease_time = lease_time; |
| 6086 | clp->cl_last_renewal = jiffies; |
| 6087 | } |
| 6088 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6089 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6090 | ret = nfs41_check_session_ready(clp); |
| 6091 | if (ret) |
| 6092 | return ret; |
| 6093 | /* Test for the DS role */ |
| 6094 | if (!is_ds_client(clp)) |
| 6095 | return -ENODEV; |
| 6096 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6097 | } |
| 6098 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 6099 | |
| 6100 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6101 | /* |
| 6102 | * Renew the cl_session lease. |
| 6103 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6104 | struct nfs4_sequence_data { |
| 6105 | struct nfs_client *clp; |
| 6106 | struct nfs4_sequence_args args; |
| 6107 | struct nfs4_sequence_res res; |
| 6108 | }; |
| 6109 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6110 | static void nfs41_sequence_release(void *data) |
| 6111 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6112 | struct nfs4_sequence_data *calldata = data; |
| 6113 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6114 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6115 | if (atomic_read(&clp->cl_count) > 1) |
| 6116 | nfs4_schedule_state_renewal(clp); |
| 6117 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6118 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6119 | } |
| 6120 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6121 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6122 | { |
| 6123 | switch(task->tk_status) { |
| 6124 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6125 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6126 | return -EAGAIN; |
| 6127 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6128 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6129 | } |
| 6130 | return 0; |
| 6131 | } |
| 6132 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6133 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6134 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6135 | struct nfs4_sequence_data *calldata = data; |
| 6136 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6137 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6138 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6139 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6140 | |
| 6141 | if (task->tk_status < 0) { |
| 6142 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6143 | if (atomic_read(&clp->cl_count) == 1) |
| 6144 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6145 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6146 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6147 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6148 | return; |
| 6149 | } |
| 6150 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6151 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6152 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6153 | dprintk("<-- %s\n", __func__); |
| 6154 | } |
| 6155 | |
| 6156 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6157 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6158 | struct nfs4_sequence_data *calldata = data; |
| 6159 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6160 | struct nfs4_sequence_args *args; |
| 6161 | struct nfs4_sequence_res *res; |
| 6162 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6163 | args = task->tk_msg.rpc_argp; |
| 6164 | res = task->tk_msg.rpc_resp; |
| 6165 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6166 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6167 | return; |
| 6168 | rpc_call_start(task); |
| 6169 | } |
| 6170 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6171 | static void nfs41_sequence_prepare_privileged(struct rpc_task *task, void *data) |
| 6172 | { |
| 6173 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 6174 | nfs41_sequence_prepare(task, data); |
| 6175 | } |
| 6176 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6177 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6178 | .rpc_call_done = nfs41_sequence_call_done, |
| 6179 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6180 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6181 | }; |
| 6182 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6183 | static const struct rpc_call_ops nfs41_sequence_privileged_ops = { |
| 6184 | .rpc_call_done = nfs41_sequence_call_done, |
| 6185 | .rpc_call_prepare = nfs41_sequence_prepare_privileged, |
| 6186 | .rpc_release = nfs41_sequence_release, |
| 6187 | }; |
| 6188 | |
| 6189 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred, |
| 6190 | const struct rpc_call_ops *seq_ops) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6191 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6192 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6193 | struct rpc_message msg = { |
| 6194 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6195 | .rpc_cred = cred, |
| 6196 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6197 | struct rpc_task_setup task_setup_data = { |
| 6198 | .rpc_client = clp->cl_rpcclient, |
| 6199 | .rpc_message = &msg, |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6200 | .callback_ops = seq_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6201 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6202 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6203 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6204 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6205 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6206 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6207 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6208 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6209 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6210 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6211 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6212 | msg.rpc_argp = &calldata->args; |
| 6213 | msg.rpc_resp = &calldata->res; |
| 6214 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6215 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6216 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6217 | return rpc_run_task(&task_setup_data); |
| 6218 | } |
| 6219 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6220 | 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] | 6221 | { |
| 6222 | struct rpc_task *task; |
| 6223 | int ret = 0; |
| 6224 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6225 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6226 | return 0; |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6227 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6228 | if (IS_ERR(task)) |
| 6229 | ret = PTR_ERR(task); |
| 6230 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6231 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6232 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6233 | return ret; |
| 6234 | } |
| 6235 | |
| 6236 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6237 | { |
| 6238 | struct rpc_task *task; |
| 6239 | int ret; |
| 6240 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6241 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_privileged_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6242 | if (IS_ERR(task)) { |
| 6243 | ret = PTR_ERR(task); |
| 6244 | goto out; |
| 6245 | } |
| 6246 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6247 | if (!ret) { |
| 6248 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6249 | |
| 6250 | if (task->tk_status == 0) |
| 6251 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6252 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6253 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6254 | rpc_put_task(task); |
| 6255 | out: |
| 6256 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6257 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6258 | } |
| 6259 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6260 | struct nfs4_reclaim_complete_data { |
| 6261 | struct nfs_client *clp; |
| 6262 | struct nfs41_reclaim_complete_args arg; |
| 6263 | struct nfs41_reclaim_complete_res res; |
| 6264 | }; |
| 6265 | |
| 6266 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6267 | { |
| 6268 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6269 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6270 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6271 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6272 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6273 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6274 | return; |
| 6275 | |
| 6276 | rpc_call_start(task); |
| 6277 | } |
| 6278 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6279 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6280 | { |
| 6281 | switch(task->tk_status) { |
| 6282 | case 0: |
| 6283 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6284 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6285 | break; |
| 6286 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6287 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6288 | /* fall through */ |
| 6289 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6290 | return -EAGAIN; |
| 6291 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6292 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6293 | } |
| 6294 | return 0; |
| 6295 | } |
| 6296 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6297 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6298 | { |
| 6299 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6300 | struct nfs_client *clp = calldata->clp; |
| 6301 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6302 | |
| 6303 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6304 | if (!nfs41_sequence_done(task, res)) |
| 6305 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6306 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6307 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6308 | rpc_restart_call_prepare(task); |
| 6309 | return; |
| 6310 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6311 | dprintk("<-- %s\n", __func__); |
| 6312 | } |
| 6313 | |
| 6314 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6315 | { |
| 6316 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6317 | |
| 6318 | kfree(calldata); |
| 6319 | } |
| 6320 | |
| 6321 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6322 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6323 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6324 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6325 | }; |
| 6326 | |
| 6327 | /* |
| 6328 | * Issue a global reclaim complete. |
| 6329 | */ |
| 6330 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6331 | { |
| 6332 | struct nfs4_reclaim_complete_data *calldata; |
| 6333 | struct rpc_task *task; |
| 6334 | struct rpc_message msg = { |
| 6335 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6336 | }; |
| 6337 | struct rpc_task_setup task_setup_data = { |
| 6338 | .rpc_client = clp->cl_rpcclient, |
| 6339 | .rpc_message = &msg, |
| 6340 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6341 | .flags = RPC_TASK_ASYNC, |
| 6342 | }; |
| 6343 | int status = -ENOMEM; |
| 6344 | |
| 6345 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6346 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6347 | if (calldata == NULL) |
| 6348 | goto out; |
| 6349 | calldata->clp = clp; |
| 6350 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6351 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6352 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6353 | msg.rpc_argp = &calldata->arg; |
| 6354 | msg.rpc_resp = &calldata->res; |
| 6355 | task_setup_data.callback_data = calldata; |
| 6356 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6357 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6358 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6359 | goto out; |
| 6360 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6361 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6362 | if (status == 0) |
| 6363 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6364 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6365 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6366 | out: |
| 6367 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6368 | return status; |
| 6369 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6370 | |
| 6371 | static void |
| 6372 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6373 | { |
| 6374 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6375 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6376 | |
| 6377 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6378 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6379 | * right now covering the LAYOUTGET we are about to send. |
| 6380 | * However, that is not so catastrophic, and there seems |
| 6381 | * to be no way to prevent it completely. |
| 6382 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6383 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6384 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6385 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6386 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6387 | NFS_I(lgp->args.inode)->layout, |
| 6388 | lgp->args.ctx->state)) { |
| 6389 | rpc_exit(task, NFS4_OK); |
| 6390 | return; |
| 6391 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6392 | rpc_call_start(task); |
| 6393 | } |
| 6394 | |
| 6395 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6396 | { |
| 6397 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6398 | struct inode *inode = lgp->args.inode; |
| 6399 | struct nfs_server *server = NFS_SERVER(inode); |
| 6400 | struct pnfs_layout_hdr *lo; |
| 6401 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6402 | |
| 6403 | dprintk("--> %s\n", __func__); |
| 6404 | |
| 6405 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6406 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6407 | |
| 6408 | switch (task->tk_status) { |
| 6409 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6410 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6411 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6412 | case -NFS4ERR_RECALLCONFLICT: |
| 6413 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6414 | break; |
| 6415 | case -NFS4ERR_EXPIRED: |
| 6416 | case -NFS4ERR_BAD_STATEID: |
| 6417 | spin_lock(&inode->i_lock); |
| 6418 | lo = NFS_I(inode)->layout; |
| 6419 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6420 | spin_unlock(&inode->i_lock); |
| 6421 | /* If the open stateid was bad, then recover it. */ |
| 6422 | state = lgp->args.ctx->state; |
| 6423 | } else { |
| 6424 | LIST_HEAD(head); |
| 6425 | |
| 6426 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6427 | spin_unlock(&inode->i_lock); |
| 6428 | /* Mark the bad layout state as invalid, then |
| 6429 | * retry using the open stateid. */ |
| 6430 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6431 | } |
| 6432 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6433 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6434 | rpc_restart_call_prepare(task); |
| 6435 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6436 | dprintk("<-- %s\n", __func__); |
| 6437 | } |
| 6438 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6439 | static size_t max_response_pages(struct nfs_server *server) |
| 6440 | { |
| 6441 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6442 | return nfs_page_array_len(0, max_resp_sz); |
| 6443 | } |
| 6444 | |
| 6445 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6446 | { |
| 6447 | int i; |
| 6448 | |
| 6449 | if (!pages) |
| 6450 | return; |
| 6451 | |
| 6452 | for (i = 0; i < size; i++) { |
| 6453 | if (!pages[i]) |
| 6454 | break; |
| 6455 | __free_page(pages[i]); |
| 6456 | } |
| 6457 | kfree(pages); |
| 6458 | } |
| 6459 | |
| 6460 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6461 | { |
| 6462 | struct page **pages; |
| 6463 | int i; |
| 6464 | |
| 6465 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6466 | if (!pages) { |
| 6467 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6468 | return NULL; |
| 6469 | } |
| 6470 | |
| 6471 | for (i = 0; i < size; i++) { |
| 6472 | pages[i] = alloc_page(gfp_flags); |
| 6473 | if (!pages[i]) { |
| 6474 | dprintk("%s: failed to allocate page\n", __func__); |
| 6475 | nfs4_free_pages(pages, size); |
| 6476 | return NULL; |
| 6477 | } |
| 6478 | } |
| 6479 | |
| 6480 | return pages; |
| 6481 | } |
| 6482 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6483 | static void nfs4_layoutget_release(void *calldata) |
| 6484 | { |
| 6485 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6486 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6487 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6488 | |
| 6489 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6490 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6491 | put_nfs_open_context(lgp->args.ctx); |
| 6492 | kfree(calldata); |
| 6493 | dprintk("<-- %s\n", __func__); |
| 6494 | } |
| 6495 | |
| 6496 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6497 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6498 | .rpc_call_done = nfs4_layoutget_done, |
| 6499 | .rpc_release = nfs4_layoutget_release, |
| 6500 | }; |
| 6501 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6502 | struct pnfs_layout_segment * |
| 6503 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6504 | { |
| 6505 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6506 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6507 | struct rpc_task *task; |
| 6508 | struct rpc_message msg = { |
| 6509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6510 | .rpc_argp = &lgp->args, |
| 6511 | .rpc_resp = &lgp->res, |
| 6512 | }; |
| 6513 | struct rpc_task_setup task_setup_data = { |
| 6514 | .rpc_client = server->client, |
| 6515 | .rpc_message = &msg, |
| 6516 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6517 | .callback_data = lgp, |
| 6518 | .flags = RPC_TASK_ASYNC, |
| 6519 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6520 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6521 | int status = 0; |
| 6522 | |
| 6523 | dprintk("--> %s\n", __func__); |
| 6524 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6525 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6526 | if (!lgp->args.layout.pages) { |
| 6527 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6528 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6529 | } |
| 6530 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6531 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6532 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6533 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6534 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6535 | task = rpc_run_task(&task_setup_data); |
| 6536 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6537 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6538 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6539 | if (status == 0) |
| 6540 | status = task->tk_status; |
| 6541 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6542 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6543 | rpc_put_task(task); |
| 6544 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6545 | if (status) |
| 6546 | return ERR_PTR(status); |
| 6547 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6548 | } |
| 6549 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6550 | static void |
| 6551 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6552 | { |
| 6553 | struct nfs4_layoutreturn *lrp = calldata; |
| 6554 | |
| 6555 | dprintk("--> %s\n", __func__); |
| 6556 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6557 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6558 | return; |
| 6559 | rpc_call_start(task); |
| 6560 | } |
| 6561 | |
| 6562 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6563 | { |
| 6564 | struct nfs4_layoutreturn *lrp = calldata; |
| 6565 | struct nfs_server *server; |
| 6566 | |
| 6567 | dprintk("--> %s\n", __func__); |
| 6568 | |
| 6569 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6570 | return; |
| 6571 | |
| 6572 | server = NFS_SERVER(lrp->args.inode); |
| 6573 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6574 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6575 | return; |
| 6576 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6577 | dprintk("<-- %s\n", __func__); |
| 6578 | } |
| 6579 | |
| 6580 | static void nfs4_layoutreturn_release(void *calldata) |
| 6581 | { |
| 6582 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6583 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6584 | |
| 6585 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6586 | spin_lock(&lo->plh_inode->i_lock); |
| 6587 | if (lrp->res.lrs_present) |
| 6588 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6589 | lo->plh_block_lgets--; |
| 6590 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6591 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6592 | kfree(calldata); |
| 6593 | dprintk("<-- %s\n", __func__); |
| 6594 | } |
| 6595 | |
| 6596 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6597 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6598 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6599 | .rpc_release = nfs4_layoutreturn_release, |
| 6600 | }; |
| 6601 | |
| 6602 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6603 | { |
| 6604 | struct rpc_task *task; |
| 6605 | struct rpc_message msg = { |
| 6606 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6607 | .rpc_argp = &lrp->args, |
| 6608 | .rpc_resp = &lrp->res, |
| 6609 | }; |
| 6610 | struct rpc_task_setup task_setup_data = { |
| 6611 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6612 | .rpc_message = &msg, |
| 6613 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6614 | .callback_data = lrp, |
| 6615 | }; |
| 6616 | int status; |
| 6617 | |
| 6618 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6619 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6620 | task = rpc_run_task(&task_setup_data); |
| 6621 | if (IS_ERR(task)) |
| 6622 | return PTR_ERR(task); |
| 6623 | status = task->tk_status; |
| 6624 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6625 | rpc_put_task(task); |
| 6626 | return status; |
| 6627 | } |
| 6628 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6629 | /* |
| 6630 | * Retrieve the list of Data Server devices from the MDS. |
| 6631 | */ |
| 6632 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6633 | const struct nfs_fh *fh, |
| 6634 | struct pnfs_devicelist *devlist) |
| 6635 | { |
| 6636 | struct nfs4_getdevicelist_args args = { |
| 6637 | .fh = fh, |
| 6638 | .layoutclass = server->pnfs_curr_ld->id, |
| 6639 | }; |
| 6640 | struct nfs4_getdevicelist_res res = { |
| 6641 | .devlist = devlist, |
| 6642 | }; |
| 6643 | struct rpc_message msg = { |
| 6644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6645 | .rpc_argp = &args, |
| 6646 | .rpc_resp = &res, |
| 6647 | }; |
| 6648 | int status; |
| 6649 | |
| 6650 | dprintk("--> %s\n", __func__); |
| 6651 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6652 | &res.seq_res, 0); |
| 6653 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6654 | return status; |
| 6655 | } |
| 6656 | |
| 6657 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6658 | const struct nfs_fh *fh, |
| 6659 | struct pnfs_devicelist *devlist) |
| 6660 | { |
| 6661 | struct nfs4_exception exception = { }; |
| 6662 | int err; |
| 6663 | |
| 6664 | do { |
| 6665 | err = nfs4_handle_exception(server, |
| 6666 | _nfs4_getdevicelist(server, fh, devlist), |
| 6667 | &exception); |
| 6668 | } while (exception.retry); |
| 6669 | |
| 6670 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6671 | err, devlist->num_devs); |
| 6672 | |
| 6673 | return err; |
| 6674 | } |
| 6675 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6676 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6677 | static int |
| 6678 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6679 | { |
| 6680 | struct nfs4_getdeviceinfo_args args = { |
| 6681 | .pdev = pdev, |
| 6682 | }; |
| 6683 | struct nfs4_getdeviceinfo_res res = { |
| 6684 | .pdev = pdev, |
| 6685 | }; |
| 6686 | struct rpc_message msg = { |
| 6687 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6688 | .rpc_argp = &args, |
| 6689 | .rpc_resp = &res, |
| 6690 | }; |
| 6691 | int status; |
| 6692 | |
| 6693 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6694 | 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] | 6695 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6696 | |
| 6697 | return status; |
| 6698 | } |
| 6699 | |
| 6700 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6701 | { |
| 6702 | struct nfs4_exception exception = { }; |
| 6703 | int err; |
| 6704 | |
| 6705 | do { |
| 6706 | err = nfs4_handle_exception(server, |
| 6707 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6708 | &exception); |
| 6709 | } while (exception.retry); |
| 6710 | return err; |
| 6711 | } |
| 6712 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6713 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6714 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6715 | { |
| 6716 | struct nfs4_layoutcommit_data *data = calldata; |
| 6717 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6718 | |
| 6719 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6720 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6721 | return; |
| 6722 | rpc_call_start(task); |
| 6723 | } |
| 6724 | |
| 6725 | static void |
| 6726 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6727 | { |
| 6728 | struct nfs4_layoutcommit_data *data = calldata; |
| 6729 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6730 | |
| 6731 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6732 | return; |
| 6733 | |
| 6734 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6735 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6736 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6737 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6738 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6739 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6740 | break; |
| 6741 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6742 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6743 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6744 | break; |
| 6745 | default: |
| 6746 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6747 | rpc_restart_call_prepare(task); |
| 6748 | return; |
| 6749 | } |
| 6750 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | static void nfs4_layoutcommit_release(void *calldata) |
| 6754 | { |
| 6755 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6756 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6757 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6758 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6759 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6760 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6761 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6762 | list_del_init(&lseg->pls_lc_list); |
| 6763 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6764 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6765 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6766 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6767 | |
| 6768 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6769 | smp_mb__after_clear_bit(); |
| 6770 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6771 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6772 | put_rpccred(data->cred); |
| 6773 | kfree(data); |
| 6774 | } |
| 6775 | |
| 6776 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6777 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6778 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6779 | .rpc_release = nfs4_layoutcommit_release, |
| 6780 | }; |
| 6781 | |
| 6782 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6783 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6784 | { |
| 6785 | struct rpc_message msg = { |
| 6786 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6787 | .rpc_argp = &data->args, |
| 6788 | .rpc_resp = &data->res, |
| 6789 | .rpc_cred = data->cred, |
| 6790 | }; |
| 6791 | struct rpc_task_setup task_setup_data = { |
| 6792 | .task = &data->task, |
| 6793 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6794 | .rpc_message = &msg, |
| 6795 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6796 | .callback_data = data, |
| 6797 | .flags = RPC_TASK_ASYNC, |
| 6798 | }; |
| 6799 | struct rpc_task *task; |
| 6800 | int status = 0; |
| 6801 | |
| 6802 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6803 | "lbw: %llu inode %lu\n", |
| 6804 | data->task.tk_pid, sync, |
| 6805 | data->args.lastbytewritten, |
| 6806 | data->args.inode->i_ino); |
| 6807 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6808 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6809 | task = rpc_run_task(&task_setup_data); |
| 6810 | if (IS_ERR(task)) |
| 6811 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6812 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6813 | goto out; |
| 6814 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6815 | if (status != 0) |
| 6816 | goto out; |
| 6817 | status = task->tk_status; |
| 6818 | out: |
| 6819 | dprintk("%s: status %d\n", __func__, status); |
| 6820 | rpc_put_task(task); |
| 6821 | return status; |
| 6822 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6823 | |
| 6824 | static int |
| 6825 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6826 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6827 | { |
| 6828 | struct nfs41_secinfo_no_name_args args = { |
| 6829 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6830 | }; |
| 6831 | struct nfs4_secinfo_res res = { |
| 6832 | .flavors = flavors, |
| 6833 | }; |
| 6834 | struct rpc_message msg = { |
| 6835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6836 | .rpc_argp = &args, |
| 6837 | .rpc_resp = &res, |
| 6838 | }; |
| 6839 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6840 | } |
| 6841 | |
| 6842 | static int |
| 6843 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6844 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6845 | { |
| 6846 | struct nfs4_exception exception = { }; |
| 6847 | int err; |
| 6848 | do { |
| 6849 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6850 | switch (err) { |
| 6851 | case 0: |
| 6852 | case -NFS4ERR_WRONGSEC: |
| 6853 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6854 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6855 | default: |
| 6856 | err = nfs4_handle_exception(server, err, &exception); |
| 6857 | } |
| 6858 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6859 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6860 | return err; |
| 6861 | } |
| 6862 | |
| 6863 | static int |
| 6864 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6865 | struct nfs_fsinfo *info) |
| 6866 | { |
| 6867 | int err; |
| 6868 | struct page *page; |
| 6869 | rpc_authflavor_t flavor; |
| 6870 | struct nfs4_secinfo_flavors *flavors; |
| 6871 | |
| 6872 | page = alloc_page(GFP_KERNEL); |
| 6873 | if (!page) { |
| 6874 | err = -ENOMEM; |
| 6875 | goto out; |
| 6876 | } |
| 6877 | |
| 6878 | flavors = page_address(page); |
| 6879 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6880 | |
| 6881 | /* |
| 6882 | * Fall back on "guess and check" method if |
| 6883 | * the server doesn't support SECINFO_NO_NAME |
| 6884 | */ |
| 6885 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6886 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6887 | goto out_freepage; |
| 6888 | } |
| 6889 | if (err) |
| 6890 | goto out_freepage; |
| 6891 | |
| 6892 | flavor = nfs_find_best_sec(flavors); |
| 6893 | if (err == 0) |
| 6894 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6895 | |
| 6896 | out_freepage: |
| 6897 | put_page(page); |
| 6898 | if (err == -EACCES) |
| 6899 | return -EPERM; |
| 6900 | out: |
| 6901 | return err; |
| 6902 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6903 | |
| 6904 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6905 | { |
| 6906 | int status; |
| 6907 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6908 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6909 | }; |
| 6910 | struct nfs41_test_stateid_res res; |
| 6911 | struct rpc_message msg = { |
| 6912 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6913 | .rpc_argp = &args, |
| 6914 | .rpc_resp = &res, |
| 6915 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6916 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6917 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6918 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6919 | 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] | 6920 | if (status != NFS_OK) { |
| 6921 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6922 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6923 | } |
| 6924 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6925 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6926 | } |
| 6927 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6928 | /** |
| 6929 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6930 | * |
| 6931 | * @server: server / transport on which to perform the operation |
| 6932 | * @stateid: state ID to test |
| 6933 | * |
| 6934 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6935 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6936 | * failed or the state ID is not currently valid. |
| 6937 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6938 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6939 | { |
| 6940 | struct nfs4_exception exception = { }; |
| 6941 | int err; |
| 6942 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6943 | err = _nfs41_test_stateid(server, stateid); |
| 6944 | if (err != -NFS4ERR_DELAY) |
| 6945 | break; |
| 6946 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6947 | } while (exception.retry); |
| 6948 | return err; |
| 6949 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6950 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6951 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6952 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6953 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6954 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6955 | }; |
| 6956 | struct nfs41_free_stateid_res res; |
| 6957 | struct rpc_message msg = { |
| 6958 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6959 | .rpc_argp = &args, |
| 6960 | .rpc_resp = &res, |
| 6961 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6962 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6963 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6964 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6965 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6966 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6967 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6968 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6969 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6970 | } |
| 6971 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6972 | /** |
| 6973 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6974 | * |
| 6975 | * @server: server / transport on which to perform the operation |
| 6976 | * @stateid: state ID to release |
| 6977 | * |
| 6978 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6979 | * negative NFS4ERR value is returned. |
| 6980 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6981 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6982 | { |
| 6983 | struct nfs4_exception exception = { }; |
| 6984 | int err; |
| 6985 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6986 | err = _nfs4_free_stateid(server, stateid); |
| 6987 | if (err != -NFS4ERR_DELAY) |
| 6988 | break; |
| 6989 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6990 | } while (exception.retry); |
| 6991 | return err; |
| 6992 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6993 | |
| 6994 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6995 | const nfs4_stateid *s2) |
| 6996 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6997 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6998 | return false; |
| 6999 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7000 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7001 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7002 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7003 | return true; |
| 7004 | |
| 7005 | return false; |
| 7006 | } |
| 7007 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7008 | #endif /* CONFIG_NFS_V4_1 */ |
| 7009 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7010 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7011 | const nfs4_stateid *s2) |
| 7012 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7013 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7014 | } |
| 7015 | |
| 7016 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7017 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7018 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7019 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7020 | .recover_open = nfs4_open_reclaim, |
| 7021 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7022 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7023 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7024 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7025 | }; |
| 7026 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7027 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7028 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7029 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7030 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7031 | .recover_open = nfs4_open_reclaim, |
| 7032 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7033 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7034 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7035 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7036 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7037 | }; |
| 7038 | #endif /* CONFIG_NFS_V4_1 */ |
| 7039 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7040 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7041 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7042 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7043 | .recover_open = nfs4_open_expired, |
| 7044 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7045 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7046 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7047 | }; |
| 7048 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7049 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7050 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7051 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7052 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7053 | .recover_open = nfs41_open_expired, |
| 7054 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7055 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7056 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7057 | }; |
| 7058 | #endif /* CONFIG_NFS_V4_1 */ |
| 7059 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7060 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7061 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7062 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7063 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7064 | }; |
| 7065 | |
| 7066 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7067 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7068 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7069 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7070 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7071 | }; |
| 7072 | #endif |
| 7073 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7074 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7075 | .minor_version = 0, |
| 7076 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7077 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7078 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7079 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7080 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7081 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7082 | }; |
| 7083 | |
| 7084 | #if defined(CONFIG_NFS_V4_1) |
| 7085 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7086 | .minor_version = 1, |
| 7087 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7088 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7089 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7090 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7091 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7092 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7093 | }; |
| 7094 | #endif |
| 7095 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7096 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7097 | [0] = &nfs_v4_0_minor_ops, |
| 7098 | #if defined(CONFIG_NFS_V4_1) |
| 7099 | [1] = &nfs_v4_1_minor_ops, |
| 7100 | #endif |
| 7101 | }; |
| 7102 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7103 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7104 | .create = nfs_create, |
| 7105 | .lookup = nfs_lookup, |
| 7106 | .atomic_open = nfs_atomic_open, |
| 7107 | .link = nfs_link, |
| 7108 | .unlink = nfs_unlink, |
| 7109 | .symlink = nfs_symlink, |
| 7110 | .mkdir = nfs_mkdir, |
| 7111 | .rmdir = nfs_rmdir, |
| 7112 | .mknod = nfs_mknod, |
| 7113 | .rename = nfs_rename, |
| 7114 | .permission = nfs_permission, |
| 7115 | .getattr = nfs_getattr, |
| 7116 | .setattr = nfs_setattr, |
| 7117 | .getxattr = generic_getxattr, |
| 7118 | .setxattr = generic_setxattr, |
| 7119 | .listxattr = generic_listxattr, |
| 7120 | .removexattr = generic_removexattr, |
| 7121 | }; |
| 7122 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7123 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7124 | .permission = nfs_permission, |
| 7125 | .getattr = nfs_getattr, |
| 7126 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7127 | .getxattr = generic_getxattr, |
| 7128 | .setxattr = generic_setxattr, |
| 7129 | .listxattr = generic_listxattr, |
| 7130 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7131 | }; |
| 7132 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7133 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7134 | .version = 4, /* protocol version */ |
| 7135 | .dentry_ops = &nfs4_dentry_operations, |
| 7136 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7137 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7138 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7139 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7140 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7141 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7142 | .getattr = nfs4_proc_getattr, |
| 7143 | .setattr = nfs4_proc_setattr, |
| 7144 | .lookup = nfs4_proc_lookup, |
| 7145 | .access = nfs4_proc_access, |
| 7146 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7147 | .create = nfs4_proc_create, |
| 7148 | .remove = nfs4_proc_remove, |
| 7149 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7150 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7151 | .unlink_done = nfs4_proc_unlink_done, |
| 7152 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7153 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7154 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7155 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7156 | .link = nfs4_proc_link, |
| 7157 | .symlink = nfs4_proc_symlink, |
| 7158 | .mkdir = nfs4_proc_mkdir, |
| 7159 | .rmdir = nfs4_proc_remove, |
| 7160 | .readdir = nfs4_proc_readdir, |
| 7161 | .mknod = nfs4_proc_mknod, |
| 7162 | .statfs = nfs4_proc_statfs, |
| 7163 | .fsinfo = nfs4_proc_fsinfo, |
| 7164 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7165 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7166 | .decode_dirent = nfs4_decode_dirent, |
| 7167 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7168 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7169 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7170 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7171 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7172 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7173 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7174 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7175 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7176 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7177 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7178 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7179 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7180 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7181 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7182 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7183 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7184 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7185 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7186 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7187 | .create_server = nfs4_create_server, |
| 7188 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7189 | }; |
| 7190 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7191 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7192 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7193 | .list = nfs4_xattr_list_nfs4_acl, |
| 7194 | .get = nfs4_xattr_get_nfs4_acl, |
| 7195 | .set = nfs4_xattr_set_nfs4_acl, |
| 7196 | }; |
| 7197 | |
| 7198 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7199 | &nfs4_xattr_nfs4_acl_handler, |
| 7200 | NULL |
| 7201 | }; |
| 7202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7203 | /* |
| 7204 | * Local variables: |
| 7205 | * c-basic-offset: 8 |
| 7206 | * End: |
| 7207 | */ |