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 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 529 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 530 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 531 | slot->slot_nr, |
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 | /* |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 559 | * nfs4_alloc_slot - efficiently look for a free slot |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 560 | * |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 561 | * nfs4_alloc_slot looks for an unset bit in the used_slots bitmap. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 562 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 563 | * and respectively set up the sequence operation args. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 564 | * |
| 565 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 566 | */ |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 567 | static struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 568 | { |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 569 | struct nfs4_slot *ret = NULL; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 570 | u32 slotid; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 571 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 572 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 573 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 574 | tbl->max_slots); |
| 575 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 576 | if (slotid >= tbl->max_slots) |
| 577 | goto out; |
| 578 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 579 | if (slotid > tbl->highest_used_slotid || |
| 580 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 581 | tbl->highest_used_slotid = slotid; |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 582 | ret = &tbl->slots[slotid]; |
| 583 | ret->renewal_time = jiffies; |
| 584 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 585 | out: |
| 586 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 587 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 588 | ret ? ret->slot_nr : -1); |
| 589 | return ret; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 592 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 593 | struct nfs4_sequence_res *res, int cache_reply) |
| 594 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 595 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 596 | args->sa_cache_this = 0; |
| 597 | if (cache_reply) |
| 598 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 599 | res->sr_slot = NULL; |
| 600 | } |
| 601 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 602 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 603 | struct nfs4_sequence_args *args, |
| 604 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 605 | struct rpc_task *task) |
| 606 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 607 | struct nfs4_slot *slot; |
| 608 | struct nfs4_slot_table *tbl; |
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 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 635 | slot = nfs4_alloc_slot(tbl); |
| 636 | if (slot == NULL) { |
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); |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 645 | |
| 646 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 647 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame^] | 648 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 649 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 650 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 651 | res->sr_slot = slot; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 652 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 653 | /* |
| 654 | * sr_status is only set in decode_sequence, and so will remain |
| 655 | * set to 1 if an rpc level failure occurs. |
| 656 | */ |
| 657 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 658 | return 0; |
| 659 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 660 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 662 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | struct nfs4_sequence_args *args, |
| 664 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 665 | struct rpc_task *task) |
| 666 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 667 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 668 | int ret = 0; |
| 669 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 670 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 672 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 673 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 674 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 675 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 676 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 677 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 678 | out: |
| 679 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 680 | return ret; |
| 681 | } |
| 682 | |
| 683 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 684 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 685 | struct nfs4_sequence_args *seq_args; |
| 686 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 687 | }; |
| 688 | |
| 689 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 690 | { |
| 691 | struct nfs41_call_sync_data *data = calldata; |
| 692 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 693 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 694 | |
| 695 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 696 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 697 | return; |
| 698 | rpc_call_start(task); |
| 699 | } |
| 700 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 701 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 702 | { |
| 703 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 704 | nfs41_call_sync_prepare(task, calldata); |
| 705 | } |
| 706 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 707 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 708 | { |
| 709 | struct nfs41_call_sync_data *data = calldata; |
| 710 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 711 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 712 | } |
| 713 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 714 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 715 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 716 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 717 | }; |
| 718 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 719 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 720 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 721 | .rpc_call_done = nfs41_call_sync_done, |
| 722 | }; |
| 723 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 724 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 725 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 726 | struct rpc_message *msg, |
| 727 | struct nfs4_sequence_args *args, |
| 728 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 729 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 730 | { |
| 731 | int ret; |
| 732 | struct rpc_task *task; |
| 733 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 734 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 735 | .seq_args = args, |
| 736 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 737 | }; |
| 738 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 739 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 740 | .rpc_message = msg, |
| 741 | .callback_ops = &nfs41_call_sync_ops, |
| 742 | .callback_data = &data |
| 743 | }; |
| 744 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 745 | if (privileged) |
| 746 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 747 | task = rpc_run_task(&task_setup); |
| 748 | if (IS_ERR(task)) |
| 749 | ret = PTR_ERR(task); |
| 750 | else { |
| 751 | ret = task->tk_status; |
| 752 | rpc_put_task(task); |
| 753 | } |
| 754 | return ret; |
| 755 | } |
| 756 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 757 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 758 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 759 | struct rpc_message *msg, |
| 760 | struct nfs4_sequence_args *args, |
| 761 | struct nfs4_sequence_res *res, |
| 762 | int cache_reply) |
| 763 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 764 | nfs41_init_sequence(args, res, cache_reply); |
| 765 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 766 | } |
| 767 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 768 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 769 | static inline |
| 770 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 771 | struct nfs4_sequence_res *res, int cache_reply) |
| 772 | { |
| 773 | } |
| 774 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 775 | static int nfs4_sequence_done(struct rpc_task *task, |
| 776 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 777 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 778 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 779 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 780 | #endif /* CONFIG_NFS_V4_1 */ |
| 781 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 782 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 783 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 784 | struct rpc_message *msg, |
| 785 | struct nfs4_sequence_args *args, |
| 786 | struct nfs4_sequence_res *res, |
| 787 | int cache_reply) |
| 788 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 789 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 790 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 791 | } |
| 792 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 793 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 794 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 795 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 796 | struct rpc_message *msg, |
| 797 | struct nfs4_sequence_args *args, |
| 798 | struct nfs4_sequence_res *res, |
| 799 | int cache_reply) |
| 800 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 801 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 802 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 803 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 804 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 805 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 807 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 809 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 810 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 811 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 812 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 813 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 814 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 817 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 818 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 819 | struct nfs_openargs o_arg; |
| 820 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 821 | struct nfs_open_confirmargs c_arg; |
| 822 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 823 | struct nfs4_string owner_name; |
| 824 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 827 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 829 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 830 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 831 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 832 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 833 | int rpc_status; |
| 834 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 835 | }; |
| 836 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 837 | |
| 838 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 839 | { |
| 840 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 841 | p->o_res.seqid = p->o_arg.seqid; |
| 842 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 843 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 844 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 845 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 846 | 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] | 847 | } |
| 848 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 849 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 850 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 851 | const struct iattr *attrs, |
| 852 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 853 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 854 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | struct inode *dir = parent->d_inode; |
| 856 | struct nfs_server *server = NFS_SERVER(dir); |
| 857 | struct nfs4_opendata *p; |
| 858 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 859 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 860 | if (p == NULL) |
| 861 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 862 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 863 | if (p->o_arg.seqid == NULL) |
| 864 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 865 | nfs_sb_active(dentry->d_sb); |
| 866 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 867 | p->dir = parent; |
| 868 | p->owner = sp; |
| 869 | atomic_inc(&sp->so_count); |
| 870 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 871 | p->o_arg.open_flags = flags; |
| 872 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 873 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 874 | * will return permission denied for all bits until close */ |
| 875 | if (!(flags & O_EXCL)) { |
| 876 | /* ask server to check for all possible rights as results |
| 877 | * are cached */ |
| 878 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 879 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 880 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 881 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 882 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 883 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 884 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 885 | p->o_arg.server = server; |
| 886 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 887 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 888 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 889 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 890 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 891 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 892 | p->o_arg.u.attrs = &p->attrs; |
| 893 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 894 | |
| 895 | verf[0] = jiffies; |
| 896 | verf[1] = current->pid; |
| 897 | memcpy(p->o_arg.u.verifier.data, verf, |
| 898 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 899 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 900 | p->c_arg.fh = &p->o_res.fh; |
| 901 | p->c_arg.stateid = &p->o_res.stateid; |
| 902 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 903 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 904 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 905 | return p; |
| 906 | err_free: |
| 907 | kfree(p); |
| 908 | err: |
| 909 | dput(parent); |
| 910 | return NULL; |
| 911 | } |
| 912 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 913 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 914 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 915 | struct nfs4_opendata *p = container_of(kref, |
| 916 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 917 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 918 | |
| 919 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 920 | if (p->state != NULL) |
| 921 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 922 | nfs4_put_state_owner(p->owner); |
| 923 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 924 | dput(p->dentry); |
| 925 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 926 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 927 | kfree(p); |
| 928 | } |
| 929 | |
| 930 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 931 | { |
| 932 | if (p != NULL) |
| 933 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 934 | } |
| 935 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 936 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 937 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 938 | int ret; |
| 939 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 940 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 941 | return ret; |
| 942 | } |
| 943 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 944 | 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] | 945 | { |
| 946 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 948 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 949 | goto out; |
| 950 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 951 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 952 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 953 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 954 | break; |
| 955 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 956 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 957 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 958 | break; |
| 959 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 960 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 961 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 962 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 964 | return ret; |
| 965 | } |
| 966 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 967 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 968 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 969 | if (delegation == NULL) |
| 970 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 971 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 972 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 973 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 974 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 975 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 976 | return 1; |
| 977 | } |
| 978 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 979 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 980 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 981 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 982 | case FMODE_WRITE: |
| 983 | state->n_wronly++; |
| 984 | break; |
| 985 | case FMODE_READ: |
| 986 | state->n_rdonly++; |
| 987 | break; |
| 988 | case FMODE_READ|FMODE_WRITE: |
| 989 | state->n_rdwr++; |
| 990 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 991 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 994 | 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] | 995 | { |
| 996 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 997 | nfs4_stateid_copy(&state->stateid, stateid); |
| 998 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1000 | case FMODE_READ: |
| 1001 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1002 | break; |
| 1003 | case FMODE_WRITE: |
| 1004 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1005 | break; |
| 1006 | case FMODE_READ|FMODE_WRITE: |
| 1007 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1008 | } |
| 1009 | } |
| 1010 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1011 | 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] | 1012 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1013 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1014 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1015 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1018 | 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] | 1019 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1020 | /* |
| 1021 | * Protect the call to nfs4_state_set_mode_locked and |
| 1022 | * serialise the stateid update |
| 1023 | */ |
| 1024 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1025 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1026 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1027 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1028 | } |
| 1029 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1031 | write_sequnlock(&state->seqlock); |
| 1032 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1033 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1034 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1037 | 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] | 1038 | { |
| 1039 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1040 | struct nfs_delegation *deleg_cur; |
| 1041 | int ret = 0; |
| 1042 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1043 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1044 | |
| 1045 | rcu_read_lock(); |
| 1046 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1047 | if (deleg_cur == NULL) |
| 1048 | goto no_delegation; |
| 1049 | |
| 1050 | spin_lock(&deleg_cur->lock); |
| 1051 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1052 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1053 | goto no_delegation_unlock; |
| 1054 | |
| 1055 | if (delegation == NULL) |
| 1056 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1057 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1058 | goto no_delegation_unlock; |
| 1059 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1060 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1061 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1062 | ret = 1; |
| 1063 | no_delegation_unlock: |
| 1064 | spin_unlock(&deleg_cur->lock); |
| 1065 | no_delegation: |
| 1066 | rcu_read_unlock(); |
| 1067 | |
| 1068 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1069 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1070 | ret = 1; |
| 1071 | } |
| 1072 | |
| 1073 | return ret; |
| 1074 | } |
| 1075 | |
| 1076 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1077 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1078 | { |
| 1079 | struct nfs_delegation *delegation; |
| 1080 | |
| 1081 | rcu_read_lock(); |
| 1082 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1083 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1084 | rcu_read_unlock(); |
| 1085 | return; |
| 1086 | } |
| 1087 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1088 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1091 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1092 | { |
| 1093 | struct nfs4_state *state = opendata->state; |
| 1094 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1095 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1096 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1097 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1098 | nfs4_stateid stateid; |
| 1099 | int ret = -EAGAIN; |
| 1100 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1101 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1102 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1103 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1104 | if (can_open_cached(state, fmode, open_mode)) { |
| 1105 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1106 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1107 | goto out_return_state; |
| 1108 | } |
| 1109 | spin_unlock(&state->owner->so_lock); |
| 1110 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1111 | rcu_read_lock(); |
| 1112 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1113 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1114 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1115 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1116 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1117 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1118 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1119 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1120 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1121 | if (ret != 0) |
| 1122 | goto out; |
| 1123 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1124 | |
| 1125 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1126 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1127 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1128 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1129 | out: |
| 1130 | return ERR_PTR(ret); |
| 1131 | out_return_state: |
| 1132 | atomic_inc(&state->count); |
| 1133 | return state; |
| 1134 | } |
| 1135 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1136 | static void |
| 1137 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1138 | { |
| 1139 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1140 | struct nfs_delegation *delegation; |
| 1141 | int delegation_flags = 0; |
| 1142 | |
| 1143 | rcu_read_lock(); |
| 1144 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1145 | if (delegation) |
| 1146 | delegation_flags = delegation->flags; |
| 1147 | rcu_read_unlock(); |
| 1148 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1149 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1150 | "returning a delegation for " |
| 1151 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1152 | clp->cl_hostname); |
| 1153 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1154 | nfs_inode_set_delegation(state->inode, |
| 1155 | data->owner->so_cred, |
| 1156 | &data->o_res); |
| 1157 | else |
| 1158 | nfs_inode_reclaim_delegation(state->inode, |
| 1159 | data->owner->so_cred, |
| 1160 | &data->o_res); |
| 1161 | } |
| 1162 | |
| 1163 | /* |
| 1164 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1165 | * and update the nfs4_state. |
| 1166 | */ |
| 1167 | static struct nfs4_state * |
| 1168 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1169 | { |
| 1170 | struct inode *inode = data->state->inode; |
| 1171 | struct nfs4_state *state = data->state; |
| 1172 | int ret; |
| 1173 | |
| 1174 | if (!data->rpc_done) { |
| 1175 | ret = data->rpc_status; |
| 1176 | goto err; |
| 1177 | } |
| 1178 | |
| 1179 | ret = -ESTALE; |
| 1180 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1181 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1182 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1183 | goto err; |
| 1184 | |
| 1185 | ret = -ENOMEM; |
| 1186 | state = nfs4_get_open_state(inode, data->owner); |
| 1187 | if (state == NULL) |
| 1188 | goto err; |
| 1189 | |
| 1190 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1191 | if (ret) |
| 1192 | goto err; |
| 1193 | |
| 1194 | if (data->o_res.delegation_type != 0) |
| 1195 | nfs4_opendata_check_deleg(data, state); |
| 1196 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1197 | data->o_arg.fmode); |
| 1198 | |
| 1199 | return state; |
| 1200 | err: |
| 1201 | return ERR_PTR(ret); |
| 1202 | |
| 1203 | } |
| 1204 | |
| 1205 | static struct nfs4_state * |
| 1206 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1207 | { |
| 1208 | struct inode *inode; |
| 1209 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1210 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1211 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1212 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1213 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1214 | goto out; |
| 1215 | } |
| 1216 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1217 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1218 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1219 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1220 | 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] | 1221 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1222 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1223 | goto err; |
| 1224 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1225 | state = nfs4_get_open_state(inode, data->owner); |
| 1226 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1227 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1228 | if (data->o_res.delegation_type != 0) |
| 1229 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1230 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1231 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1232 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1233 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1234 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1235 | err_put_inode: |
| 1236 | iput(inode); |
| 1237 | err: |
| 1238 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1241 | static struct nfs4_state * |
| 1242 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1243 | { |
| 1244 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1245 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1246 | return _nfs4_opendata_to_nfs4_state(data); |
| 1247 | } |
| 1248 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1249 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1250 | { |
| 1251 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1252 | struct nfs_open_context *ctx; |
| 1253 | |
| 1254 | spin_lock(&state->inode->i_lock); |
| 1255 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1256 | if (ctx->state != state) |
| 1257 | continue; |
| 1258 | get_nfs_open_context(ctx); |
| 1259 | spin_unlock(&state->inode->i_lock); |
| 1260 | return ctx; |
| 1261 | } |
| 1262 | spin_unlock(&state->inode->i_lock); |
| 1263 | return ERR_PTR(-ENOENT); |
| 1264 | } |
| 1265 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1266 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1267 | { |
| 1268 | struct nfs4_opendata *opendata; |
| 1269 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1270 | 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] | 1271 | if (opendata == NULL) |
| 1272 | return ERR_PTR(-ENOMEM); |
| 1273 | opendata->state = state; |
| 1274 | atomic_inc(&state->count); |
| 1275 | return opendata; |
| 1276 | } |
| 1277 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1278 | 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] | 1279 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1280 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1281 | int ret; |
| 1282 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1283 | opendata->o_arg.open_flags = 0; |
| 1284 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1285 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1286 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1287 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1288 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1289 | if (ret != 0) |
| 1290 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1291 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1292 | if (IS_ERR(newstate)) |
| 1293 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1294 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1295 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1300 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1301 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1302 | int ret; |
| 1303 | |
| 1304 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1305 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1306 | smp_rmb(); |
| 1307 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1308 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1309 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1310 | if (ret != 0) |
| 1311 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1312 | if (newstate != state) |
| 1313 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1314 | } |
| 1315 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1316 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1317 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1318 | if (ret != 0) |
| 1319 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1320 | if (newstate != state) |
| 1321 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1322 | } |
| 1323 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1324 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1325 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1326 | if (ret != 0) |
| 1327 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1328 | if (newstate != state) |
| 1329 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1330 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1331 | /* |
| 1332 | * We may have performed cached opens for all three recoveries. |
| 1333 | * Check if we need to update the current stateid. |
| 1334 | */ |
| 1335 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1336 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1337 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1338 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1339 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1340 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1341 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1342 | return 0; |
| 1343 | } |
| 1344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | /* |
| 1346 | * OPEN_RECLAIM: |
| 1347 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1349 | 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] | 1350 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1351 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1352 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1353 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | int status; |
| 1355 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1356 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1357 | if (IS_ERR(opendata)) |
| 1358 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1359 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1360 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1361 | rcu_read_lock(); |
| 1362 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1363 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1364 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1365 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1366 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1367 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1368 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | return status; |
| 1370 | } |
| 1371 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1372 | 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] | 1373 | { |
| 1374 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1375 | struct nfs4_exception exception = { }; |
| 1376 | int err; |
| 1377 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1378 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1379 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1380 | break; |
| 1381 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | } while (exception.retry); |
| 1383 | return err; |
| 1384 | } |
| 1385 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1386 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1387 | { |
| 1388 | struct nfs_open_context *ctx; |
| 1389 | int ret; |
| 1390 | |
| 1391 | ctx = nfs4_state_find_open_context(state); |
| 1392 | if (IS_ERR(ctx)) |
| 1393 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1394 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1395 | put_nfs_open_context(ctx); |
| 1396 | return ret; |
| 1397 | } |
| 1398 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1399 | 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] | 1400 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1401 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1402 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1404 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1405 | if (IS_ERR(opendata)) |
| 1406 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1407 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1408 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1409 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1410 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1411 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1414 | 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] | 1415 | { |
| 1416 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1417 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | int err; |
| 1419 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1420 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | switch (err) { |
| 1422 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1423 | case -ENOENT: |
| 1424 | case -ESTALE: |
| 1425 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1426 | case -NFS4ERR_BADSESSION: |
| 1427 | case -NFS4ERR_BADSLOT: |
| 1428 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1429 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1430 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1431 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1432 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | case -NFS4ERR_STALE_CLIENTID: |
| 1434 | case -NFS4ERR_STALE_STATEID: |
| 1435 | case -NFS4ERR_EXPIRED: |
| 1436 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1437 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1438 | goto out; |
| 1439 | case -ERESTARTSYS: |
| 1440 | /* |
| 1441 | * The show must go on: exit, but mark the |
| 1442 | * stateid as needing recovery. |
| 1443 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1444 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1445 | case -NFS4ERR_ADMIN_REVOKED: |
| 1446 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1447 | nfs_inode_find_state_and_recover(state->inode, |
| 1448 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1449 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1450 | case -EKEYEXPIRED: |
| 1451 | /* |
| 1452 | * User RPCSEC_GSS context has expired. |
| 1453 | * We cannot recover this stateid now, so |
| 1454 | * skip it and allow recovery thread to |
| 1455 | * proceed. |
| 1456 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1457 | case -ENOMEM: |
| 1458 | err = 0; |
| 1459 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | } |
| 1461 | err = nfs4_handle_exception(server, err, &exception); |
| 1462 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1463 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | return err; |
| 1465 | } |
| 1466 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1467 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1468 | { |
| 1469 | struct nfs4_opendata *data = calldata; |
| 1470 | |
| 1471 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1472 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1473 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1474 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1475 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1476 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1477 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | static void nfs4_open_confirm_release(void *calldata) |
| 1481 | { |
| 1482 | struct nfs4_opendata *data = calldata; |
| 1483 | struct nfs4_state *state = NULL; |
| 1484 | |
| 1485 | /* If this request hasn't been cancelled, do nothing */ |
| 1486 | if (data->cancelled == 0) |
| 1487 | goto out_free; |
| 1488 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1489 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1490 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1491 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1492 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1493 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1494 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1495 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1499 | .rpc_call_done = nfs4_open_confirm_done, |
| 1500 | .rpc_release = nfs4_open_confirm_release, |
| 1501 | }; |
| 1502 | |
| 1503 | /* |
| 1504 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1505 | */ |
| 1506 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1507 | { |
| 1508 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1509 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1510 | struct rpc_message msg = { |
| 1511 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1512 | .rpc_argp = &data->c_arg, |
| 1513 | .rpc_resp = &data->c_res, |
| 1514 | .rpc_cred = data->owner->so_cred, |
| 1515 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1516 | struct rpc_task_setup task_setup_data = { |
| 1517 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1518 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1519 | .callback_ops = &nfs4_open_confirm_ops, |
| 1520 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1521 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1522 | .flags = RPC_TASK_ASYNC, |
| 1523 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | int status; |
| 1525 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1526 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1527 | data->rpc_done = 0; |
| 1528 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1529 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1530 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1531 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1532 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1533 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1534 | if (status != 0) { |
| 1535 | data->cancelled = 1; |
| 1536 | smp_wmb(); |
| 1537 | } else |
| 1538 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1539 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | return status; |
| 1541 | } |
| 1542 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1543 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1545 | struct nfs4_opendata *data = calldata; |
| 1546 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1547 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1548 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1549 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1550 | /* |
| 1551 | * Check if we still need to send an OPEN call, or if we can use |
| 1552 | * a delegation instead. |
| 1553 | */ |
| 1554 | if (data->state != NULL) { |
| 1555 | struct nfs_delegation *delegation; |
| 1556 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1557 | 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] | 1558 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1559 | rcu_read_lock(); |
| 1560 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1561 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1562 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1563 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1564 | rcu_read_unlock(); |
| 1565 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1566 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1567 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1568 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1569 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1570 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1571 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1572 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1573 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1574 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1575 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1576 | &data->o_res.seq_res, |
| 1577 | task) != 0) |
| 1578 | nfs_release_seqid(data->o_arg.seqid); |
| 1579 | else |
| 1580 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1581 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1582 | unlock_no_action: |
| 1583 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1584 | out_no_action: |
| 1585 | task->tk_action = NULL; |
| 1586 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1589 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1590 | { |
| 1591 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1592 | nfs4_open_prepare(task, calldata); |
| 1593 | } |
| 1594 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1595 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1596 | { |
| 1597 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1599 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1600 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1601 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1602 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1603 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1604 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1605 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1606 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1607 | case S_IFREG: |
| 1608 | break; |
| 1609 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1610 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1611 | break; |
| 1612 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1613 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1614 | break; |
| 1615 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1616 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1617 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1618 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1619 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1620 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1621 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1622 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1623 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1624 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1625 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1626 | static void nfs4_open_release(void *calldata) |
| 1627 | { |
| 1628 | struct nfs4_opendata *data = calldata; |
| 1629 | struct nfs4_state *state = NULL; |
| 1630 | |
| 1631 | /* If this request hasn't been cancelled, do nothing */ |
| 1632 | if (data->cancelled == 0) |
| 1633 | goto out_free; |
| 1634 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1635 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1636 | goto out_free; |
| 1637 | /* In case we need an open_confirm, no cleanup! */ |
| 1638 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1639 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1640 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1641 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1642 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1643 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1644 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1648 | .rpc_call_prepare = nfs4_open_prepare, |
| 1649 | .rpc_call_done = nfs4_open_done, |
| 1650 | .rpc_release = nfs4_open_release, |
| 1651 | }; |
| 1652 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1653 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1654 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1655 | .rpc_call_done = nfs4_open_done, |
| 1656 | .rpc_release = nfs4_open_release, |
| 1657 | }; |
| 1658 | |
| 1659 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1660 | { |
| 1661 | struct inode *dir = data->dir->d_inode; |
| 1662 | struct nfs_server *server = NFS_SERVER(dir); |
| 1663 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1664 | struct nfs_openres *o_res = &data->o_res; |
| 1665 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1666 | struct rpc_message msg = { |
| 1667 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1668 | .rpc_argp = o_arg, |
| 1669 | .rpc_resp = o_res, |
| 1670 | .rpc_cred = data->owner->so_cred, |
| 1671 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1672 | struct rpc_task_setup task_setup_data = { |
| 1673 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1674 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1675 | .callback_ops = &nfs4_open_ops, |
| 1676 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1677 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1678 | .flags = RPC_TASK_ASYNC, |
| 1679 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1680 | int status; |
| 1681 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1682 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1683 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1684 | data->rpc_done = 0; |
| 1685 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1686 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1687 | if (isrecover) |
| 1688 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1689 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1690 | if (IS_ERR(task)) |
| 1691 | return PTR_ERR(task); |
| 1692 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1693 | if (status != 0) { |
| 1694 | data->cancelled = 1; |
| 1695 | smp_wmb(); |
| 1696 | } else |
| 1697 | status = data->rpc_status; |
| 1698 | rpc_put_task(task); |
| 1699 | |
| 1700 | return status; |
| 1701 | } |
| 1702 | |
| 1703 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1704 | { |
| 1705 | struct inode *dir = data->dir->d_inode; |
| 1706 | struct nfs_openres *o_res = &data->o_res; |
| 1707 | int status; |
| 1708 | |
| 1709 | status = nfs4_run_open_task(data, 1); |
| 1710 | if (status != 0 || !data->rpc_done) |
| 1711 | return status; |
| 1712 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1713 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1714 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1715 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1716 | status = _nfs4_proc_open_confirm(data); |
| 1717 | if (status != 0) |
| 1718 | return status; |
| 1719 | } |
| 1720 | |
| 1721 | return status; |
| 1722 | } |
| 1723 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1724 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1725 | struct nfs4_opendata *opendata, |
| 1726 | struct nfs4_state *state, fmode_t fmode) |
| 1727 | { |
| 1728 | struct nfs_access_entry cache; |
| 1729 | u32 mask; |
| 1730 | |
| 1731 | /* access call failed or for some reason the server doesn't |
| 1732 | * support any access modes -- defer access call until later */ |
| 1733 | if (opendata->o_res.access_supported == 0) |
| 1734 | return 0; |
| 1735 | |
| 1736 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1737 | /* don't check MAY_WRITE - a newly created file may not have |
| 1738 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1739 | if (fmode & FMODE_READ) |
| 1740 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1741 | if (fmode & FMODE_EXEC) |
| 1742 | mask |= MAY_EXEC; |
| 1743 | |
| 1744 | cache.cred = cred; |
| 1745 | cache.jiffies = jiffies; |
| 1746 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1747 | nfs_access_add_cache(state->inode, &cache); |
| 1748 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1749 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1750 | return 0; |
| 1751 | |
| 1752 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1753 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1754 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1755 | } |
| 1756 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1757 | /* |
| 1758 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1759 | */ |
| 1760 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1761 | { |
| 1762 | struct inode *dir = data->dir->d_inode; |
| 1763 | struct nfs_server *server = NFS_SERVER(dir); |
| 1764 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1765 | struct nfs_openres *o_res = &data->o_res; |
| 1766 | int status; |
| 1767 | |
| 1768 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1769 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1770 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1771 | if (status != 0) { |
| 1772 | if (status == -NFS4ERR_BADNAME && |
| 1773 | !(o_arg->open_flags & O_CREAT)) |
| 1774 | return -ENOENT; |
| 1775 | return status; |
| 1776 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1777 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1778 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1779 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1780 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1781 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1782 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1783 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1785 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1787 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | } |
| 1789 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1790 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1791 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1794 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1795 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1796 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1797 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1798 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1799 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1800 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1801 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1802 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1803 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1804 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1805 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1806 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1807 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1808 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1809 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1810 | } |
| 1811 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1812 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1813 | { |
| 1814 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1815 | } |
| 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | /* |
| 1818 | * OPEN_EXPIRED: |
| 1819 | * reclaim state on the server after a network partition. |
| 1820 | * Assumes caller holds the appropriate lock |
| 1821 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1822 | 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] | 1823 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1824 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1825 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1827 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1828 | if (IS_ERR(opendata)) |
| 1829 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1830 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1831 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1832 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1833 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1834 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1837 | 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] | 1838 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1839 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1840 | struct nfs4_exception exception = { }; |
| 1841 | int err; |
| 1842 | |
| 1843 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1844 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1845 | switch (err) { |
| 1846 | default: |
| 1847 | goto out; |
| 1848 | case -NFS4ERR_GRACE: |
| 1849 | case -NFS4ERR_DELAY: |
| 1850 | nfs4_handle_exception(server, err, &exception); |
| 1851 | err = 0; |
| 1852 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1853 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1854 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1855 | return err; |
| 1856 | } |
| 1857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1859 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1861 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1863 | ctx = nfs4_state_find_open_context(state); |
| 1864 | if (IS_ERR(ctx)) |
| 1865 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1866 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1867 | put_nfs_open_context(ctx); |
| 1868 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1871 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1872 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1873 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1874 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1875 | nfs4_stateid *stateid = &state->stateid; |
| 1876 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1877 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1878 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1879 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1880 | return; |
| 1881 | |
| 1882 | status = nfs41_test_stateid(server, stateid); |
| 1883 | if (status != NFS_OK) { |
| 1884 | /* Free the stateid unless the server explicitly |
| 1885 | * informs us the stateid is unrecognized. */ |
| 1886 | if (status != -NFS4ERR_BAD_STATEID) |
| 1887 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1888 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1889 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1890 | write_seqlock(&state->seqlock); |
| 1891 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1892 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1893 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | /** |
| 1898 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1899 | * |
| 1900 | * @state: NFSv4 state for an inode |
| 1901 | * |
| 1902 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1903 | * Otherwise a negative NFS4ERR value is returned. |
| 1904 | */ |
| 1905 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1906 | { |
| 1907 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1908 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1909 | int status; |
| 1910 | |
| 1911 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1912 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1913 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1914 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1915 | return -NFS4ERR_BAD_STATEID; |
| 1916 | |
| 1917 | status = nfs41_test_stateid(server, stateid); |
| 1918 | if (status != NFS_OK) { |
| 1919 | /* Free the stateid unless the server explicitly |
| 1920 | * informs us the stateid is unrecognized. */ |
| 1921 | if (status != -NFS4ERR_BAD_STATEID) |
| 1922 | nfs41_free_stateid(server, stateid); |
| 1923 | |
| 1924 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1925 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1926 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1927 | } |
| 1928 | return status; |
| 1929 | } |
| 1930 | |
| 1931 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1932 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1933 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1934 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1935 | nfs41_clear_delegation_stateid(state); |
| 1936 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1937 | if (status != NFS_OK) |
| 1938 | status = nfs4_open_expired(sp, state); |
| 1939 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1940 | } |
| 1941 | #endif |
| 1942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1944 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1945 | * fields corresponding to attributes that were used to store the verifier. |
| 1946 | * Make sure we clobber those fields in the later setattr call |
| 1947 | */ |
| 1948 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1949 | { |
| 1950 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1951 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1952 | sattr->ia_valid |= ATTR_ATIME; |
| 1953 | |
| 1954 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1955 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1956 | sattr->ia_valid |= ATTR_MTIME; |
| 1957 | } |
| 1958 | |
| 1959 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1960 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1962 | static int _nfs4_do_open(struct inode *dir, |
| 1963 | struct dentry *dentry, |
| 1964 | fmode_t fmode, |
| 1965 | int flags, |
| 1966 | struct iattr *sattr, |
| 1967 | struct rpc_cred *cred, |
| 1968 | struct nfs4_state **res, |
| 1969 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | { |
| 1971 | struct nfs4_state_owner *sp; |
| 1972 | struct nfs4_state *state = NULL; |
| 1973 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1974 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1975 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | |
| 1977 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1979 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1980 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1982 | goto out_err; |
| 1983 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1984 | status = nfs4_recover_expired_lease(server); |
| 1985 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1986 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1987 | if (dentry->d_inode != NULL) |
| 1988 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1989 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1990 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1991 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1992 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1994 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1995 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1996 | if (!opendata->f_attr.mdsthreshold) |
| 1997 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1998 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1999 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2000 | if (dentry->d_inode != NULL) |
| 2001 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2002 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2003 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2005 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2007 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2008 | status = PTR_ERR(state); |
| 2009 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2010 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2011 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 2012 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2013 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2014 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 2015 | if (status != 0) |
| 2016 | goto err_opendata_put; |
| 2017 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2018 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 2019 | nfs4_exclusive_attrset(opendata, sattr); |
| 2020 | |
| 2021 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2022 | status = nfs4_do_setattr(state->inode, cred, |
| 2023 | opendata->o_res.f_attr, sattr, |
| 2024 | state); |
| 2025 | if (status == 0) |
| 2026 | nfs_setattr_update_inode(state->inode, sattr); |
| 2027 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2028 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2029 | |
| 2030 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2031 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2032 | else |
| 2033 | kfree(opendata->f_attr.mdsthreshold); |
| 2034 | opendata->f_attr.mdsthreshold = NULL; |
| 2035 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2036 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | *res = state; |
| 2039 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2040 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2041 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2042 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2043 | err_put_state_owner: |
| 2044 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | *res = NULL; |
| 2047 | return status; |
| 2048 | } |
| 2049 | |
| 2050 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2051 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2052 | struct dentry *dentry, |
| 2053 | fmode_t fmode, |
| 2054 | int flags, |
| 2055 | struct iattr *sattr, |
| 2056 | struct rpc_cred *cred, |
| 2057 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | { |
| 2059 | struct nfs4_exception exception = { }; |
| 2060 | struct nfs4_state *res; |
| 2061 | int status; |
| 2062 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2063 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2065 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2066 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | if (status == 0) |
| 2068 | break; |
| 2069 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2070 | * book-keeping w.r.t. state-changing operations |
| 2071 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2072 | * It is actually a sign of a bug on the client or on the server. |
| 2073 | * |
| 2074 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2075 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | * have unhashed the old state_owner for us, and that we can |
| 2077 | * therefore safely retry using a new one. We should still warn |
| 2078 | * the user though... |
| 2079 | */ |
| 2080 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2081 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2082 | " returned a bad sequence-id error!\n", |
| 2083 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | exception.retry = 1; |
| 2085 | continue; |
| 2086 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2087 | /* |
| 2088 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2089 | * state before it received the OPEN_CONFIRM. |
| 2090 | * Recover by retrying the request as per the discussion |
| 2091 | * on Page 181 of RFC3530. |
| 2092 | */ |
| 2093 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2094 | exception.retry = 1; |
| 2095 | continue; |
| 2096 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2097 | if (status == -EAGAIN) { |
| 2098 | /* We must have found a delegation */ |
| 2099 | exception.retry = 1; |
| 2100 | continue; |
| 2101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2103 | status, &exception)); |
| 2104 | } while (exception.retry); |
| 2105 | return res; |
| 2106 | } |
| 2107 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2108 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2109 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2110 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2112 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2114 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | .iap = sattr, |
| 2116 | .server = server, |
| 2117 | .bitmask = server->attr_bitmask, |
| 2118 | }; |
| 2119 | struct nfs_setattrres res = { |
| 2120 | .fattr = fattr, |
| 2121 | .server = server, |
| 2122 | }; |
| 2123 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2125 | .rpc_argp = &arg, |
| 2126 | .rpc_resp = &res, |
| 2127 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2129 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2130 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2132 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2134 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2135 | struct nfs_lockowner lockowner = { |
| 2136 | .l_owner = current->files, |
| 2137 | .l_pid = current->tgid, |
| 2138 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2139 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2140 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2141 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2142 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2143 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2144 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2145 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2147 | 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] | 2148 | if (status == 0 && state != NULL) |
| 2149 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2150 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2153 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2154 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2155 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2157 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2158 | struct nfs4_exception exception = { |
| 2159 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2160 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2161 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | int err; |
| 2163 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2164 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2165 | switch (err) { |
| 2166 | case -NFS4ERR_OPENMODE: |
| 2167 | if (state && !(state->state & FMODE_WRITE)) { |
| 2168 | err = -EBADF; |
| 2169 | if (sattr->ia_valid & ATTR_OPEN) |
| 2170 | err = -EACCES; |
| 2171 | goto out; |
| 2172 | } |
| 2173 | } |
| 2174 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2176 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | return err; |
| 2178 | } |
| 2179 | |
| 2180 | struct nfs4_closedata { |
| 2181 | struct inode *inode; |
| 2182 | struct nfs4_state *state; |
| 2183 | struct nfs_closeargs arg; |
| 2184 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2185 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2186 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2187 | bool roc; |
| 2188 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | }; |
| 2190 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2191 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2192 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2193 | struct nfs4_closedata *calldata = data; |
| 2194 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2195 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2196 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2197 | if (calldata->roc) |
| 2198 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2199 | nfs4_put_open_state(calldata->state); |
| 2200 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2201 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2202 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2203 | kfree(calldata); |
| 2204 | } |
| 2205 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2206 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2207 | fmode_t fmode) |
| 2208 | { |
| 2209 | spin_lock(&state->owner->so_lock); |
| 2210 | if (!(fmode & FMODE_READ)) |
| 2211 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2212 | if (!(fmode & FMODE_WRITE)) |
| 2213 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2214 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2215 | spin_unlock(&state->owner->so_lock); |
| 2216 | } |
| 2217 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2218 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2220 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2223 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2224 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2225 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2226 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | /* hmm. we are done with the inode, and in the process of freeing |
| 2228 | * the state_owner. we keep this around to process errors |
| 2229 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | switch (task->tk_status) { |
| 2231 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2232 | if (calldata->roc) |
| 2233 | pnfs_roc_set_barrier(state->inode, |
| 2234 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2235 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2236 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2237 | nfs4_close_clear_stateid_flags(state, |
| 2238 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | break; |
| 2240 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2241 | case -NFS4ERR_OLD_STATEID: |
| 2242 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2244 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2245 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2247 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2248 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2250 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2251 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2252 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2255 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2257 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2258 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2259 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2260 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2261 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2262 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2263 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2264 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2265 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2266 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2267 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2268 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2269 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2270 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2271 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2272 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2273 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2274 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2275 | } |
| 2276 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2277 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2278 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2279 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2280 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2281 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2282 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2283 | |
| 2284 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2285 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2286 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2287 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2288 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2289 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2290 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2291 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2292 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2293 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2294 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2295 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2296 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2297 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2298 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2299 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2300 | &calldata->arg.seq_args, |
| 2301 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2302 | task) != 0) |
| 2303 | nfs_release_seqid(calldata->arg.seqid); |
| 2304 | else |
| 2305 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2306 | out: |
| 2307 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2310 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2311 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2312 | .rpc_call_done = nfs4_close_done, |
| 2313 | .rpc_release = nfs4_free_closedata, |
| 2314 | }; |
| 2315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | /* |
| 2317 | * It is possible for data to be read/written from a mem-mapped file |
| 2318 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2319 | * This means that we can't safely call nfsv4 close on a file until |
| 2320 | * the inode is cleared. This in turn means that we are not good |
| 2321 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2322 | * share state even when we are done with one of the three share |
| 2323 | * stateid's in the inode. |
| 2324 | * |
| 2325 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2326 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2327 | 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] | 2328 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2329 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2331 | struct nfs4_state_owner *sp = state->owner; |
| 2332 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2333 | struct rpc_message msg = { |
| 2334 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2335 | .rpc_cred = state->owner->so_cred, |
| 2336 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2337 | struct rpc_task_setup task_setup_data = { |
| 2338 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2339 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2340 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2341 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2342 | .flags = RPC_TASK_ASYNC, |
| 2343 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2344 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2346 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2348 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2349 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2350 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2352 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2353 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2355 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2356 | if (calldata->arg.seqid == NULL) |
| 2357 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2358 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2359 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2360 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2361 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2362 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2363 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2364 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2365 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2366 | msg.rpc_argp = &calldata->arg; |
| 2367 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2368 | task_setup_data.callback_data = calldata; |
| 2369 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2370 | if (IS_ERR(task)) |
| 2371 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2372 | status = 0; |
| 2373 | if (wait) |
| 2374 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2375 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2376 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2377 | out_free_calldata: |
| 2378 | kfree(calldata); |
| 2379 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2380 | nfs4_put_open_state(state); |
| 2381 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2382 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2385 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2386 | 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] | 2387 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | struct nfs4_state *state; |
| 2389 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2390 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2391 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2392 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2393 | if (IS_ERR(state)) |
| 2394 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2395 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2396 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2399 | 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] | 2400 | { |
| 2401 | if (ctx->state == NULL) |
| 2402 | return; |
| 2403 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2404 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2405 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2406 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | |
| 2409 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2410 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2411 | struct nfs4_server_caps_arg args = { |
| 2412 | .fhandle = fhandle, |
| 2413 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | struct nfs4_server_caps_res res = {}; |
| 2415 | struct rpc_message msg = { |
| 2416 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2417 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | .rpc_resp = &res, |
| 2419 | }; |
| 2420 | int status; |
| 2421 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2422 | 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] | 2423 | if (status == 0) { |
| 2424 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2425 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2426 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2427 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2428 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2429 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2431 | server->caps |= NFS_CAP_ACLS; |
| 2432 | if (res.has_links != 0) |
| 2433 | server->caps |= NFS_CAP_HARDLINKS; |
| 2434 | if (res.has_symlinks != 0) |
| 2435 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2436 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2437 | server->caps |= NFS_CAP_FILEID; |
| 2438 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2439 | server->caps |= NFS_CAP_MODE; |
| 2440 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2441 | server->caps |= NFS_CAP_NLINK; |
| 2442 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2443 | server->caps |= NFS_CAP_OWNER; |
| 2444 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2445 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2446 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2447 | server->caps |= NFS_CAP_ATIME; |
| 2448 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2449 | server->caps |= NFS_CAP_CTIME; |
| 2450 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2451 | server->caps |= NFS_CAP_MTIME; |
| 2452 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2453 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2454 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2455 | 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] | 2456 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2457 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | return status; |
| 2461 | } |
| 2462 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2463 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | { |
| 2465 | struct nfs4_exception exception = { }; |
| 2466 | int err; |
| 2467 | do { |
| 2468 | err = nfs4_handle_exception(server, |
| 2469 | _nfs4_server_capabilities(server, fhandle), |
| 2470 | &exception); |
| 2471 | } while (exception.retry); |
| 2472 | return err; |
| 2473 | } |
| 2474 | |
| 2475 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2476 | struct nfs_fsinfo *info) |
| 2477 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | struct nfs4_lookup_root_arg args = { |
| 2479 | .bitmask = nfs4_fattr_bitmap, |
| 2480 | }; |
| 2481 | struct nfs4_lookup_res res = { |
| 2482 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2483 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | .fh = fhandle, |
| 2485 | }; |
| 2486 | struct rpc_message msg = { |
| 2487 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2488 | .rpc_argp = &args, |
| 2489 | .rpc_resp = &res, |
| 2490 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2491 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2492 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2493 | 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] | 2494 | } |
| 2495 | |
| 2496 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2497 | struct nfs_fsinfo *info) |
| 2498 | { |
| 2499 | struct nfs4_exception exception = { }; |
| 2500 | int err; |
| 2501 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2502 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2503 | switch (err) { |
| 2504 | case 0: |
| 2505 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2506 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2507 | default: |
| 2508 | err = nfs4_handle_exception(server, err, &exception); |
| 2509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2511 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | return err; |
| 2513 | } |
| 2514 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2515 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2516 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2517 | { |
| 2518 | struct rpc_auth *auth; |
| 2519 | int ret; |
| 2520 | |
| 2521 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2522 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2523 | ret = -EIO; |
| 2524 | goto out; |
| 2525 | } |
| 2526 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2527 | out: |
| 2528 | return ret; |
| 2529 | } |
| 2530 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2531 | 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] | 2532 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2534 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2535 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2537 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2538 | if (len < 0) |
| 2539 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2540 | |
| 2541 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2542 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2543 | * thus has already been tried. */ |
| 2544 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2545 | continue; |
| 2546 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2547 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2548 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2549 | continue; |
| 2550 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2551 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2552 | /* |
| 2553 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2554 | * to access the mount. It could also mean that we tried to mount |
| 2555 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2556 | * existing mount programs don't handle -EACCES very well so it should |
| 2557 | * be mapped to -EPERM instead. |
| 2558 | */ |
| 2559 | if (status == -EACCES) |
| 2560 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2561 | return status; |
| 2562 | } |
| 2563 | |
| 2564 | /* |
| 2565 | * get the file handle for the "/" directory on the server |
| 2566 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2567 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2568 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2569 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2570 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2571 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2572 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2573 | /* |
| 2574 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2575 | * by nfs4_map_errors() as this function exits. |
| 2576 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2577 | 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] | 2578 | if (status == 0) |
| 2579 | status = nfs4_server_capabilities(server, fhandle); |
| 2580 | if (status == 0) |
| 2581 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2582 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2585 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2586 | struct nfs_fsinfo *info) |
| 2587 | { |
| 2588 | int error; |
| 2589 | struct nfs_fattr *fattr = info->fattr; |
| 2590 | |
| 2591 | error = nfs4_server_capabilities(server, mntfh); |
| 2592 | if (error < 0) { |
| 2593 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2594 | return error; |
| 2595 | } |
| 2596 | |
| 2597 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2598 | if (error < 0) { |
| 2599 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2600 | return error; |
| 2601 | } |
| 2602 | |
| 2603 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2604 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2605 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2606 | |
| 2607 | return error; |
| 2608 | } |
| 2609 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2610 | /* |
| 2611 | * Get locations and (maybe) other attributes of a referral. |
| 2612 | * Note that we'll actually follow the referral later when |
| 2613 | * we detect fsid mismatch in inode revalidation |
| 2614 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2615 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2616 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2617 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2618 | { |
| 2619 | int status = -ENOMEM; |
| 2620 | struct page *page = NULL; |
| 2621 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2622 | |
| 2623 | page = alloc_page(GFP_KERNEL); |
| 2624 | if (page == NULL) |
| 2625 | goto out; |
| 2626 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2627 | if (locations == NULL) |
| 2628 | goto out; |
| 2629 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2630 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2631 | if (status != 0) |
| 2632 | goto out; |
| 2633 | /* Make sure server returned a different fsid for the referral */ |
| 2634 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2635 | dprintk("%s: server did not return a different fsid for" |
| 2636 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2637 | status = -EIO; |
| 2638 | goto out; |
| 2639 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2640 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2641 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2642 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2643 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2644 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2645 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2646 | out: |
| 2647 | if (page) |
| 2648 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2649 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2650 | return status; |
| 2651 | } |
| 2652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2654 | { |
| 2655 | struct nfs4_getattr_arg args = { |
| 2656 | .fh = fhandle, |
| 2657 | .bitmask = server->attr_bitmask, |
| 2658 | }; |
| 2659 | struct nfs4_getattr_res res = { |
| 2660 | .fattr = fattr, |
| 2661 | .server = server, |
| 2662 | }; |
| 2663 | struct rpc_message msg = { |
| 2664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2665 | .rpc_argp = &args, |
| 2666 | .rpc_resp = &res, |
| 2667 | }; |
| 2668 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2669 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2670 | 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] | 2671 | } |
| 2672 | |
| 2673 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2674 | { |
| 2675 | struct nfs4_exception exception = { }; |
| 2676 | int err; |
| 2677 | do { |
| 2678 | err = nfs4_handle_exception(server, |
| 2679 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2680 | &exception); |
| 2681 | } while (exception.retry); |
| 2682 | return err; |
| 2683 | } |
| 2684 | |
| 2685 | /* |
| 2686 | * The file is not closed if it is opened due to the a request to change |
| 2687 | * the size of the file. The open call will not be needed once the |
| 2688 | * VFS layer lookup-intents are implemented. |
| 2689 | * |
| 2690 | * Close is called when the inode is destroyed. |
| 2691 | * If we haven't opened the file for O_WRONLY, we |
| 2692 | * need to in the size_change case to obtain a stateid. |
| 2693 | * |
| 2694 | * Got race? |
| 2695 | * Because OPEN is always done by name in nfsv4, it is |
| 2696 | * possible that we opened a different file by the same |
| 2697 | * name. We can recognize this race condition, but we |
| 2698 | * can't do anything about it besides returning an error. |
| 2699 | * |
| 2700 | * This will be fixed with VFS changes (lookup-intent). |
| 2701 | */ |
| 2702 | static int |
| 2703 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2704 | struct iattr *sattr) |
| 2705 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2706 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2707 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2708 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | int status; |
| 2710 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2711 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2712 | pnfs_return_layout(inode); |
| 2713 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2714 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2716 | /* Deal with open(O_TRUNC) */ |
| 2717 | if (sattr->ia_valid & ATTR_OPEN) |
| 2718 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2719 | |
| 2720 | /* Optimization: if the end result is no change, don't RPC */ |
| 2721 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2722 | return 0; |
| 2723 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2724 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2725 | if (sattr->ia_valid & ATTR_FILE) { |
| 2726 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2727 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2728 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2729 | if (ctx) { |
| 2730 | cred = ctx->cred; |
| 2731 | state = ctx->state; |
| 2732 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2736 | if (status == 0) |
| 2737 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | return status; |
| 2739 | } |
| 2740 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2741 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2742 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2743 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2744 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2745 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2746 | int status; |
| 2747 | struct nfs4_lookup_arg args = { |
| 2748 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2749 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2750 | .name = name, |
| 2751 | }; |
| 2752 | struct nfs4_lookup_res res = { |
| 2753 | .server = server, |
| 2754 | .fattr = fattr, |
| 2755 | .fh = fhandle, |
| 2756 | }; |
| 2757 | struct rpc_message msg = { |
| 2758 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2759 | .rpc_argp = &args, |
| 2760 | .rpc_resp = &res, |
| 2761 | }; |
| 2762 | |
| 2763 | nfs_fattr_init(fattr); |
| 2764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2766 | 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] | 2767 | dprintk("NFS reply lookup: %d\n", status); |
| 2768 | return status; |
| 2769 | } |
| 2770 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2771 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2772 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2773 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2774 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2775 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2776 | fattr->nlink = 2; |
| 2777 | } |
| 2778 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2779 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2780 | struct qstr *name, struct nfs_fh *fhandle, |
| 2781 | struct nfs_fattr *fattr) |
| 2782 | { |
| 2783 | struct nfs4_exception exception = { }; |
| 2784 | struct rpc_clnt *client = *clnt; |
| 2785 | int err; |
| 2786 | do { |
| 2787 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2788 | switch (err) { |
| 2789 | case -NFS4ERR_BADNAME: |
| 2790 | err = -ENOENT; |
| 2791 | goto out; |
| 2792 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2793 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2794 | goto out; |
| 2795 | case -NFS4ERR_WRONGSEC: |
| 2796 | err = -EPERM; |
| 2797 | if (client != *clnt) |
| 2798 | goto out; |
| 2799 | |
| 2800 | client = nfs4_create_sec_client(client, dir, name); |
| 2801 | if (IS_ERR(client)) |
| 2802 | return PTR_ERR(client); |
| 2803 | |
| 2804 | exception.retry = 1; |
| 2805 | break; |
| 2806 | default: |
| 2807 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2808 | } |
| 2809 | } while (exception.retry); |
| 2810 | |
| 2811 | out: |
| 2812 | if (err == 0) |
| 2813 | *clnt = client; |
| 2814 | else if (client != *clnt) |
| 2815 | rpc_shutdown_client(client); |
| 2816 | |
| 2817 | return err; |
| 2818 | } |
| 2819 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2820 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2821 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2823 | int status; |
| 2824 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2825 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2826 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2827 | if (client != NFS_CLIENT(dir)) { |
| 2828 | rpc_shutdown_client(client); |
| 2829 | nfs_fixup_secinfo_attributes(fattr); |
| 2830 | } |
| 2831 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2834 | struct rpc_clnt * |
| 2835 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2836 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2837 | { |
| 2838 | int status; |
| 2839 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2840 | |
| 2841 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2842 | if (status < 0) { |
| 2843 | rpc_shutdown_client(client); |
| 2844 | return ERR_PTR(status); |
| 2845 | } |
| 2846 | return client; |
| 2847 | } |
| 2848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2850 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2851 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | struct nfs4_accessargs args = { |
| 2853 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2854 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2856 | struct nfs4_accessres res = { |
| 2857 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2858 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | struct rpc_message msg = { |
| 2860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2861 | .rpc_argp = &args, |
| 2862 | .rpc_resp = &res, |
| 2863 | .rpc_cred = entry->cred, |
| 2864 | }; |
| 2865 | int mode = entry->mask; |
| 2866 | int status; |
| 2867 | |
| 2868 | /* |
| 2869 | * Determine which access bits we want to ask for... |
| 2870 | */ |
| 2871 | if (mode & MAY_READ) |
| 2872 | args.access |= NFS4_ACCESS_READ; |
| 2873 | if (S_ISDIR(inode->i_mode)) { |
| 2874 | if (mode & MAY_WRITE) |
| 2875 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2876 | if (mode & MAY_EXEC) |
| 2877 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2878 | } else { |
| 2879 | if (mode & MAY_WRITE) |
| 2880 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2881 | if (mode & MAY_EXEC) |
| 2882 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2883 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2884 | |
| 2885 | res.fattr = nfs_alloc_fattr(); |
| 2886 | if (res.fattr == NULL) |
| 2887 | return -ENOMEM; |
| 2888 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2889 | 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] | 2890 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2891 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2892 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2894 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | return status; |
| 2896 | } |
| 2897 | |
| 2898 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2899 | { |
| 2900 | struct nfs4_exception exception = { }; |
| 2901 | int err; |
| 2902 | do { |
| 2903 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2904 | _nfs4_proc_access(inode, entry), |
| 2905 | &exception); |
| 2906 | } while (exception.retry); |
| 2907 | return err; |
| 2908 | } |
| 2909 | |
| 2910 | /* |
| 2911 | * TODO: For the time being, we don't try to get any attributes |
| 2912 | * along with any of the zero-copy operations READ, READDIR, |
| 2913 | * READLINK, WRITE. |
| 2914 | * |
| 2915 | * In the case of the first three, we want to put the GETATTR |
| 2916 | * after the read-type operation -- this is because it is hard |
| 2917 | * to predict the length of a GETATTR response in v4, and thus |
| 2918 | * align the READ data correctly. This means that the GETATTR |
| 2919 | * may end up partially falling into the page cache, and we should |
| 2920 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2921 | * To do this efficiently, we need to know the total length |
| 2922 | * of data received, which doesn't seem to be available outside |
| 2923 | * of the RPC layer. |
| 2924 | * |
| 2925 | * In the case of WRITE, we also want to put the GETATTR after |
| 2926 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2927 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | * |
| 2929 | * Both of these changes to the XDR layer would in fact be quite |
| 2930 | * minor, but I decided to leave them for a subsequent patch. |
| 2931 | */ |
| 2932 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2933 | unsigned int pgbase, unsigned int pglen) |
| 2934 | { |
| 2935 | struct nfs4_readlink args = { |
| 2936 | .fh = NFS_FH(inode), |
| 2937 | .pgbase = pgbase, |
| 2938 | .pglen = pglen, |
| 2939 | .pages = &page, |
| 2940 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2941 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | struct rpc_message msg = { |
| 2943 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2944 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2945 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | }; |
| 2947 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2948 | 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] | 2949 | } |
| 2950 | |
| 2951 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2952 | unsigned int pgbase, unsigned int pglen) |
| 2953 | { |
| 2954 | struct nfs4_exception exception = { }; |
| 2955 | int err; |
| 2956 | do { |
| 2957 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2958 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2959 | &exception); |
| 2960 | } while (exception.retry); |
| 2961 | return err; |
| 2962 | } |
| 2963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2965 | * 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] | 2966 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | static int |
| 2968 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2969 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2971 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | int status = 0; |
| 2974 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2975 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2976 | if (IS_ERR(ctx)) |
| 2977 | return PTR_ERR(ctx); |
| 2978 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2979 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2980 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2981 | flags, sattr, ctx->cred, |
| 2982 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2983 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | if (IS_ERR(state)) { |
| 2985 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2986 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2988 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2989 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2990 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2992 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | return status; |
| 2994 | } |
| 2995 | |
| 2996 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2997 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2998 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2999 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3001 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3003 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3004 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3005 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3008 | .rpc_argp = &args, |
| 3009 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3011 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3012 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3013 | 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] | 3014 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3015 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | return status; |
| 3017 | } |
| 3018 | |
| 3019 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3020 | { |
| 3021 | struct nfs4_exception exception = { }; |
| 3022 | int err; |
| 3023 | do { |
| 3024 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3025 | _nfs4_proc_remove(dir, name), |
| 3026 | &exception); |
| 3027 | } while (exception.retry); |
| 3028 | return err; |
| 3029 | } |
| 3030 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3031 | 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] | 3032 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3033 | struct nfs_server *server = NFS_SERVER(dir); |
| 3034 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3035 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3037 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3039 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3042 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3043 | { |
| 3044 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3045 | &data->args.seq_args, |
| 3046 | &data->res.seq_res, |
| 3047 | task)) |
| 3048 | return; |
| 3049 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | } |
| 3051 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3052 | 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] | 3053 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3054 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3055 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3056 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3057 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3058 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3059 | return 0; |
| 3060 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3061 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3064 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3065 | { |
| 3066 | struct nfs_server *server = NFS_SERVER(dir); |
| 3067 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3068 | struct nfs_renameres *res = msg->rpc_resp; |
| 3069 | |
| 3070 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3071 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3072 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3073 | } |
| 3074 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3075 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3076 | { |
| 3077 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3078 | &data->args.seq_args, |
| 3079 | &data->res.seq_res, |
| 3080 | task)) |
| 3081 | return; |
| 3082 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3086 | struct inode *new_dir) |
| 3087 | { |
| 3088 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3089 | |
| 3090 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3091 | return 0; |
| 3092 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3093 | return 0; |
| 3094 | |
| 3095 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3096 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3097 | return 1; |
| 3098 | } |
| 3099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3101 | struct inode *new_dir, struct qstr *new_name) |
| 3102 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3103 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3104 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | .old_dir = NFS_FH(old_dir), |
| 3106 | .new_dir = NFS_FH(new_dir), |
| 3107 | .old_name = old_name, |
| 3108 | .new_name = new_name, |
| 3109 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3110 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3111 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3112 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | struct rpc_message msg = { |
| 3114 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3115 | .rpc_argp = &arg, |
| 3116 | .rpc_resp = &res, |
| 3117 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3118 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3120 | 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] | 3121 | if (!status) { |
| 3122 | update_changeattr(old_dir, &res.old_cinfo); |
| 3123 | update_changeattr(new_dir, &res.new_cinfo); |
| 3124 | } |
| 3125 | return status; |
| 3126 | } |
| 3127 | |
| 3128 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3129 | struct inode *new_dir, struct qstr *new_name) |
| 3130 | { |
| 3131 | struct nfs4_exception exception = { }; |
| 3132 | int err; |
| 3133 | do { |
| 3134 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3135 | _nfs4_proc_rename(old_dir, old_name, |
| 3136 | new_dir, new_name), |
| 3137 | &exception); |
| 3138 | } while (exception.retry); |
| 3139 | return err; |
| 3140 | } |
| 3141 | |
| 3142 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3143 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3144 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | struct nfs4_link_arg arg = { |
| 3146 | .fh = NFS_FH(inode), |
| 3147 | .dir_fh = NFS_FH(dir), |
| 3148 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3149 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3151 | struct nfs4_link_res res = { |
| 3152 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3153 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | struct rpc_message msg = { |
| 3155 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3156 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3157 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3159 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3161 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3162 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3163 | goto out; |
| 3164 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3165 | 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] | 3166 | if (!status) { |
| 3167 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3168 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3169 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3170 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3171 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | return status; |
| 3173 | } |
| 3174 | |
| 3175 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3176 | { |
| 3177 | struct nfs4_exception exception = { }; |
| 3178 | int err; |
| 3179 | do { |
| 3180 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3181 | _nfs4_proc_link(inode, dir, name), |
| 3182 | &exception); |
| 3183 | } while (exception.retry); |
| 3184 | return err; |
| 3185 | } |
| 3186 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3187 | struct nfs4_createdata { |
| 3188 | struct rpc_message msg; |
| 3189 | struct nfs4_create_arg arg; |
| 3190 | struct nfs4_create_res res; |
| 3191 | struct nfs_fh fh; |
| 3192 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3193 | }; |
| 3194 | |
| 3195 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3196 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3197 | { |
| 3198 | struct nfs4_createdata *data; |
| 3199 | |
| 3200 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3201 | if (data != NULL) { |
| 3202 | struct nfs_server *server = NFS_SERVER(dir); |
| 3203 | |
| 3204 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3205 | data->msg.rpc_argp = &data->arg; |
| 3206 | data->msg.rpc_resp = &data->res; |
| 3207 | data->arg.dir_fh = NFS_FH(dir); |
| 3208 | data->arg.server = server; |
| 3209 | data->arg.name = name; |
| 3210 | data->arg.attrs = sattr; |
| 3211 | data->arg.ftype = ftype; |
| 3212 | data->arg.bitmask = server->attr_bitmask; |
| 3213 | data->res.server = server; |
| 3214 | data->res.fh = &data->fh; |
| 3215 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3216 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3217 | } |
| 3218 | return data; |
| 3219 | } |
| 3220 | |
| 3221 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3222 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3223 | 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] | 3224 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3225 | if (status == 0) { |
| 3226 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3227 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3228 | } |
| 3229 | return status; |
| 3230 | } |
| 3231 | |
| 3232 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3233 | { |
| 3234 | kfree(data); |
| 3235 | } |
| 3236 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3237 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3238 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3240 | struct nfs4_createdata *data; |
| 3241 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3243 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3244 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3245 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3246 | status = -ENOMEM; |
| 3247 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3248 | if (data == NULL) |
| 3249 | goto out; |
| 3250 | |
| 3251 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3252 | data->arg.u.symlink.pages = &page; |
| 3253 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3255 | status = nfs4_do_create(dir, dentry, data); |
| 3256 | |
| 3257 | nfs4_free_createdata(data); |
| 3258 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | return status; |
| 3260 | } |
| 3261 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3262 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3263 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | { |
| 3265 | struct nfs4_exception exception = { }; |
| 3266 | int err; |
| 3267 | do { |
| 3268 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3269 | _nfs4_proc_symlink(dir, dentry, page, |
| 3270 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | &exception); |
| 3272 | } while (exception.retry); |
| 3273 | return err; |
| 3274 | } |
| 3275 | |
| 3276 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3277 | struct iattr *sattr) |
| 3278 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3279 | struct nfs4_createdata *data; |
| 3280 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3282 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3283 | if (data == NULL) |
| 3284 | goto out; |
| 3285 | |
| 3286 | status = nfs4_do_create(dir, dentry, data); |
| 3287 | |
| 3288 | nfs4_free_createdata(data); |
| 3289 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | return status; |
| 3291 | } |
| 3292 | |
| 3293 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3294 | struct iattr *sattr) |
| 3295 | { |
| 3296 | struct nfs4_exception exception = { }; |
| 3297 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3298 | |
| 3299 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | do { |
| 3301 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3302 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3303 | &exception); |
| 3304 | } while (exception.retry); |
| 3305 | return err; |
| 3306 | } |
| 3307 | |
| 3308 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3309 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | { |
| 3311 | struct inode *dir = dentry->d_inode; |
| 3312 | struct nfs4_readdir_arg args = { |
| 3313 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3314 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | .pgbase = 0, |
| 3316 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3317 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3318 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | }; |
| 3320 | struct nfs4_readdir_res res; |
| 3321 | struct rpc_message msg = { |
| 3322 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3323 | .rpc_argp = &args, |
| 3324 | .rpc_resp = &res, |
| 3325 | .rpc_cred = cred, |
| 3326 | }; |
| 3327 | int status; |
| 3328 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3329 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3330 | dentry->d_parent->d_name.name, |
| 3331 | dentry->d_name.name, |
| 3332 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3333 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3335 | 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] | 3336 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3337 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3338 | status += args.pgbase; |
| 3339 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3340 | |
| 3341 | nfs_invalidate_atime(dir); |
| 3342 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3343 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | return status; |
| 3345 | } |
| 3346 | |
| 3347 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3348 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | { |
| 3350 | struct nfs4_exception exception = { }; |
| 3351 | int err; |
| 3352 | do { |
| 3353 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3354 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3355 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | &exception); |
| 3357 | } while (exception.retry); |
| 3358 | return err; |
| 3359 | } |
| 3360 | |
| 3361 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3362 | struct iattr *sattr, dev_t rdev) |
| 3363 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3364 | struct nfs4_createdata *data; |
| 3365 | int mode = sattr->ia_mode; |
| 3366 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3368 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3369 | if (data == NULL) |
| 3370 | goto out; |
| 3371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3373 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3375 | data->arg.ftype = NF4BLK; |
| 3376 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3377 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | } |
| 3379 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3380 | data->arg.ftype = NF4CHR; |
| 3381 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3382 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3383 | } else if (!S_ISSOCK(mode)) { |
| 3384 | status = -EINVAL; |
| 3385 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3388 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3389 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3390 | nfs4_free_createdata(data); |
| 3391 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | return status; |
| 3393 | } |
| 3394 | |
| 3395 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3396 | struct iattr *sattr, dev_t rdev) |
| 3397 | { |
| 3398 | struct nfs4_exception exception = { }; |
| 3399 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3400 | |
| 3401 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | do { |
| 3403 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3404 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3405 | &exception); |
| 3406 | } while (exception.retry); |
| 3407 | return err; |
| 3408 | } |
| 3409 | |
| 3410 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3411 | struct nfs_fsstat *fsstat) |
| 3412 | { |
| 3413 | struct nfs4_statfs_arg args = { |
| 3414 | .fh = fhandle, |
| 3415 | .bitmask = server->attr_bitmask, |
| 3416 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3417 | struct nfs4_statfs_res res = { |
| 3418 | .fsstat = fsstat, |
| 3419 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | struct rpc_message msg = { |
| 3421 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3422 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3423 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | }; |
| 3425 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3426 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3427 | 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] | 3428 | } |
| 3429 | |
| 3430 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3431 | { |
| 3432 | struct nfs4_exception exception = { }; |
| 3433 | int err; |
| 3434 | do { |
| 3435 | err = nfs4_handle_exception(server, |
| 3436 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3437 | &exception); |
| 3438 | } while (exception.retry); |
| 3439 | return err; |
| 3440 | } |
| 3441 | |
| 3442 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3443 | struct nfs_fsinfo *fsinfo) |
| 3444 | { |
| 3445 | struct nfs4_fsinfo_arg args = { |
| 3446 | .fh = fhandle, |
| 3447 | .bitmask = server->attr_bitmask, |
| 3448 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3449 | struct nfs4_fsinfo_res res = { |
| 3450 | .fsinfo = fsinfo, |
| 3451 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | struct rpc_message msg = { |
| 3453 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3454 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3455 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | }; |
| 3457 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3458 | 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] | 3459 | } |
| 3460 | |
| 3461 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3462 | { |
| 3463 | struct nfs4_exception exception = { }; |
| 3464 | int err; |
| 3465 | |
| 3466 | do { |
| 3467 | err = nfs4_handle_exception(server, |
| 3468 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3469 | &exception); |
| 3470 | } while (exception.retry); |
| 3471 | return err; |
| 3472 | } |
| 3473 | |
| 3474 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3475 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3476 | int error; |
| 3477 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3478 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3479 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3480 | if (error == 0) { |
| 3481 | /* block layout checks this! */ |
| 3482 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3483 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3484 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3485 | |
| 3486 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3490 | struct nfs_pathconf *pathconf) |
| 3491 | { |
| 3492 | struct nfs4_pathconf_arg args = { |
| 3493 | .fh = fhandle, |
| 3494 | .bitmask = server->attr_bitmask, |
| 3495 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3496 | struct nfs4_pathconf_res res = { |
| 3497 | .pathconf = pathconf, |
| 3498 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | struct rpc_message msg = { |
| 3500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3501 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3502 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | }; |
| 3504 | |
| 3505 | /* None of the pathconf attributes are mandatory to implement */ |
| 3506 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3507 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3508 | return 0; |
| 3509 | } |
| 3510 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3511 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3512 | 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] | 3513 | } |
| 3514 | |
| 3515 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3516 | struct nfs_pathconf *pathconf) |
| 3517 | { |
| 3518 | struct nfs4_exception exception = { }; |
| 3519 | int err; |
| 3520 | |
| 3521 | do { |
| 3522 | err = nfs4_handle_exception(server, |
| 3523 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3524 | &exception); |
| 3525 | } while (exception.retry); |
| 3526 | return err; |
| 3527 | } |
| 3528 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3529 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3530 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3531 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3532 | } |
| 3533 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3534 | 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] | 3535 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3536 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3538 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3539 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3540 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3542 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3543 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3545 | renew_lease(server, data->timestamp); |
| 3546 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3549 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3550 | { |
| 3551 | |
| 3552 | dprintk("--> %s\n", __func__); |
| 3553 | |
| 3554 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3555 | return -EAGAIN; |
| 3556 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3557 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3558 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3561 | 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] | 3562 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3564 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3565 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3566 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3569 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3570 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3571 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3572 | &data->args.seq_args, |
| 3573 | &data->res.seq_res, |
| 3574 | task)) |
| 3575 | return; |
| 3576 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3579 | 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] | 3580 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3581 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3583 | 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] | 3584 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3585 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3587 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3589 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3590 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3591 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3594 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3595 | { |
| 3596 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3597 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3598 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3599 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3602 | static |
| 3603 | 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] | 3604 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3605 | const struct nfs_pgio_header *hdr = data->header; |
| 3606 | |
| 3607 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3608 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3609 | return false; |
| 3610 | /* Otherwise, request attributes if and only if we don't hold |
| 3611 | * a delegation |
| 3612 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3613 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3614 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3615 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3616 | 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] | 3617 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3618 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3619 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3620 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3621 | data->args.bitmask = NULL; |
| 3622 | data->res.fattr = NULL; |
| 3623 | } else |
| 3624 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3625 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3626 | if (!data->write_done_cb) |
| 3627 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3628 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | data->timestamp = jiffies; |
| 3630 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3631 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3632 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | } |
| 3634 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3635 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3636 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3637 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3638 | &data->args.seq_args, |
| 3639 | &data->res.seq_res, |
| 3640 | task)) |
| 3641 | return; |
| 3642 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3645 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3646 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3648 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3649 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | return; |
| 3652 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3653 | } |
| 3654 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3655 | 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] | 3656 | { |
| 3657 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3658 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3659 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3660 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3661 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3663 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3666 | 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] | 3667 | { |
| 3668 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3669 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3670 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3671 | } |
| 3672 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3673 | 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] | 3674 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3675 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3676 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3677 | if (data->commit_done_cb == NULL) |
| 3678 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3679 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3680 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3681 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3684 | struct nfs4_renewdata { |
| 3685 | struct nfs_client *client; |
| 3686 | unsigned long timestamp; |
| 3687 | }; |
| 3688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | /* |
| 3690 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3691 | * standalone procedure for queueing an asynchronous RENEW. |
| 3692 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3693 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3694 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3695 | struct nfs4_renewdata *data = calldata; |
| 3696 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3697 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3698 | if (atomic_read(&clp->cl_count) > 1) |
| 3699 | nfs4_schedule_state_renewal(clp); |
| 3700 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3701 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3704 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3706 | struct nfs4_renewdata *data = calldata; |
| 3707 | struct nfs_client *clp = data->client; |
| 3708 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | |
| 3710 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3711 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3712 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3713 | return; |
| 3714 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3715 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3716 | return; |
| 3717 | } |
| 3718 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3720 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | } |
| 3722 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3723 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3724 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3725 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3726 | }; |
| 3727 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3728 | 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] | 3729 | { |
| 3730 | struct rpc_message msg = { |
| 3731 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3732 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3733 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3735 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3737 | if (renew_flags == 0) |
| 3738 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3739 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3740 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3741 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3742 | if (data == NULL) |
| 3743 | return -ENOMEM; |
| 3744 | data->client = clp; |
| 3745 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3747 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3750 | 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] | 3751 | { |
| 3752 | struct rpc_message msg = { |
| 3753 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3754 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3755 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | }; |
| 3757 | unsigned long now = jiffies; |
| 3758 | int status; |
| 3759 | |
| 3760 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3761 | if (status < 0) |
| 3762 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3763 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | return 0; |
| 3765 | } |
| 3766 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3767 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3768 | { |
| 3769 | return (server->caps & NFS_CAP_ACLS) |
| 3770 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3771 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3772 | } |
| 3773 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3774 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3775 | * 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] | 3776 | * the stack. |
| 3777 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3778 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3779 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3780 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3781 | struct page **pages, unsigned int *pgbase) |
| 3782 | { |
| 3783 | struct page *newpage, **spages; |
| 3784 | int rc = 0; |
| 3785 | size_t len; |
| 3786 | spages = pages; |
| 3787 | |
| 3788 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3789 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3790 | newpage = alloc_page(GFP_KERNEL); |
| 3791 | |
| 3792 | if (newpage == NULL) |
| 3793 | goto unwind; |
| 3794 | memcpy(page_address(newpage), buf, len); |
| 3795 | buf += len; |
| 3796 | buflen -= len; |
| 3797 | *pages++ = newpage; |
| 3798 | rc++; |
| 3799 | } while (buflen != 0); |
| 3800 | |
| 3801 | return rc; |
| 3802 | |
| 3803 | unwind: |
| 3804 | for(; rc > 0; rc--) |
| 3805 | __free_page(spages[rc-1]); |
| 3806 | return -ENOMEM; |
| 3807 | } |
| 3808 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3809 | struct nfs4_cached_acl { |
| 3810 | int cached; |
| 3811 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3812 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3813 | }; |
| 3814 | |
| 3815 | 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] | 3816 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3817 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3818 | |
| 3819 | spin_lock(&inode->i_lock); |
| 3820 | kfree(nfsi->nfs4_acl); |
| 3821 | nfsi->nfs4_acl = acl; |
| 3822 | spin_unlock(&inode->i_lock); |
| 3823 | } |
| 3824 | |
| 3825 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3826 | { |
| 3827 | nfs4_set_cached_acl(inode, NULL); |
| 3828 | } |
| 3829 | |
| 3830 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3831 | { |
| 3832 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3833 | struct nfs4_cached_acl *acl; |
| 3834 | int ret = -ENOENT; |
| 3835 | |
| 3836 | spin_lock(&inode->i_lock); |
| 3837 | acl = nfsi->nfs4_acl; |
| 3838 | if (acl == NULL) |
| 3839 | goto out; |
| 3840 | if (buf == NULL) /* user is just asking for length */ |
| 3841 | goto out_len; |
| 3842 | if (acl->cached == 0) |
| 3843 | goto out; |
| 3844 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3845 | if (acl->len > buflen) |
| 3846 | goto out; |
| 3847 | memcpy(buf, acl->data, acl->len); |
| 3848 | out_len: |
| 3849 | ret = acl->len; |
| 3850 | out: |
| 3851 | spin_unlock(&inode->i_lock); |
| 3852 | return ret; |
| 3853 | } |
| 3854 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3855 | 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] | 3856 | { |
| 3857 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3858 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3859 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3860 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3861 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3862 | if (acl == NULL) |
| 3863 | goto out; |
| 3864 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3865 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3866 | } else { |
| 3867 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3868 | if (acl == NULL) |
| 3869 | goto out; |
| 3870 | acl->cached = 0; |
| 3871 | } |
| 3872 | acl->len = acl_len; |
| 3873 | out: |
| 3874 | nfs4_set_cached_acl(inode, acl); |
| 3875 | } |
| 3876 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3877 | /* |
| 3878 | * The getxattr API returns the required buffer length when called with a |
| 3879 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3880 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3881 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3882 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3883 | * the cache. If not so, we throw away the page, and cache the required |
| 3884 | * length. The next getxattr call will then produce another round trip to |
| 3885 | * the server, this time with the input buf of the required size. |
| 3886 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3887 | 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] | 3888 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3889 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3890 | struct nfs_getaclargs args = { |
| 3891 | .fh = NFS_FH(inode), |
| 3892 | .acl_pages = pages, |
| 3893 | .acl_len = buflen, |
| 3894 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3895 | struct nfs_getaclres res = { |
| 3896 | .acl_len = buflen, |
| 3897 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3898 | struct rpc_message msg = { |
| 3899 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3900 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3901 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3902 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3903 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3904 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3905 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3906 | /* As long as we're doing a round trip to the server anyway, |
| 3907 | * let's be prepared for a page of acl data. */ |
| 3908 | if (npages == 0) |
| 3909 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3910 | if (npages > ARRAY_SIZE(pages)) |
| 3911 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3912 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3913 | for (i = 0; i < npages; i++) { |
| 3914 | pages[i] = alloc_page(GFP_KERNEL); |
| 3915 | if (!pages[i]) |
| 3916 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3917 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3918 | |
| 3919 | /* for decoding across pages */ |
| 3920 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3921 | if (!res.acl_scratch) |
| 3922 | goto out_free; |
| 3923 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3924 | args.acl_len = npages * PAGE_SIZE; |
| 3925 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3926 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3927 | 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] | 3928 | __func__, buf, buflen, npages, args.acl_len); |
| 3929 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3930 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3931 | if (ret) |
| 3932 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3933 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3934 | /* Handle the case where the passed-in buffer is too short */ |
| 3935 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3936 | /* Did the user only issue a request for the acl length? */ |
| 3937 | if (buf == NULL) |
| 3938 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3939 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3940 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3941 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3942 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3943 | if (buf) |
| 3944 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3945 | out_ok: |
| 3946 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3947 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3948 | for (i = 0; i < npages; i++) |
| 3949 | if (pages[i]) |
| 3950 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3951 | if (res.acl_scratch) |
| 3952 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3953 | return ret; |
| 3954 | } |
| 3955 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3956 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3957 | { |
| 3958 | struct nfs4_exception exception = { }; |
| 3959 | ssize_t ret; |
| 3960 | do { |
| 3961 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3962 | if (ret >= 0) |
| 3963 | break; |
| 3964 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3965 | } while (exception.retry); |
| 3966 | return ret; |
| 3967 | } |
| 3968 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3969 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3970 | { |
| 3971 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3972 | int ret; |
| 3973 | |
| 3974 | if (!nfs4_server_supports_acls(server)) |
| 3975 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3976 | ret = nfs_revalidate_inode(server, inode); |
| 3977 | if (ret < 0) |
| 3978 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3979 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3980 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3981 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3982 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3983 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3984 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3985 | return ret; |
| 3986 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3987 | } |
| 3988 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3989 | 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] | 3990 | { |
| 3991 | struct nfs_server *server = NFS_SERVER(inode); |
| 3992 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3993 | struct nfs_setaclargs arg = { |
| 3994 | .fh = NFS_FH(inode), |
| 3995 | .acl_pages = pages, |
| 3996 | .acl_len = buflen, |
| 3997 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3998 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3999 | struct rpc_message msg = { |
| 4000 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4001 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4002 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4003 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4004 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4005 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4006 | |
| 4007 | if (!nfs4_server_supports_acls(server)) |
| 4008 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4009 | if (npages > ARRAY_SIZE(pages)) |
| 4010 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4011 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4012 | if (i < 0) |
| 4013 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4014 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4015 | 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] | 4016 | |
| 4017 | /* |
| 4018 | * Free each page after tx, so the only ref left is |
| 4019 | * held by the network stack |
| 4020 | */ |
| 4021 | for (; i > 0; i--) |
| 4022 | put_page(pages[i-1]); |
| 4023 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4024 | /* |
| 4025 | * Acl update can result in inode attribute update. |
| 4026 | * so mark the attribute cache invalid. |
| 4027 | */ |
| 4028 | spin_lock(&inode->i_lock); |
| 4029 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4030 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4031 | nfs_access_zap_cache(inode); |
| 4032 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4033 | return ret; |
| 4034 | } |
| 4035 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4036 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4037 | { |
| 4038 | struct nfs4_exception exception = { }; |
| 4039 | int err; |
| 4040 | do { |
| 4041 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4042 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4043 | &exception); |
| 4044 | } while (exception.retry); |
| 4045 | return err; |
| 4046 | } |
| 4047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4049 | 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] | 4050 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4051 | struct nfs_client *clp = server->nfs_client; |
| 4052 | |
| 4053 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | return 0; |
| 4055 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4056 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4057 | case -NFS4ERR_ADMIN_REVOKED: |
| 4058 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4059 | if (state == NULL) |
| 4060 | break; |
| 4061 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4062 | case -NFS4ERR_OPENMODE: |
| 4063 | if (state == NULL) |
| 4064 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4065 | nfs4_schedule_stateid_recovery(server, state); |
| 4066 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4067 | case -NFS4ERR_EXPIRED: |
| 4068 | if (state != NULL) |
| 4069 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4071 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4072 | nfs4_schedule_lease_recovery(clp); |
| 4073 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4074 | #if defined(CONFIG_NFS_V4_1) |
| 4075 | case -NFS4ERR_BADSESSION: |
| 4076 | case -NFS4ERR_BADSLOT: |
| 4077 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4078 | case -NFS4ERR_DEADSESSION: |
| 4079 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4080 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4081 | case -NFS4ERR_SEQ_MISORDERED: |
| 4082 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4083 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4084 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4085 | task->tk_status = 0; |
| 4086 | return -EAGAIN; |
| 4087 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4089 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4090 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4091 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4093 | task->tk_status = 0; |
| 4094 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4095 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | case -NFS4ERR_OLD_STATEID: |
| 4097 | task->tk_status = 0; |
| 4098 | return -EAGAIN; |
| 4099 | } |
| 4100 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4101 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4102 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4103 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4104 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4105 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4106 | task->tk_status = 0; |
| 4107 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4110 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4111 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4112 | { |
| 4113 | __be32 verf[2]; |
| 4114 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4115 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4116 | /* An impossible timestamp guarantees this value |
| 4117 | * will never match a generated boot time. */ |
| 4118 | verf[0] = 0; |
| 4119 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4120 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4121 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4122 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4123 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4124 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4125 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4126 | } |
| 4127 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4128 | static unsigned int |
| 4129 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4130 | char *buf, size_t len) |
| 4131 | { |
| 4132 | unsigned int result; |
| 4133 | |
| 4134 | rcu_read_lock(); |
| 4135 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4136 | clp->cl_ipaddr, |
| 4137 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4138 | RPC_DISPLAY_ADDR), |
| 4139 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4140 | RPC_DISPLAY_PROTO)); |
| 4141 | rcu_read_unlock(); |
| 4142 | return result; |
| 4143 | } |
| 4144 | |
| 4145 | static unsigned int |
| 4146 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4147 | char *buf, size_t len) |
| 4148 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4149 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4150 | |
| 4151 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4152 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4153 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4154 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4155 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4156 | } |
| 4157 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4158 | /** |
| 4159 | * nfs4_proc_setclientid - Negotiate client ID |
| 4160 | * @clp: state data structure |
| 4161 | * @program: RPC program for NFSv4 callback service |
| 4162 | * @port: IP port number for NFS4 callback service |
| 4163 | * @cred: RPC credential to use for this call |
| 4164 | * @res: where to place the result |
| 4165 | * |
| 4166 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4167 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4168 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4169 | unsigned short port, struct rpc_cred *cred, |
| 4170 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | { |
| 4172 | nfs4_verifier sc_verifier; |
| 4173 | struct nfs4_setclientid setclientid = { |
| 4174 | .sc_verifier = &sc_verifier, |
| 4175 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4176 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | }; |
| 4178 | struct rpc_message msg = { |
| 4179 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4180 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4181 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4182 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4184 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4186 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4187 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4188 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4189 | setclientid.sc_name_len = |
| 4190 | nfs4_init_uniform_client_string(clp, |
| 4191 | setclientid.sc_name, |
| 4192 | sizeof(setclientid.sc_name)); |
| 4193 | else |
| 4194 | setclientid.sc_name_len = |
| 4195 | nfs4_init_nonuniform_client_string(clp, |
| 4196 | setclientid.sc_name, |
| 4197 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4198 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4199 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4200 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4201 | sizeof(setclientid.sc_netid), |
| 4202 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4203 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4204 | rcu_read_unlock(); |
| 4205 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4206 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4208 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4209 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4210 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4211 | setclientid.sc_name_len, setclientid.sc_name); |
| 4212 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4213 | dprintk("NFS reply setclientid: %d\n", status); |
| 4214 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | } |
| 4216 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4217 | /** |
| 4218 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4219 | * @clp: state data structure |
| 4220 | * @res: result of a previous SETCLIENTID |
| 4221 | * @cred: RPC credential to use for this call |
| 4222 | * |
| 4223 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4224 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4225 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4226 | struct nfs4_setclientid_res *arg, |
| 4227 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | { |
| 4229 | struct nfs_fsinfo fsinfo; |
| 4230 | struct rpc_message msg = { |
| 4231 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4232 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4234 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | }; |
| 4236 | unsigned long now; |
| 4237 | int status; |
| 4238 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4239 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4240 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4241 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4243 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | if (status == 0) { |
| 4245 | spin_lock(&clp->cl_lock); |
| 4246 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4247 | clp->cl_last_renewal = now; |
| 4248 | spin_unlock(&clp->cl_lock); |
| 4249 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4250 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | return status; |
| 4252 | } |
| 4253 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4254 | struct nfs4_delegreturndata { |
| 4255 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4256 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4257 | struct nfs_fh fh; |
| 4258 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4259 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4260 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4261 | int rpc_status; |
| 4262 | }; |
| 4263 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4264 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4265 | { |
| 4266 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4267 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4268 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4269 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4270 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4271 | switch (task->tk_status) { |
| 4272 | case -NFS4ERR_STALE_STATEID: |
| 4273 | case -NFS4ERR_EXPIRED: |
| 4274 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4275 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4276 | break; |
| 4277 | default: |
| 4278 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4279 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4280 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4281 | return; |
| 4282 | } |
| 4283 | } |
| 4284 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | static void nfs4_delegreturn_release(void *calldata) |
| 4288 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4289 | kfree(calldata); |
| 4290 | } |
| 4291 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4292 | #if defined(CONFIG_NFS_V4_1) |
| 4293 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4294 | { |
| 4295 | struct nfs4_delegreturndata *d_data; |
| 4296 | |
| 4297 | d_data = (struct nfs4_delegreturndata *)data; |
| 4298 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4299 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4300 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4301 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4302 | return; |
| 4303 | rpc_call_start(task); |
| 4304 | } |
| 4305 | #endif /* CONFIG_NFS_V4_1 */ |
| 4306 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4307 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4308 | #if defined(CONFIG_NFS_V4_1) |
| 4309 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4310 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4311 | .rpc_call_done = nfs4_delegreturn_done, |
| 4312 | .rpc_release = nfs4_delegreturn_release, |
| 4313 | }; |
| 4314 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4315 | 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] | 4316 | { |
| 4317 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4318 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4319 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4320 | struct rpc_message msg = { |
| 4321 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4322 | .rpc_cred = cred, |
| 4323 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4324 | struct rpc_task_setup task_setup_data = { |
| 4325 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4326 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4327 | .callback_ops = &nfs4_delegreturn_ops, |
| 4328 | .flags = RPC_TASK_ASYNC, |
| 4329 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4330 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4331 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4332 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4333 | if (data == NULL) |
| 4334 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4335 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4336 | data->args.fhandle = &data->fh; |
| 4337 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4338 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4339 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4340 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4341 | data->res.fattr = &data->fattr; |
| 4342 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4343 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4344 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4345 | data->rpc_status = 0; |
| 4346 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4347 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4348 | msg.rpc_argp = &data->args; |
| 4349 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4350 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4351 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4352 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4353 | if (!issync) |
| 4354 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4355 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4356 | if (status != 0) |
| 4357 | goto out; |
| 4358 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4359 | if (status == 0) |
| 4360 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4361 | else |
| 4362 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4363 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4364 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4365 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | } |
| 4367 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4368 | 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] | 4369 | { |
| 4370 | struct nfs_server *server = NFS_SERVER(inode); |
| 4371 | struct nfs4_exception exception = { }; |
| 4372 | int err; |
| 4373 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4374 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | switch (err) { |
| 4376 | case -NFS4ERR_STALE_STATEID: |
| 4377 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | case 0: |
| 4379 | return 0; |
| 4380 | } |
| 4381 | err = nfs4_handle_exception(server, err, &exception); |
| 4382 | } while (exception.retry); |
| 4383 | return err; |
| 4384 | } |
| 4385 | |
| 4386 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4387 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4388 | |
| 4389 | /* |
| 4390 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4391 | */ |
| 4392 | static unsigned long |
| 4393 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4394 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4395 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | timeout <<= 1; |
| 4397 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4398 | return NFS4_LOCK_MAXTIMEOUT; |
| 4399 | return timeout; |
| 4400 | } |
| 4401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4403 | { |
| 4404 | struct inode *inode = state->inode; |
| 4405 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4406 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4407 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4409 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4411 | struct nfs_lockt_res res = { |
| 4412 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | }; |
| 4414 | struct rpc_message msg = { |
| 4415 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4416 | .rpc_argp = &arg, |
| 4417 | .rpc_resp = &res, |
| 4418 | .rpc_cred = state->owner->so_cred, |
| 4419 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | struct nfs4_lock_state *lsp; |
| 4421 | int status; |
| 4422 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4423 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4424 | status = nfs4_set_lock_state(state, request); |
| 4425 | if (status != 0) |
| 4426 | goto out; |
| 4427 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4428 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4429 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4430 | 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] | 4431 | switch (status) { |
| 4432 | case 0: |
| 4433 | request->fl_type = F_UNLCK; |
| 4434 | break; |
| 4435 | case -NFS4ERR_DENIED: |
| 4436 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4438 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4439 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | return status; |
| 4441 | } |
| 4442 | |
| 4443 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4444 | { |
| 4445 | struct nfs4_exception exception = { }; |
| 4446 | int err; |
| 4447 | |
| 4448 | do { |
| 4449 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4450 | _nfs4_proc_getlk(state, cmd, request), |
| 4451 | &exception); |
| 4452 | } while (exception.retry); |
| 4453 | return err; |
| 4454 | } |
| 4455 | |
| 4456 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4457 | { |
| 4458 | int res = 0; |
| 4459 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4460 | case FL_POSIX: |
| 4461 | res = posix_lock_file_wait(file, fl); |
| 4462 | break; |
| 4463 | case FL_FLOCK: |
| 4464 | res = flock_lock_file_wait(file, fl); |
| 4465 | break; |
| 4466 | default: |
| 4467 | BUG(); |
| 4468 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | return res; |
| 4470 | } |
| 4471 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4472 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4473 | struct nfs_locku_args arg; |
| 4474 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4475 | struct nfs4_lock_state *lsp; |
| 4476 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4477 | struct file_lock fl; |
| 4478 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4479 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4480 | }; |
| 4481 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4482 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4483 | struct nfs_open_context *ctx, |
| 4484 | struct nfs4_lock_state *lsp, |
| 4485 | struct nfs_seqid *seqid) |
| 4486 | { |
| 4487 | struct nfs4_unlockdata *p; |
| 4488 | struct inode *inode = lsp->ls_state->inode; |
| 4489 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4490 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4491 | if (p == NULL) |
| 4492 | return NULL; |
| 4493 | p->arg.fh = NFS_FH(inode); |
| 4494 | p->arg.fl = &p->fl; |
| 4495 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4496 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4497 | p->arg.stateid = &lsp->ls_stateid; |
| 4498 | p->lsp = lsp; |
| 4499 | atomic_inc(&lsp->ls_count); |
| 4500 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4501 | p->ctx = get_nfs_open_context(ctx); |
| 4502 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4503 | p->server = NFS_SERVER(inode); |
| 4504 | return p; |
| 4505 | } |
| 4506 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4507 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4508 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4509 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4510 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4511 | nfs4_put_lock_state(calldata->lsp); |
| 4512 | put_nfs_open_context(calldata->ctx); |
| 4513 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4516 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4517 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4518 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4519 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4520 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4521 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4522 | switch (task->tk_status) { |
| 4523 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4524 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4525 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4526 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4527 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4528 | case -NFS4ERR_BAD_STATEID: |
| 4529 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4530 | case -NFS4ERR_STALE_STATEID: |
| 4531 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4532 | break; |
| 4533 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4534 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4535 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4536 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4537 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4540 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4541 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4542 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4544 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4545 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4546 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4547 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4548 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4549 | return; |
| 4550 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4551 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4552 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4553 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4554 | &calldata->res.seq_res, |
| 4555 | task) != 0) |
| 4556 | nfs_release_seqid(calldata->arg.seqid); |
| 4557 | else |
| 4558 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | } |
| 4560 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4561 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4562 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4563 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4564 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4565 | }; |
| 4566 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4567 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4568 | struct nfs_open_context *ctx, |
| 4569 | struct nfs4_lock_state *lsp, |
| 4570 | struct nfs_seqid *seqid) |
| 4571 | { |
| 4572 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4573 | struct rpc_message msg = { |
| 4574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4575 | .rpc_cred = ctx->cred, |
| 4576 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4577 | struct rpc_task_setup task_setup_data = { |
| 4578 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4579 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4580 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4581 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4582 | .flags = RPC_TASK_ASYNC, |
| 4583 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4584 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4585 | /* Ensure this is an unlock - when canceling a lock, the |
| 4586 | * canceled lock is passed in, and it won't be an unlock. |
| 4587 | */ |
| 4588 | fl->fl_type = F_UNLCK; |
| 4589 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4590 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4591 | if (data == NULL) { |
| 4592 | nfs_free_seqid(seqid); |
| 4593 | return ERR_PTR(-ENOMEM); |
| 4594 | } |
| 4595 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4596 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4597 | msg.rpc_argp = &data->arg; |
| 4598 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4599 | task_setup_data.callback_data = data; |
| 4600 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4601 | } |
| 4602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4604 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4605 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4606 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4607 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4608 | struct rpc_task *task; |
| 4609 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4610 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4612 | status = nfs4_set_lock_state(state, request); |
| 4613 | /* Unlock _before_ we do the RPC call */ |
| 4614 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4615 | down_read(&nfsi->rwsem); |
| 4616 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4617 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4618 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4619 | } |
| 4620 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4621 | if (status != 0) |
| 4622 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4623 | /* Is this a delegated lock? */ |
| 4624 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4625 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4626 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4627 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4628 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4629 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4630 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4631 | 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] | 4632 | status = PTR_ERR(task); |
| 4633 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4634 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4635 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4636 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4637 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4638 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4639 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4642 | struct nfs4_lockdata { |
| 4643 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4644 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4645 | struct nfs4_lock_state *lsp; |
| 4646 | struct nfs_open_context *ctx; |
| 4647 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4648 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4649 | int rpc_status; |
| 4650 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4651 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4652 | }; |
| 4653 | |
| 4654 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4655 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4656 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4657 | { |
| 4658 | struct nfs4_lockdata *p; |
| 4659 | struct inode *inode = lsp->ls_state->inode; |
| 4660 | struct nfs_server *server = NFS_SERVER(inode); |
| 4661 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4662 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4663 | if (p == NULL) |
| 4664 | return NULL; |
| 4665 | |
| 4666 | p->arg.fh = NFS_FH(inode); |
| 4667 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4668 | 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] | 4669 | if (p->arg.open_seqid == NULL) |
| 4670 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4671 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4672 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4673 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4674 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4675 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4676 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4677 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4678 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4679 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4680 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4681 | atomic_inc(&lsp->ls_count); |
| 4682 | p->ctx = get_nfs_open_context(ctx); |
| 4683 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4684 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4685 | out_free_seqid: |
| 4686 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4687 | out_free: |
| 4688 | kfree(p); |
| 4689 | return NULL; |
| 4690 | } |
| 4691 | |
| 4692 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4693 | { |
| 4694 | struct nfs4_lockdata *data = calldata; |
| 4695 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4697 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4698 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4699 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4700 | /* Do we need to do an open_to_lock_owner? */ |
| 4701 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4702 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4703 | goto out_release_lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4704 | data->arg.open_stateid = &state->stateid; |
| 4705 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4706 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4707 | } else |
| 4708 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4709 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4710 | if (nfs4_setup_sequence(data->server, |
| 4711 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4712 | &data->res.seq_res, |
| 4713 | task) == 0) { |
| 4714 | rpc_call_start(task); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4715 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4716 | } |
| 4717 | nfs_release_seqid(data->arg.open_seqid); |
| 4718 | out_release_lock_seqid: |
| 4719 | nfs_release_seqid(data->arg.lock_seqid); |
| 4720 | dprintk("%s: done!, ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4721 | } |
| 4722 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4723 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4724 | { |
| 4725 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4726 | nfs4_lock_prepare(task, calldata); |
| 4727 | } |
| 4728 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4729 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4730 | { |
| 4731 | struct nfs4_lockdata *data = calldata; |
| 4732 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4733 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4734 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4735 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4736 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4737 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4738 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4739 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4740 | if (data->rpc_status == 0) |
| 4741 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4742 | else |
| 4743 | goto out; |
| 4744 | } |
| 4745 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4746 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4747 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4748 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4749 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4750 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4751 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | static void nfs4_lock_release(void *calldata) |
| 4755 | { |
| 4756 | struct nfs4_lockdata *data = calldata; |
| 4757 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4758 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4759 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4760 | if (data->cancelled != 0) { |
| 4761 | struct rpc_task *task; |
| 4762 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4763 | data->arg.lock_seqid); |
| 4764 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4765 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4766 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4767 | } else |
| 4768 | nfs_free_seqid(data->arg.lock_seqid); |
| 4769 | nfs4_put_lock_state(data->lsp); |
| 4770 | put_nfs_open_context(data->ctx); |
| 4771 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4772 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4776 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4777 | .rpc_call_done = nfs4_lock_done, |
| 4778 | .rpc_release = nfs4_lock_release, |
| 4779 | }; |
| 4780 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4781 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4782 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4783 | .rpc_call_done = nfs4_lock_done, |
| 4784 | .rpc_release = nfs4_lock_release, |
| 4785 | }; |
| 4786 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4787 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4788 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4789 | switch (error) { |
| 4790 | case -NFS4ERR_ADMIN_REVOKED: |
| 4791 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4792 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4793 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4794 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4795 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4796 | break; |
| 4797 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4798 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4799 | case -NFS4ERR_EXPIRED: |
| 4800 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4801 | }; |
| 4802 | } |
| 4803 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4804 | 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] | 4805 | { |
| 4806 | struct nfs4_lockdata *data; |
| 4807 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4808 | struct rpc_message msg = { |
| 4809 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4810 | .rpc_cred = state->owner->so_cred, |
| 4811 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4812 | struct rpc_task_setup task_setup_data = { |
| 4813 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4814 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4815 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4816 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4817 | .flags = RPC_TASK_ASYNC, |
| 4818 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4819 | int ret; |
| 4820 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4821 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4822 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4823 | fl->fl_u.nfs4_fl.owner, |
| 4824 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4825 | if (data == NULL) |
| 4826 | return -ENOMEM; |
| 4827 | if (IS_SETLKW(cmd)) |
| 4828 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4829 | if (recovery_type > NFS_LOCK_NEW) { |
| 4830 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4831 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4832 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4833 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4834 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4835 | msg.rpc_argp = &data->arg; |
| 4836 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4837 | task_setup_data.callback_data = data; |
| 4838 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4839 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4840 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4841 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4842 | if (ret == 0) { |
| 4843 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4844 | if (ret) |
| 4845 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4846 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4847 | } else |
| 4848 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4849 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4850 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4851 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4855 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4856 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4857 | struct nfs4_exception exception = { |
| 4858 | .inode = state->inode, |
| 4859 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4860 | int err; |
| 4861 | |
| 4862 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4863 | /* Cache the lock if possible... */ |
| 4864 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4865 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4866 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4867 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4868 | break; |
| 4869 | nfs4_handle_exception(server, err, &exception); |
| 4870 | } while (exception.retry); |
| 4871 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4875 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4876 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4877 | struct nfs4_exception exception = { |
| 4878 | .inode = state->inode, |
| 4879 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4880 | int err; |
| 4881 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4882 | err = nfs4_set_lock_state(state, request); |
| 4883 | if (err != 0) |
| 4884 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4885 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4886 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4887 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4888 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4889 | switch (err) { |
| 4890 | default: |
| 4891 | goto out; |
| 4892 | case -NFS4ERR_GRACE: |
| 4893 | case -NFS4ERR_DELAY: |
| 4894 | nfs4_handle_exception(server, err, &exception); |
| 4895 | err = 0; |
| 4896 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4897 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4898 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4899 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4902 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4903 | /** |
| 4904 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4905 | * |
| 4906 | * @state: NFSv4 state for an inode |
| 4907 | * |
| 4908 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4909 | * Otherwise a negative NFS4ERR value is returned. |
| 4910 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4911 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4912 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4913 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4914 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4915 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4916 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4917 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4918 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4919 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4920 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4921 | /* Free the stateid unless the server |
| 4922 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4923 | if (status != -NFS4ERR_BAD_STATEID) |
| 4924 | nfs41_free_stateid(server, |
| 4925 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4926 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4927 | ret = status; |
| 4928 | } |
| 4929 | } |
| 4930 | }; |
| 4931 | |
| 4932 | return ret; |
| 4933 | } |
| 4934 | |
| 4935 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4936 | { |
| 4937 | int status = NFS_OK; |
| 4938 | |
| 4939 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4940 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4941 | if (status != NFS_OK) |
| 4942 | status = nfs4_lock_expired(state, request); |
| 4943 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4944 | } |
| 4945 | #endif |
| 4946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4948 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4949 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4950 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4951 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4953 | if ((fl_flags & FL_POSIX) && |
| 4954 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4955 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4956 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4957 | status = nfs4_set_lock_state(state, request); |
| 4958 | if (status != 0) |
| 4959 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4960 | request->fl_flags |= FL_ACCESS; |
| 4961 | status = do_vfs_lock(request->fl_file, request); |
| 4962 | if (status < 0) |
| 4963 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4964 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4965 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4966 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4967 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4968 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4969 | status = do_vfs_lock(request->fl_file, request); |
| 4970 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4971 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4972 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4973 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4974 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4975 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4976 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4977 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4978 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4979 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4980 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4981 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4982 | out: |
| 4983 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4984 | return status; |
| 4985 | } |
| 4986 | |
| 4987 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4988 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4989 | struct nfs4_exception exception = { |
| 4990 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4991 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4992 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | int err; |
| 4994 | |
| 4995 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4996 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4997 | if (err == -NFS4ERR_DENIED) |
| 4998 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5000 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | } while (exception.retry); |
| 5002 | return err; |
| 5003 | } |
| 5004 | |
| 5005 | static int |
| 5006 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5007 | { |
| 5008 | struct nfs_open_context *ctx; |
| 5009 | struct nfs4_state *state; |
| 5010 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5011 | int status; |
| 5012 | |
| 5013 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5014 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | state = ctx->state; |
| 5016 | |
| 5017 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5018 | return -EINVAL; |
| 5019 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5020 | if (IS_GETLK(cmd)) { |
| 5021 | if (state != NULL) |
| 5022 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5023 | return 0; |
| 5024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | |
| 5026 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5027 | return -EINVAL; |
| 5028 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5029 | if (request->fl_type == F_UNLCK) { |
| 5030 | if (state != NULL) |
| 5031 | return nfs4_proc_unlck(state, cmd, request); |
| 5032 | return 0; |
| 5033 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5035 | if (state == NULL) |
| 5036 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5037 | /* |
| 5038 | * Don't rely on the VFS having checked the file open mode, |
| 5039 | * since it won't do this for flock() locks. |
| 5040 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5041 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5042 | case F_RDLCK: |
| 5043 | if (!(filp->f_mode & FMODE_READ)) |
| 5044 | return -EBADF; |
| 5045 | break; |
| 5046 | case F_WRLCK: |
| 5047 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5048 | return -EBADF; |
| 5049 | } |
| 5050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | do { |
| 5052 | status = nfs4_proc_setlk(state, cmd, request); |
| 5053 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5054 | break; |
| 5055 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5056 | status = -ERESTARTSYS; |
| 5057 | if (signalled()) |
| 5058 | break; |
| 5059 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | return status; |
| 5061 | } |
| 5062 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5063 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5064 | { |
| 5065 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5066 | struct nfs4_exception exception = { }; |
| 5067 | int err; |
| 5068 | |
| 5069 | err = nfs4_set_lock_state(state, fl); |
| 5070 | if (err != 0) |
| 5071 | goto out; |
| 5072 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5073 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5074 | switch (err) { |
| 5075 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5076 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5077 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5078 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5079 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5080 | goto out; |
| 5081 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 5082 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5083 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5084 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5085 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5086 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5087 | case -NFS4ERR_BADSESSION: |
| 5088 | case -NFS4ERR_BADSLOT: |
| 5089 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5090 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5091 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5092 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5093 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5094 | case -ERESTARTSYS: |
| 5095 | /* |
| 5096 | * The show must go on: exit, but mark the |
| 5097 | * stateid as needing recovery. |
| 5098 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5099 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5100 | case -NFS4ERR_ADMIN_REVOKED: |
| 5101 | case -NFS4ERR_BAD_STATEID: |
| 5102 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5103 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5104 | err = 0; |
| 5105 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5106 | case -EKEYEXPIRED: |
| 5107 | /* |
| 5108 | * User RPCSEC_GSS context has expired. |
| 5109 | * We cannot recover this stateid now, so |
| 5110 | * skip it and allow recovery thread to |
| 5111 | * proceed. |
| 5112 | */ |
| 5113 | err = 0; |
| 5114 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5115 | case -ENOMEM: |
| 5116 | case -NFS4ERR_DENIED: |
| 5117 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5118 | err = 0; |
| 5119 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5120 | case -NFS4ERR_DELAY: |
| 5121 | break; |
| 5122 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5123 | err = nfs4_handle_exception(server, err, &exception); |
| 5124 | } while (exception.retry); |
| 5125 | out: |
| 5126 | return err; |
| 5127 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5128 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5129 | struct nfs_release_lockowner_data { |
| 5130 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5131 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5132 | struct nfs_release_lockowner_args args; |
| 5133 | }; |
| 5134 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5135 | static void nfs4_release_lockowner_release(void *calldata) |
| 5136 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5137 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5138 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5139 | kfree(calldata); |
| 5140 | } |
| 5141 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5142 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5143 | .rpc_release = nfs4_release_lockowner_release, |
| 5144 | }; |
| 5145 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5146 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5147 | { |
| 5148 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5149 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5150 | struct rpc_message msg = { |
| 5151 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5152 | }; |
| 5153 | |
| 5154 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5155 | return -EINVAL; |
| 5156 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5157 | if (!data) |
| 5158 | return -ENOMEM; |
| 5159 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5160 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5161 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5162 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5163 | data->args.lock_owner.s_dev = server->s_dev; |
| 5164 | msg.rpc_argp = &data->args; |
| 5165 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5166 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5167 | } |
| 5168 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5169 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5170 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5171 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5172 | const void *buf, size_t buflen, |
| 5173 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5174 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5175 | if (strcmp(key, "") != 0) |
| 5176 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5177 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5178 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5179 | } |
| 5180 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5181 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5182 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5183 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5184 | if (strcmp(key, "") != 0) |
| 5185 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5186 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5187 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5190 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5191 | size_t list_len, const char *name, |
| 5192 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5193 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5194 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5195 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5196 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5197 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5198 | |
| 5199 | if (list && len <= list_len) |
| 5200 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5201 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5204 | /* |
| 5205 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5206 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5207 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5208 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5209 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5210 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5211 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5212 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5213 | return; |
| 5214 | |
| 5215 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5216 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5217 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5218 | fattr->nlink = 2; |
| 5219 | } |
| 5220 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5221 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5222 | const struct qstr *name, |
| 5223 | struct nfs4_fs_locations *fs_locations, |
| 5224 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5225 | { |
| 5226 | struct nfs_server *server = NFS_SERVER(dir); |
| 5227 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5228 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5229 | }; |
| 5230 | struct nfs4_fs_locations_arg args = { |
| 5231 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5232 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5233 | .page = page, |
| 5234 | .bitmask = bitmask, |
| 5235 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5236 | struct nfs4_fs_locations_res res = { |
| 5237 | .fs_locations = fs_locations, |
| 5238 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5239 | struct rpc_message msg = { |
| 5240 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5241 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5242 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5243 | }; |
| 5244 | int status; |
| 5245 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5246 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5247 | |
| 5248 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5249 | * is not supported */ |
| 5250 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5251 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5252 | else |
| 5253 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5254 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5255 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5256 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5257 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5258 | 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] | 5259 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5260 | return status; |
| 5261 | } |
| 5262 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5263 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5264 | const struct qstr *name, |
| 5265 | struct nfs4_fs_locations *fs_locations, |
| 5266 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5267 | { |
| 5268 | struct nfs4_exception exception = { }; |
| 5269 | int err; |
| 5270 | do { |
| 5271 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5272 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5273 | &exception); |
| 5274 | } while (exception.retry); |
| 5275 | return err; |
| 5276 | } |
| 5277 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5278 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5279 | { |
| 5280 | int status; |
| 5281 | struct nfs4_secinfo_arg args = { |
| 5282 | .dir_fh = NFS_FH(dir), |
| 5283 | .name = name, |
| 5284 | }; |
| 5285 | struct nfs4_secinfo_res res = { |
| 5286 | .flavors = flavors, |
| 5287 | }; |
| 5288 | struct rpc_message msg = { |
| 5289 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5290 | .rpc_argp = &args, |
| 5291 | .rpc_resp = &res, |
| 5292 | }; |
| 5293 | |
| 5294 | dprintk("NFS call secinfo %s\n", name->name); |
| 5295 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5296 | dprintk("NFS reply secinfo: %d\n", status); |
| 5297 | return status; |
| 5298 | } |
| 5299 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5300 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5301 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5302 | { |
| 5303 | struct nfs4_exception exception = { }; |
| 5304 | int err; |
| 5305 | do { |
| 5306 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5307 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5308 | &exception); |
| 5309 | } while (exception.retry); |
| 5310 | return err; |
| 5311 | } |
| 5312 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5313 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5314 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5315 | * Check the exchange flags returned by the server for invalid flags, having |
| 5316 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5317 | * DS flags set. |
| 5318 | */ |
| 5319 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5320 | { |
| 5321 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5322 | goto out_inval; |
| 5323 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5324 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5325 | goto out_inval; |
| 5326 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5327 | goto out_inval; |
| 5328 | return NFS_OK; |
| 5329 | out_inval: |
| 5330 | return -NFS4ERR_INVAL; |
| 5331 | } |
| 5332 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5333 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5334 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5335 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5336 | { |
| 5337 | if (a->server_scope_sz == b->server_scope_sz && |
| 5338 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5339 | return true; |
| 5340 | |
| 5341 | return false; |
| 5342 | } |
| 5343 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5344 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5345 | * nfs4_proc_bind_conn_to_session() |
| 5346 | * |
| 5347 | * The 4.1 client currently uses the same TCP connection for the |
| 5348 | * fore and backchannel. |
| 5349 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5350 | 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] | 5351 | { |
| 5352 | int status; |
| 5353 | struct nfs41_bind_conn_to_session_res res; |
| 5354 | struct rpc_message msg = { |
| 5355 | .rpc_proc = |
| 5356 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5357 | .rpc_argp = clp, |
| 5358 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5359 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5360 | }; |
| 5361 | |
| 5362 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5363 | |
| 5364 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5365 | if (unlikely(res.session == NULL)) { |
| 5366 | status = -ENOMEM; |
| 5367 | goto out; |
| 5368 | } |
| 5369 | |
| 5370 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5371 | if (status == 0) { |
| 5372 | if (memcmp(res.session->sess_id.data, |
| 5373 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5374 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5375 | status = -EIO; |
| 5376 | goto out_session; |
| 5377 | } |
| 5378 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5379 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5380 | __func__); |
| 5381 | status = -EIO; |
| 5382 | goto out_session; |
| 5383 | } |
| 5384 | if (res.use_conn_in_rdma_mode) { |
| 5385 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5386 | __func__); |
| 5387 | status = -EIO; |
| 5388 | goto out_session; |
| 5389 | } |
| 5390 | } |
| 5391 | out_session: |
| 5392 | kfree(res.session); |
| 5393 | out: |
| 5394 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5395 | return status; |
| 5396 | } |
| 5397 | |
| 5398 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5399 | * nfs4_proc_exchange_id() |
| 5400 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5401 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5402 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5403 | * Since the clientid has expired, all compounds using sessions |
| 5404 | * associated with the stale clientid will be returning |
| 5405 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5406 | * be in some phase of session reset. |
| 5407 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5408 | 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] | 5409 | { |
| 5410 | nfs4_verifier verifier; |
| 5411 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5412 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5413 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5414 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5415 | }; |
| 5416 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5417 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5418 | }; |
| 5419 | int status; |
| 5420 | struct rpc_message msg = { |
| 5421 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5422 | .rpc_argp = &args, |
| 5423 | .rpc_resp = &res, |
| 5424 | .rpc_cred = cred, |
| 5425 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5426 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5427 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5428 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5429 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5430 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5431 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5432 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5433 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5434 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5435 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5436 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5437 | status = -ENOMEM; |
| 5438 | goto out; |
| 5439 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5440 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5441 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5442 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5443 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5444 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5445 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5446 | } |
| 5447 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5448 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5449 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5450 | status = -ENOMEM; |
| 5451 | goto out_server_scope; |
| 5452 | } |
| 5453 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5454 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5455 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5456 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5457 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5458 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5459 | clp->cl_clientid = res.clientid; |
| 5460 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5461 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5462 | clp->cl_seqid = res.seqid; |
| 5463 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5464 | kfree(clp->cl_serverowner); |
| 5465 | clp->cl_serverowner = res.server_owner; |
| 5466 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5467 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5468 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5469 | kfree(clp->cl_implid); |
| 5470 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5471 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5472 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5473 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5474 | res.server_scope)) { |
| 5475 | dprintk("%s: server_scope mismatch detected\n", |
| 5476 | __func__); |
| 5477 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5478 | kfree(clp->cl_serverscope); |
| 5479 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5480 | } |
| 5481 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5482 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5483 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5484 | goto out; |
| 5485 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5486 | } else |
| 5487 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5488 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5489 | out_server_owner: |
| 5490 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5491 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5492 | kfree(res.server_scope); |
| 5493 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5494 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5495 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5496 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5497 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5498 | clp->cl_implid->date.seconds, |
| 5499 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5500 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5501 | return status; |
| 5502 | } |
| 5503 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5504 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5505 | struct rpc_cred *cred) |
| 5506 | { |
| 5507 | struct rpc_message msg = { |
| 5508 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5509 | .rpc_argp = clp, |
| 5510 | .rpc_cred = cred, |
| 5511 | }; |
| 5512 | int status; |
| 5513 | |
| 5514 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5515 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5516 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5517 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5518 | return status; |
| 5519 | } |
| 5520 | |
| 5521 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5522 | struct rpc_cred *cred) |
| 5523 | { |
| 5524 | unsigned int loop; |
| 5525 | int ret; |
| 5526 | |
| 5527 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5528 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5529 | switch (ret) { |
| 5530 | case -NFS4ERR_DELAY: |
| 5531 | case -NFS4ERR_CLIENTID_BUSY: |
| 5532 | ssleep(1); |
| 5533 | break; |
| 5534 | default: |
| 5535 | return ret; |
| 5536 | } |
| 5537 | } |
| 5538 | return 0; |
| 5539 | } |
| 5540 | |
| 5541 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5542 | { |
| 5543 | struct rpc_cred *cred; |
| 5544 | int ret = 0; |
| 5545 | |
| 5546 | if (clp->cl_mvops->minor_version < 1) |
| 5547 | goto out; |
| 5548 | if (clp->cl_exchange_flags == 0) |
| 5549 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5550 | if (clp->cl_preserve_clid) |
| 5551 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5552 | cred = nfs4_get_exchange_id_cred(clp); |
| 5553 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5554 | if (cred) |
| 5555 | put_rpccred(cred); |
| 5556 | switch (ret) { |
| 5557 | case 0: |
| 5558 | case -NFS4ERR_STALE_CLIENTID: |
| 5559 | clp->cl_exchange_flags = 0; |
| 5560 | } |
| 5561 | out: |
| 5562 | return ret; |
| 5563 | } |
| 5564 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5565 | struct nfs4_get_lease_time_data { |
| 5566 | struct nfs4_get_lease_time_args *args; |
| 5567 | struct nfs4_get_lease_time_res *res; |
| 5568 | struct nfs_client *clp; |
| 5569 | }; |
| 5570 | |
| 5571 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5572 | void *calldata) |
| 5573 | { |
| 5574 | int ret; |
| 5575 | struct nfs4_get_lease_time_data *data = |
| 5576 | (struct nfs4_get_lease_time_data *)calldata; |
| 5577 | |
| 5578 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5579 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5580 | /* just setup sequence, do not trigger session recovery |
| 5581 | since we're invoked within one */ |
| 5582 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5583 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5584 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5585 | |
Trond Myklebust | d3edcf9 | 2012-10-15 13:14:43 -0400 | [diff] [blame] | 5586 | if (ret != -EAGAIN) |
| 5587 | rpc_call_start(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5588 | dprintk("<-- %s\n", __func__); |
| 5589 | } |
| 5590 | |
| 5591 | /* |
| 5592 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5593 | * from sequence operation or clientid errors. |
| 5594 | */ |
| 5595 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5596 | { |
| 5597 | struct nfs4_get_lease_time_data *data = |
| 5598 | (struct nfs4_get_lease_time_data *)calldata; |
| 5599 | |
| 5600 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5601 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5602 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5603 | switch (task->tk_status) { |
| 5604 | case -NFS4ERR_DELAY: |
| 5605 | case -NFS4ERR_GRACE: |
| 5606 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5607 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5608 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5609 | /* fall through */ |
| 5610 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5611 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5612 | return; |
| 5613 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5614 | dprintk("<-- %s\n", __func__); |
| 5615 | } |
| 5616 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5617 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5618 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5619 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5620 | }; |
| 5621 | |
| 5622 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5623 | { |
| 5624 | struct rpc_task *task; |
| 5625 | struct nfs4_get_lease_time_args args; |
| 5626 | struct nfs4_get_lease_time_res res = { |
| 5627 | .lr_fsinfo = fsinfo, |
| 5628 | }; |
| 5629 | struct nfs4_get_lease_time_data data = { |
| 5630 | .args = &args, |
| 5631 | .res = &res, |
| 5632 | .clp = clp, |
| 5633 | }; |
| 5634 | struct rpc_message msg = { |
| 5635 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5636 | .rpc_argp = &args, |
| 5637 | .rpc_resp = &res, |
| 5638 | }; |
| 5639 | struct rpc_task_setup task_setup = { |
| 5640 | .rpc_client = clp->cl_rpcclient, |
| 5641 | .rpc_message = &msg, |
| 5642 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5643 | .callback_data = &data, |
| 5644 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5645 | }; |
| 5646 | int status; |
| 5647 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5648 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5649 | dprintk("--> %s\n", __func__); |
| 5650 | task = rpc_run_task(&task_setup); |
| 5651 | |
| 5652 | if (IS_ERR(task)) |
| 5653 | status = PTR_ERR(task); |
| 5654 | else { |
| 5655 | status = task->tk_status; |
| 5656 | rpc_put_task(task); |
| 5657 | } |
| 5658 | dprintk("<-- %s return %d\n", __func__, status); |
| 5659 | |
| 5660 | return status; |
| 5661 | } |
| 5662 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5663 | struct nfs4_slot *nfs4_alloc_slots(struct nfs4_slot_table *table, |
| 5664 | u32 max_slots, gfp_t gfp_flags) |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5665 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5666 | struct nfs4_slot *tbl; |
| 5667 | u32 i; |
| 5668 | |
| 5669 | tbl = kmalloc_array(max_slots, sizeof(*tbl), gfp_flags); |
| 5670 | if (tbl != NULL) { |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 5671 | for (i = 0; i < max_slots; i++) { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5672 | tbl[i].table = table; |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 5673 | tbl[i].slot_nr = i; |
| 5674 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5675 | } |
| 5676 | return tbl; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5677 | } |
| 5678 | |
| 5679 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5680 | struct nfs4_slot *new, |
| 5681 | u32 max_slots, |
| 5682 | u32 ivalue) |
| 5683 | { |
| 5684 | struct nfs4_slot *old = NULL; |
| 5685 | u32 i; |
| 5686 | |
| 5687 | spin_lock(&tbl->slot_tbl_lock); |
| 5688 | if (new) { |
| 5689 | old = tbl->slots; |
| 5690 | tbl->slots = new; |
| 5691 | tbl->max_slots = max_slots; |
| 5692 | } |
Trond Myklebust | f9b1ef5 | 2012-10-29 16:48:40 -0400 | [diff] [blame] | 5693 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5694 | for (i = 0; i < tbl->max_slots; i++) |
| 5695 | tbl->slots[i].seq_nr = ivalue; |
| 5696 | spin_unlock(&tbl->slot_tbl_lock); |
| 5697 | kfree(old); |
| 5698 | } |
| 5699 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5700 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5701 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5702 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5703 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5704 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5705 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5706 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5707 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5708 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5709 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5710 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5711 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5712 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5713 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5714 | new = nfs4_alloc_slots(tbl, max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5715 | if (!new) |
| 5716 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5717 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5718 | ret = 0; |
| 5719 | |
| 5720 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5721 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5722 | tbl, tbl->slots, tbl->max_slots); |
| 5723 | out: |
| 5724 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5725 | return ret; |
| 5726 | } |
| 5727 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5728 | /* Destroy the slot table */ |
| 5729 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5730 | { |
| 5731 | if (session->fc_slot_table.slots != NULL) { |
| 5732 | kfree(session->fc_slot_table.slots); |
| 5733 | session->fc_slot_table.slots = NULL; |
| 5734 | } |
| 5735 | if (session->bc_slot_table.slots != NULL) { |
| 5736 | kfree(session->bc_slot_table.slots); |
| 5737 | session->bc_slot_table.slots = NULL; |
| 5738 | } |
| 5739 | return; |
| 5740 | } |
| 5741 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5742 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5743 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5744 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5745 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5746 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5747 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5748 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5749 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5750 | dprintk("--> %s\n", __func__); |
| 5751 | /* Fore channel */ |
| 5752 | tbl = &ses->fc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5753 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5754 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5755 | if (status) /* -ENOMEM */ |
| 5756 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5757 | /* Back channel */ |
| 5758 | tbl = &ses->bc_slot_table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 5759 | tbl->session = ses; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5760 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5761 | if (status && tbl->slots == NULL) |
| 5762 | /* Fore and back channel share a connection so get |
| 5763 | * both slot tables or neither */ |
| 5764 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5765 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5766 | } |
| 5767 | |
| 5768 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5769 | { |
| 5770 | struct nfs4_session *session; |
| 5771 | struct nfs4_slot_table *tbl; |
| 5772 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5773 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5774 | if (!session) |
| 5775 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5776 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5777 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5778 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5779 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5780 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5781 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5782 | |
| 5783 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5784 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5785 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5786 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5787 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5788 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5789 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5790 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5791 | session->clp = clp; |
| 5792 | return session; |
| 5793 | } |
| 5794 | |
| 5795 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5796 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5797 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5798 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5799 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5800 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5801 | nfs4_proc_destroy_session(session, cred); |
| 5802 | if (cred) |
| 5803 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5804 | |
| 5805 | rcu_read_lock(); |
| 5806 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5807 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5808 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5809 | __func__, xprt); |
| 5810 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5811 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5812 | kfree(session); |
| 5813 | } |
| 5814 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5815 | /* |
| 5816 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5817 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5818 | * use them. |
| 5819 | * |
| 5820 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5821 | * always set csa_cachethis to FALSE because the current implementation |
| 5822 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5823 | */ |
| 5824 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5825 | { |
| 5826 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5827 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5828 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5829 | |
| 5830 | if (mxrqst_sz == 0) |
| 5831 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5832 | if (mxresp_sz == 0) |
| 5833 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5834 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5835 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5836 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5837 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5838 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5839 | |
| 5840 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5841 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5842 | __func__, |
| 5843 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5844 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5845 | |
| 5846 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5847 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5848 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5849 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5850 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5851 | args->bc_attrs.max_reqs = 1; |
| 5852 | |
| 5853 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5854 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5855 | __func__, |
| 5856 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5857 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5858 | args->bc_attrs.max_reqs); |
| 5859 | } |
| 5860 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5861 | 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] | 5862 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5863 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5864 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5865 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5866 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5867 | return -EINVAL; |
| 5868 | /* |
| 5869 | * Our requested max_ops is the minimum we need; we're not |
| 5870 | * prepared to break up compounds into smaller pieces than that. |
| 5871 | * So, no point even trying to continue if the server won't |
| 5872 | * cooperate: |
| 5873 | */ |
| 5874 | if (rcvd->max_ops < sent->max_ops) |
| 5875 | return -EINVAL; |
| 5876 | if (rcvd->max_reqs == 0) |
| 5877 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5878 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5879 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5880 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5881 | } |
| 5882 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5883 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5884 | { |
| 5885 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5886 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5887 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5888 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5889 | return -EINVAL; |
| 5890 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5891 | return -EINVAL; |
| 5892 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5893 | return -EINVAL; |
| 5894 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5895 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5896 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5897 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5898 | return -EINVAL; |
| 5899 | return 0; |
| 5900 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5901 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5902 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5903 | struct nfs4_session *session) |
| 5904 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5905 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5906 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5907 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5908 | if (ret) |
| 5909 | return ret; |
| 5910 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5911 | } |
| 5912 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5913 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5914 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5915 | { |
| 5916 | struct nfs4_session *session = clp->cl_session; |
| 5917 | struct nfs41_create_session_args args = { |
| 5918 | .client = clp, |
| 5919 | .cb_program = NFS4_CALLBACK, |
| 5920 | }; |
| 5921 | struct nfs41_create_session_res res = { |
| 5922 | .client = clp, |
| 5923 | }; |
| 5924 | struct rpc_message msg = { |
| 5925 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5926 | .rpc_argp = &args, |
| 5927 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5928 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5929 | }; |
| 5930 | int status; |
| 5931 | |
| 5932 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5933 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5934 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5935 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5936 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5937 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5938 | /* Verify the session's negotiated channel_attrs values */ |
| 5939 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5940 | /* Increment the clientid slot sequence id */ |
| 5941 | clp->cl_seqid++; |
| 5942 | } |
| 5943 | |
| 5944 | return status; |
| 5945 | } |
| 5946 | |
| 5947 | /* |
| 5948 | * Issues a CREATE_SESSION operation to the server. |
| 5949 | * It is the responsibility of the caller to verify the session is |
| 5950 | * expired before calling this routine. |
| 5951 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5952 | 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] | 5953 | { |
| 5954 | int status; |
| 5955 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5956 | struct nfs4_session *session = clp->cl_session; |
| 5957 | |
| 5958 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5959 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5960 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5961 | if (status) |
| 5962 | goto out; |
| 5963 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5964 | /* Init or reset the session slot tables */ |
| 5965 | status = nfs4_setup_session_slot_tables(session); |
| 5966 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5967 | if (status) |
| 5968 | goto out; |
| 5969 | |
| 5970 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5971 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5972 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5973 | out: |
| 5974 | dprintk("<-- %s\n", __func__); |
| 5975 | return status; |
| 5976 | } |
| 5977 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5978 | /* |
| 5979 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5980 | * The caller must serialize access to this routine. |
| 5981 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5982 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5983 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5984 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5985 | struct rpc_message msg = { |
| 5986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5987 | .rpc_argp = session, |
| 5988 | .rpc_cred = cred, |
| 5989 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5990 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5991 | |
| 5992 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5993 | |
| 5994 | /* session is still being setup */ |
| 5995 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5996 | return status; |
| 5997 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5998 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5999 | |
| 6000 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6001 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6002 | "Session has been destroyed regardless...\n", status); |
| 6003 | |
| 6004 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6005 | return status; |
| 6006 | } |
| 6007 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6008 | /* |
| 6009 | * With sessions, the client is not marked ready until after a |
| 6010 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 6011 | * |
| 6012 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 6013 | * other versions of NFS can be tried. |
| 6014 | */ |
| 6015 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 6016 | { |
| 6017 | int ret; |
| 6018 | |
| 6019 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 6020 | ret = nfs4_client_recover_expired_lease(clp); |
| 6021 | if (ret) |
| 6022 | return ret; |
| 6023 | } |
| 6024 | if (clp->cl_cons_state < NFS_CS_READY) |
| 6025 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 6026 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6027 | return 0; |
| 6028 | } |
| 6029 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6030 | int nfs4_init_session(struct nfs_server *server) |
| 6031 | { |
| 6032 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6033 | struct nfs4_session *session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6034 | unsigned int target_max_rqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 6035 | unsigned int target_max_resp_sz = NFS_MAX_FILE_IO_SIZE; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6036 | |
| 6037 | if (!nfs4_has_session(clp)) |
| 6038 | return 0; |
| 6039 | |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6040 | if (server->rsize != 0) |
| 6041 | target_max_resp_sz = server->rsize; |
| 6042 | target_max_resp_sz += nfs41_maxread_overhead; |
| 6043 | |
| 6044 | if (server->wsize != 0) |
| 6045 | target_max_rqst_sz = server->wsize; |
| 6046 | target_max_rqst_sz += nfs41_maxwrite_overhead; |
| 6047 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6048 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6049 | spin_lock(&clp->cl_lock); |
| 6050 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6051 | /* Initialise targets and channel attributes */ |
| 6052 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6053 | session->fc_attrs.max_rqst_sz = target_max_rqst_sz; |
| 6054 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6055 | session->fc_attrs.max_resp_sz = target_max_resp_sz; |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6056 | } else { |
| 6057 | /* Just adjust the targets */ |
| 6058 | if (target_max_rqst_sz > session->fc_target_max_rqst_sz) { |
| 6059 | session->fc_target_max_rqst_sz = target_max_rqst_sz; |
| 6060 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6061 | } |
| 6062 | if (target_max_resp_sz > session->fc_target_max_resp_sz) { |
| 6063 | session->fc_target_max_resp_sz = target_max_resp_sz; |
| 6064 | set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
| 6065 | } |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6066 | } |
| 6067 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6068 | |
Trond Myklebust | 688a902 | 2012-11-20 10:53:39 -0500 | [diff] [blame] | 6069 | if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)) |
| 6070 | nfs4_schedule_lease_recovery(clp); |
| 6071 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6072 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6073 | } |
| 6074 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6075 | 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] | 6076 | { |
| 6077 | struct nfs4_session *session = clp->cl_session; |
| 6078 | int ret; |
| 6079 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6080 | spin_lock(&clp->cl_lock); |
| 6081 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 6082 | /* |
| 6083 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 6084 | * DS lease to be equal to the MDS lease. |
| 6085 | */ |
| 6086 | clp->cl_lease_time = lease_time; |
| 6087 | clp->cl_last_renewal = jiffies; |
| 6088 | } |
| 6089 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6090 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6091 | ret = nfs41_check_session_ready(clp); |
| 6092 | if (ret) |
| 6093 | return ret; |
| 6094 | /* Test for the DS role */ |
| 6095 | if (!is_ds_client(clp)) |
| 6096 | return -ENODEV; |
| 6097 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6098 | } |
| 6099 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 6100 | |
| 6101 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6102 | /* |
| 6103 | * Renew the cl_session lease. |
| 6104 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6105 | struct nfs4_sequence_data { |
| 6106 | struct nfs_client *clp; |
| 6107 | struct nfs4_sequence_args args; |
| 6108 | struct nfs4_sequence_res res; |
| 6109 | }; |
| 6110 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6111 | static void nfs41_sequence_release(void *data) |
| 6112 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6113 | struct nfs4_sequence_data *calldata = data; |
| 6114 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6115 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6116 | if (atomic_read(&clp->cl_count) > 1) |
| 6117 | nfs4_schedule_state_renewal(clp); |
| 6118 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6119 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6120 | } |
| 6121 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6122 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6123 | { |
| 6124 | switch(task->tk_status) { |
| 6125 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6126 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6127 | return -EAGAIN; |
| 6128 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6129 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6130 | } |
| 6131 | return 0; |
| 6132 | } |
| 6133 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6134 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6135 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6136 | struct nfs4_sequence_data *calldata = data; |
| 6137 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6138 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6139 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6140 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6141 | |
| 6142 | if (task->tk_status < 0) { |
| 6143 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6144 | if (atomic_read(&clp->cl_count) == 1) |
| 6145 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6146 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6147 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6148 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6149 | return; |
| 6150 | } |
| 6151 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6152 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6153 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6154 | dprintk("<-- %s\n", __func__); |
| 6155 | } |
| 6156 | |
| 6157 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6158 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6159 | struct nfs4_sequence_data *calldata = data; |
| 6160 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6161 | struct nfs4_sequence_args *args; |
| 6162 | struct nfs4_sequence_res *res; |
| 6163 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6164 | args = task->tk_msg.rpc_argp; |
| 6165 | res = task->tk_msg.rpc_resp; |
| 6166 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6167 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6168 | return; |
| 6169 | rpc_call_start(task); |
| 6170 | } |
| 6171 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6172 | static void nfs41_sequence_prepare_privileged(struct rpc_task *task, void *data) |
| 6173 | { |
| 6174 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 6175 | nfs41_sequence_prepare(task, data); |
| 6176 | } |
| 6177 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6178 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6179 | .rpc_call_done = nfs41_sequence_call_done, |
| 6180 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6181 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6182 | }; |
| 6183 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6184 | static const struct rpc_call_ops nfs41_sequence_privileged_ops = { |
| 6185 | .rpc_call_done = nfs41_sequence_call_done, |
| 6186 | .rpc_call_prepare = nfs41_sequence_prepare_privileged, |
| 6187 | .rpc_release = nfs41_sequence_release, |
| 6188 | }; |
| 6189 | |
| 6190 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred, |
| 6191 | const struct rpc_call_ops *seq_ops) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6192 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6193 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6194 | struct rpc_message msg = { |
| 6195 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6196 | .rpc_cred = cred, |
| 6197 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6198 | struct rpc_task_setup task_setup_data = { |
| 6199 | .rpc_client = clp->cl_rpcclient, |
| 6200 | .rpc_message = &msg, |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6201 | .callback_ops = seq_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6202 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6203 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6204 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6205 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6206 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6207 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6208 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6209 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6210 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6211 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6212 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6213 | msg.rpc_argp = &calldata->args; |
| 6214 | msg.rpc_resp = &calldata->res; |
| 6215 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6216 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6217 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6218 | return rpc_run_task(&task_setup_data); |
| 6219 | } |
| 6220 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6221 | 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] | 6222 | { |
| 6223 | struct rpc_task *task; |
| 6224 | int ret = 0; |
| 6225 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6226 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6227 | return 0; |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6228 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6229 | if (IS_ERR(task)) |
| 6230 | ret = PTR_ERR(task); |
| 6231 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6232 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6233 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6234 | return ret; |
| 6235 | } |
| 6236 | |
| 6237 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6238 | { |
| 6239 | struct rpc_task *task; |
| 6240 | int ret; |
| 6241 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 6242 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_privileged_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6243 | if (IS_ERR(task)) { |
| 6244 | ret = PTR_ERR(task); |
| 6245 | goto out; |
| 6246 | } |
| 6247 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6248 | if (!ret) { |
| 6249 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6250 | |
| 6251 | if (task->tk_status == 0) |
| 6252 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6253 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6254 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6255 | rpc_put_task(task); |
| 6256 | out: |
| 6257 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6258 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6259 | } |
| 6260 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6261 | struct nfs4_reclaim_complete_data { |
| 6262 | struct nfs_client *clp; |
| 6263 | struct nfs41_reclaim_complete_args arg; |
| 6264 | struct nfs41_reclaim_complete_res res; |
| 6265 | }; |
| 6266 | |
| 6267 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6268 | { |
| 6269 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6270 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6271 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6272 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6273 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6274 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6275 | return; |
| 6276 | |
| 6277 | rpc_call_start(task); |
| 6278 | } |
| 6279 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6280 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6281 | { |
| 6282 | switch(task->tk_status) { |
| 6283 | case 0: |
| 6284 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6285 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6286 | break; |
| 6287 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6288 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6289 | /* fall through */ |
| 6290 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6291 | return -EAGAIN; |
| 6292 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6293 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6294 | } |
| 6295 | return 0; |
| 6296 | } |
| 6297 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6298 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6299 | { |
| 6300 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6301 | struct nfs_client *clp = calldata->clp; |
| 6302 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6303 | |
| 6304 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6305 | if (!nfs41_sequence_done(task, res)) |
| 6306 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6307 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6308 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6309 | rpc_restart_call_prepare(task); |
| 6310 | return; |
| 6311 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6312 | dprintk("<-- %s\n", __func__); |
| 6313 | } |
| 6314 | |
| 6315 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6316 | { |
| 6317 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6318 | |
| 6319 | kfree(calldata); |
| 6320 | } |
| 6321 | |
| 6322 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6323 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6324 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6325 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6326 | }; |
| 6327 | |
| 6328 | /* |
| 6329 | * Issue a global reclaim complete. |
| 6330 | */ |
| 6331 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6332 | { |
| 6333 | struct nfs4_reclaim_complete_data *calldata; |
| 6334 | struct rpc_task *task; |
| 6335 | struct rpc_message msg = { |
| 6336 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6337 | }; |
| 6338 | struct rpc_task_setup task_setup_data = { |
| 6339 | .rpc_client = clp->cl_rpcclient, |
| 6340 | .rpc_message = &msg, |
| 6341 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6342 | .flags = RPC_TASK_ASYNC, |
| 6343 | }; |
| 6344 | int status = -ENOMEM; |
| 6345 | |
| 6346 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6347 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6348 | if (calldata == NULL) |
| 6349 | goto out; |
| 6350 | calldata->clp = clp; |
| 6351 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6352 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6353 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6354 | msg.rpc_argp = &calldata->arg; |
| 6355 | msg.rpc_resp = &calldata->res; |
| 6356 | task_setup_data.callback_data = calldata; |
| 6357 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6358 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6359 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6360 | goto out; |
| 6361 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6362 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6363 | if (status == 0) |
| 6364 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6365 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6366 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6367 | out: |
| 6368 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6369 | return status; |
| 6370 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6371 | |
| 6372 | static void |
| 6373 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6374 | { |
| 6375 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6376 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6377 | |
| 6378 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6379 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6380 | * right now covering the LAYOUTGET we are about to send. |
| 6381 | * However, that is not so catastrophic, and there seems |
| 6382 | * to be no way to prevent it completely. |
| 6383 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6384 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6385 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6386 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6387 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6388 | NFS_I(lgp->args.inode)->layout, |
| 6389 | lgp->args.ctx->state)) { |
| 6390 | rpc_exit(task, NFS4_OK); |
| 6391 | return; |
| 6392 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6393 | rpc_call_start(task); |
| 6394 | } |
| 6395 | |
| 6396 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6397 | { |
| 6398 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6399 | struct inode *inode = lgp->args.inode; |
| 6400 | struct nfs_server *server = NFS_SERVER(inode); |
| 6401 | struct pnfs_layout_hdr *lo; |
| 6402 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6403 | |
| 6404 | dprintk("--> %s\n", __func__); |
| 6405 | |
| 6406 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6407 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6408 | |
| 6409 | switch (task->tk_status) { |
| 6410 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6411 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6412 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6413 | case -NFS4ERR_RECALLCONFLICT: |
| 6414 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6415 | break; |
| 6416 | case -NFS4ERR_EXPIRED: |
| 6417 | case -NFS4ERR_BAD_STATEID: |
| 6418 | spin_lock(&inode->i_lock); |
| 6419 | lo = NFS_I(inode)->layout; |
| 6420 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6421 | spin_unlock(&inode->i_lock); |
| 6422 | /* If the open stateid was bad, then recover it. */ |
| 6423 | state = lgp->args.ctx->state; |
| 6424 | } else { |
| 6425 | LIST_HEAD(head); |
| 6426 | |
| 6427 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6428 | spin_unlock(&inode->i_lock); |
| 6429 | /* Mark the bad layout state as invalid, then |
| 6430 | * retry using the open stateid. */ |
| 6431 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6432 | } |
| 6433 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6434 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6435 | rpc_restart_call_prepare(task); |
| 6436 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6437 | dprintk("<-- %s\n", __func__); |
| 6438 | } |
| 6439 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6440 | static size_t max_response_pages(struct nfs_server *server) |
| 6441 | { |
| 6442 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6443 | return nfs_page_array_len(0, max_resp_sz); |
| 6444 | } |
| 6445 | |
| 6446 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6447 | { |
| 6448 | int i; |
| 6449 | |
| 6450 | if (!pages) |
| 6451 | return; |
| 6452 | |
| 6453 | for (i = 0; i < size; i++) { |
| 6454 | if (!pages[i]) |
| 6455 | break; |
| 6456 | __free_page(pages[i]); |
| 6457 | } |
| 6458 | kfree(pages); |
| 6459 | } |
| 6460 | |
| 6461 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6462 | { |
| 6463 | struct page **pages; |
| 6464 | int i; |
| 6465 | |
| 6466 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6467 | if (!pages) { |
| 6468 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6469 | return NULL; |
| 6470 | } |
| 6471 | |
| 6472 | for (i = 0; i < size; i++) { |
| 6473 | pages[i] = alloc_page(gfp_flags); |
| 6474 | if (!pages[i]) { |
| 6475 | dprintk("%s: failed to allocate page\n", __func__); |
| 6476 | nfs4_free_pages(pages, size); |
| 6477 | return NULL; |
| 6478 | } |
| 6479 | } |
| 6480 | |
| 6481 | return pages; |
| 6482 | } |
| 6483 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6484 | static void nfs4_layoutget_release(void *calldata) |
| 6485 | { |
| 6486 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6487 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6488 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6489 | |
| 6490 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6491 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6492 | put_nfs_open_context(lgp->args.ctx); |
| 6493 | kfree(calldata); |
| 6494 | dprintk("<-- %s\n", __func__); |
| 6495 | } |
| 6496 | |
| 6497 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6498 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6499 | .rpc_call_done = nfs4_layoutget_done, |
| 6500 | .rpc_release = nfs4_layoutget_release, |
| 6501 | }; |
| 6502 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6503 | struct pnfs_layout_segment * |
| 6504 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6505 | { |
| 6506 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6507 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6508 | struct rpc_task *task; |
| 6509 | struct rpc_message msg = { |
| 6510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6511 | .rpc_argp = &lgp->args, |
| 6512 | .rpc_resp = &lgp->res, |
| 6513 | }; |
| 6514 | struct rpc_task_setup task_setup_data = { |
| 6515 | .rpc_client = server->client, |
| 6516 | .rpc_message = &msg, |
| 6517 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6518 | .callback_data = lgp, |
| 6519 | .flags = RPC_TASK_ASYNC, |
| 6520 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6521 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6522 | int status = 0; |
| 6523 | |
| 6524 | dprintk("--> %s\n", __func__); |
| 6525 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6526 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6527 | if (!lgp->args.layout.pages) { |
| 6528 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6529 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6530 | } |
| 6531 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6532 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6533 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6534 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6535 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6536 | task = rpc_run_task(&task_setup_data); |
| 6537 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6538 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6539 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6540 | if (status == 0) |
| 6541 | status = task->tk_status; |
| 6542 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6543 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6544 | rpc_put_task(task); |
| 6545 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6546 | if (status) |
| 6547 | return ERR_PTR(status); |
| 6548 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6549 | } |
| 6550 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6551 | static void |
| 6552 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6553 | { |
| 6554 | struct nfs4_layoutreturn *lrp = calldata; |
| 6555 | |
| 6556 | dprintk("--> %s\n", __func__); |
| 6557 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6558 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6559 | return; |
| 6560 | rpc_call_start(task); |
| 6561 | } |
| 6562 | |
| 6563 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6564 | { |
| 6565 | struct nfs4_layoutreturn *lrp = calldata; |
| 6566 | struct nfs_server *server; |
| 6567 | |
| 6568 | dprintk("--> %s\n", __func__); |
| 6569 | |
| 6570 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6571 | return; |
| 6572 | |
| 6573 | server = NFS_SERVER(lrp->args.inode); |
| 6574 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6575 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6576 | return; |
| 6577 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6578 | dprintk("<-- %s\n", __func__); |
| 6579 | } |
| 6580 | |
| 6581 | static void nfs4_layoutreturn_release(void *calldata) |
| 6582 | { |
| 6583 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6584 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6585 | |
| 6586 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6587 | spin_lock(&lo->plh_inode->i_lock); |
| 6588 | if (lrp->res.lrs_present) |
| 6589 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6590 | lo->plh_block_lgets--; |
| 6591 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6592 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6593 | kfree(calldata); |
| 6594 | dprintk("<-- %s\n", __func__); |
| 6595 | } |
| 6596 | |
| 6597 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6598 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6599 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6600 | .rpc_release = nfs4_layoutreturn_release, |
| 6601 | }; |
| 6602 | |
| 6603 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6604 | { |
| 6605 | struct rpc_task *task; |
| 6606 | struct rpc_message msg = { |
| 6607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6608 | .rpc_argp = &lrp->args, |
| 6609 | .rpc_resp = &lrp->res, |
| 6610 | }; |
| 6611 | struct rpc_task_setup task_setup_data = { |
| 6612 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6613 | .rpc_message = &msg, |
| 6614 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6615 | .callback_data = lrp, |
| 6616 | }; |
| 6617 | int status; |
| 6618 | |
| 6619 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6620 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6621 | task = rpc_run_task(&task_setup_data); |
| 6622 | if (IS_ERR(task)) |
| 6623 | return PTR_ERR(task); |
| 6624 | status = task->tk_status; |
| 6625 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6626 | rpc_put_task(task); |
| 6627 | return status; |
| 6628 | } |
| 6629 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6630 | /* |
| 6631 | * Retrieve the list of Data Server devices from the MDS. |
| 6632 | */ |
| 6633 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6634 | const struct nfs_fh *fh, |
| 6635 | struct pnfs_devicelist *devlist) |
| 6636 | { |
| 6637 | struct nfs4_getdevicelist_args args = { |
| 6638 | .fh = fh, |
| 6639 | .layoutclass = server->pnfs_curr_ld->id, |
| 6640 | }; |
| 6641 | struct nfs4_getdevicelist_res res = { |
| 6642 | .devlist = devlist, |
| 6643 | }; |
| 6644 | struct rpc_message msg = { |
| 6645 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6646 | .rpc_argp = &args, |
| 6647 | .rpc_resp = &res, |
| 6648 | }; |
| 6649 | int status; |
| 6650 | |
| 6651 | dprintk("--> %s\n", __func__); |
| 6652 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6653 | &res.seq_res, 0); |
| 6654 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6655 | return status; |
| 6656 | } |
| 6657 | |
| 6658 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6659 | const struct nfs_fh *fh, |
| 6660 | struct pnfs_devicelist *devlist) |
| 6661 | { |
| 6662 | struct nfs4_exception exception = { }; |
| 6663 | int err; |
| 6664 | |
| 6665 | do { |
| 6666 | err = nfs4_handle_exception(server, |
| 6667 | _nfs4_getdevicelist(server, fh, devlist), |
| 6668 | &exception); |
| 6669 | } while (exception.retry); |
| 6670 | |
| 6671 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6672 | err, devlist->num_devs); |
| 6673 | |
| 6674 | return err; |
| 6675 | } |
| 6676 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6677 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6678 | static int |
| 6679 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6680 | { |
| 6681 | struct nfs4_getdeviceinfo_args args = { |
| 6682 | .pdev = pdev, |
| 6683 | }; |
| 6684 | struct nfs4_getdeviceinfo_res res = { |
| 6685 | .pdev = pdev, |
| 6686 | }; |
| 6687 | struct rpc_message msg = { |
| 6688 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6689 | .rpc_argp = &args, |
| 6690 | .rpc_resp = &res, |
| 6691 | }; |
| 6692 | int status; |
| 6693 | |
| 6694 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6695 | 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] | 6696 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6697 | |
| 6698 | return status; |
| 6699 | } |
| 6700 | |
| 6701 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6702 | { |
| 6703 | struct nfs4_exception exception = { }; |
| 6704 | int err; |
| 6705 | |
| 6706 | do { |
| 6707 | err = nfs4_handle_exception(server, |
| 6708 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6709 | &exception); |
| 6710 | } while (exception.retry); |
| 6711 | return err; |
| 6712 | } |
| 6713 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6714 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6715 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6716 | { |
| 6717 | struct nfs4_layoutcommit_data *data = calldata; |
| 6718 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6719 | |
| 6720 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6721 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6722 | return; |
| 6723 | rpc_call_start(task); |
| 6724 | } |
| 6725 | |
| 6726 | static void |
| 6727 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6728 | { |
| 6729 | struct nfs4_layoutcommit_data *data = calldata; |
| 6730 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6731 | |
| 6732 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6733 | return; |
| 6734 | |
| 6735 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6736 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6737 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6738 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6739 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6740 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6741 | break; |
| 6742 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6743 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6744 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6745 | break; |
| 6746 | default: |
| 6747 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6748 | rpc_restart_call_prepare(task); |
| 6749 | return; |
| 6750 | } |
| 6751 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6752 | } |
| 6753 | |
| 6754 | static void nfs4_layoutcommit_release(void *calldata) |
| 6755 | { |
| 6756 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6757 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6758 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6759 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6760 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6761 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6762 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6763 | list_del_init(&lseg->pls_lc_list); |
| 6764 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6765 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6766 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6767 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6768 | |
| 6769 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6770 | smp_mb__after_clear_bit(); |
| 6771 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6772 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6773 | put_rpccred(data->cred); |
| 6774 | kfree(data); |
| 6775 | } |
| 6776 | |
| 6777 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6778 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6779 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6780 | .rpc_release = nfs4_layoutcommit_release, |
| 6781 | }; |
| 6782 | |
| 6783 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6784 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6785 | { |
| 6786 | struct rpc_message msg = { |
| 6787 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6788 | .rpc_argp = &data->args, |
| 6789 | .rpc_resp = &data->res, |
| 6790 | .rpc_cred = data->cred, |
| 6791 | }; |
| 6792 | struct rpc_task_setup task_setup_data = { |
| 6793 | .task = &data->task, |
| 6794 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6795 | .rpc_message = &msg, |
| 6796 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6797 | .callback_data = data, |
| 6798 | .flags = RPC_TASK_ASYNC, |
| 6799 | }; |
| 6800 | struct rpc_task *task; |
| 6801 | int status = 0; |
| 6802 | |
| 6803 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6804 | "lbw: %llu inode %lu\n", |
| 6805 | data->task.tk_pid, sync, |
| 6806 | data->args.lastbytewritten, |
| 6807 | data->args.inode->i_ino); |
| 6808 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6809 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6810 | task = rpc_run_task(&task_setup_data); |
| 6811 | if (IS_ERR(task)) |
| 6812 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6813 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6814 | goto out; |
| 6815 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6816 | if (status != 0) |
| 6817 | goto out; |
| 6818 | status = task->tk_status; |
| 6819 | out: |
| 6820 | dprintk("%s: status %d\n", __func__, status); |
| 6821 | rpc_put_task(task); |
| 6822 | return status; |
| 6823 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6824 | |
| 6825 | static int |
| 6826 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6827 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6828 | { |
| 6829 | struct nfs41_secinfo_no_name_args args = { |
| 6830 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6831 | }; |
| 6832 | struct nfs4_secinfo_res res = { |
| 6833 | .flavors = flavors, |
| 6834 | }; |
| 6835 | struct rpc_message msg = { |
| 6836 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6837 | .rpc_argp = &args, |
| 6838 | .rpc_resp = &res, |
| 6839 | }; |
| 6840 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6841 | } |
| 6842 | |
| 6843 | static int |
| 6844 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6845 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6846 | { |
| 6847 | struct nfs4_exception exception = { }; |
| 6848 | int err; |
| 6849 | do { |
| 6850 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6851 | switch (err) { |
| 6852 | case 0: |
| 6853 | case -NFS4ERR_WRONGSEC: |
| 6854 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6855 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6856 | default: |
| 6857 | err = nfs4_handle_exception(server, err, &exception); |
| 6858 | } |
| 6859 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6860 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6861 | return err; |
| 6862 | } |
| 6863 | |
| 6864 | static int |
| 6865 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6866 | struct nfs_fsinfo *info) |
| 6867 | { |
| 6868 | int err; |
| 6869 | struct page *page; |
| 6870 | rpc_authflavor_t flavor; |
| 6871 | struct nfs4_secinfo_flavors *flavors; |
| 6872 | |
| 6873 | page = alloc_page(GFP_KERNEL); |
| 6874 | if (!page) { |
| 6875 | err = -ENOMEM; |
| 6876 | goto out; |
| 6877 | } |
| 6878 | |
| 6879 | flavors = page_address(page); |
| 6880 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6881 | |
| 6882 | /* |
| 6883 | * Fall back on "guess and check" method if |
| 6884 | * the server doesn't support SECINFO_NO_NAME |
| 6885 | */ |
| 6886 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6887 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6888 | goto out_freepage; |
| 6889 | } |
| 6890 | if (err) |
| 6891 | goto out_freepage; |
| 6892 | |
| 6893 | flavor = nfs_find_best_sec(flavors); |
| 6894 | if (err == 0) |
| 6895 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6896 | |
| 6897 | out_freepage: |
| 6898 | put_page(page); |
| 6899 | if (err == -EACCES) |
| 6900 | return -EPERM; |
| 6901 | out: |
| 6902 | return err; |
| 6903 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6904 | |
| 6905 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6906 | { |
| 6907 | int status; |
| 6908 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6909 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6910 | }; |
| 6911 | struct nfs41_test_stateid_res res; |
| 6912 | struct rpc_message msg = { |
| 6913 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6914 | .rpc_argp = &args, |
| 6915 | .rpc_resp = &res, |
| 6916 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6917 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6918 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6919 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6920 | 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] | 6921 | if (status != NFS_OK) { |
| 6922 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6923 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6924 | } |
| 6925 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6926 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6927 | } |
| 6928 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6929 | /** |
| 6930 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6931 | * |
| 6932 | * @server: server / transport on which to perform the operation |
| 6933 | * @stateid: state ID to test |
| 6934 | * |
| 6935 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6936 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6937 | * failed or the state ID is not currently valid. |
| 6938 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6939 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6940 | { |
| 6941 | struct nfs4_exception exception = { }; |
| 6942 | int err; |
| 6943 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6944 | err = _nfs41_test_stateid(server, stateid); |
| 6945 | if (err != -NFS4ERR_DELAY) |
| 6946 | break; |
| 6947 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6948 | } while (exception.retry); |
| 6949 | return err; |
| 6950 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6951 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6952 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6953 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6954 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6955 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6956 | }; |
| 6957 | struct nfs41_free_stateid_res res; |
| 6958 | struct rpc_message msg = { |
| 6959 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6960 | .rpc_argp = &args, |
| 6961 | .rpc_resp = &res, |
| 6962 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6963 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6964 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6965 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6966 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6967 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6968 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6969 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6970 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6971 | } |
| 6972 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6973 | /** |
| 6974 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6975 | * |
| 6976 | * @server: server / transport on which to perform the operation |
| 6977 | * @stateid: state ID to release |
| 6978 | * |
| 6979 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6980 | * negative NFS4ERR value is returned. |
| 6981 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6982 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6983 | { |
| 6984 | struct nfs4_exception exception = { }; |
| 6985 | int err; |
| 6986 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6987 | err = _nfs4_free_stateid(server, stateid); |
| 6988 | if (err != -NFS4ERR_DELAY) |
| 6989 | break; |
| 6990 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6991 | } while (exception.retry); |
| 6992 | return err; |
| 6993 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6994 | |
| 6995 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6996 | const nfs4_stateid *s2) |
| 6997 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6998 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6999 | return false; |
| 7000 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7001 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7002 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7003 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7004 | return true; |
| 7005 | |
| 7006 | return false; |
| 7007 | } |
| 7008 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7009 | #endif /* CONFIG_NFS_V4_1 */ |
| 7010 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7011 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7012 | const nfs4_stateid *s2) |
| 7013 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7014 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7015 | } |
| 7016 | |
| 7017 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7018 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7019 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7020 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7021 | .recover_open = nfs4_open_reclaim, |
| 7022 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7023 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7024 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7025 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7026 | }; |
| 7027 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7028 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7029 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7030 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7031 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7032 | .recover_open = nfs4_open_reclaim, |
| 7033 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7034 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7035 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7036 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7037 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7038 | }; |
| 7039 | #endif /* CONFIG_NFS_V4_1 */ |
| 7040 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7041 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7042 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7043 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7044 | .recover_open = nfs4_open_expired, |
| 7045 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7046 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7047 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7048 | }; |
| 7049 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7050 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7051 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7052 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7053 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7054 | .recover_open = nfs41_open_expired, |
| 7055 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7056 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7057 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7058 | }; |
| 7059 | #endif /* CONFIG_NFS_V4_1 */ |
| 7060 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7061 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7062 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7063 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7064 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7065 | }; |
| 7066 | |
| 7067 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7068 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7069 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7070 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7071 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7072 | }; |
| 7073 | #endif |
| 7074 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7075 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7076 | .minor_version = 0, |
| 7077 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7078 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7079 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7080 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7081 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7082 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7083 | }; |
| 7084 | |
| 7085 | #if defined(CONFIG_NFS_V4_1) |
| 7086 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7087 | .minor_version = 1, |
| 7088 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7089 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7090 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7091 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7092 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7093 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7094 | }; |
| 7095 | #endif |
| 7096 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7097 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7098 | [0] = &nfs_v4_0_minor_ops, |
| 7099 | #if defined(CONFIG_NFS_V4_1) |
| 7100 | [1] = &nfs_v4_1_minor_ops, |
| 7101 | #endif |
| 7102 | }; |
| 7103 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7104 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7105 | .create = nfs_create, |
| 7106 | .lookup = nfs_lookup, |
| 7107 | .atomic_open = nfs_atomic_open, |
| 7108 | .link = nfs_link, |
| 7109 | .unlink = nfs_unlink, |
| 7110 | .symlink = nfs_symlink, |
| 7111 | .mkdir = nfs_mkdir, |
| 7112 | .rmdir = nfs_rmdir, |
| 7113 | .mknod = nfs_mknod, |
| 7114 | .rename = nfs_rename, |
| 7115 | .permission = nfs_permission, |
| 7116 | .getattr = nfs_getattr, |
| 7117 | .setattr = nfs_setattr, |
| 7118 | .getxattr = generic_getxattr, |
| 7119 | .setxattr = generic_setxattr, |
| 7120 | .listxattr = generic_listxattr, |
| 7121 | .removexattr = generic_removexattr, |
| 7122 | }; |
| 7123 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7124 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7125 | .permission = nfs_permission, |
| 7126 | .getattr = nfs_getattr, |
| 7127 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7128 | .getxattr = generic_getxattr, |
| 7129 | .setxattr = generic_setxattr, |
| 7130 | .listxattr = generic_listxattr, |
| 7131 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7132 | }; |
| 7133 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7134 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7135 | .version = 4, /* protocol version */ |
| 7136 | .dentry_ops = &nfs4_dentry_operations, |
| 7137 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7138 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7139 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7140 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7141 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7142 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7143 | .getattr = nfs4_proc_getattr, |
| 7144 | .setattr = nfs4_proc_setattr, |
| 7145 | .lookup = nfs4_proc_lookup, |
| 7146 | .access = nfs4_proc_access, |
| 7147 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7148 | .create = nfs4_proc_create, |
| 7149 | .remove = nfs4_proc_remove, |
| 7150 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7151 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7152 | .unlink_done = nfs4_proc_unlink_done, |
| 7153 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7154 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7155 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7156 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7157 | .link = nfs4_proc_link, |
| 7158 | .symlink = nfs4_proc_symlink, |
| 7159 | .mkdir = nfs4_proc_mkdir, |
| 7160 | .rmdir = nfs4_proc_remove, |
| 7161 | .readdir = nfs4_proc_readdir, |
| 7162 | .mknod = nfs4_proc_mknod, |
| 7163 | .statfs = nfs4_proc_statfs, |
| 7164 | .fsinfo = nfs4_proc_fsinfo, |
| 7165 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7166 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7167 | .decode_dirent = nfs4_decode_dirent, |
| 7168 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7169 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7170 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7171 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7172 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7173 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7174 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7175 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7176 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7177 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7178 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7179 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7180 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7181 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7182 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7183 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7184 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7185 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7186 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7187 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7188 | .create_server = nfs4_create_server, |
| 7189 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7190 | }; |
| 7191 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7192 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7193 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7194 | .list = nfs4_xattr_list_nfs4_acl, |
| 7195 | .get = nfs4_xattr_get_nfs4_acl, |
| 7196 | .set = nfs4_xattr_set_nfs4_acl, |
| 7197 | }; |
| 7198 | |
| 7199 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7200 | &nfs4_xattr_nfs4_acl_handler, |
| 7201 | NULL |
| 7202 | }; |
| 7203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7204 | /* |
| 7205 | * Local variables: |
| 7206 | * c-basic-offset: 8 |
| 7207 | * End: |
| 7208 | */ |