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> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 70 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 73 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 74 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 75 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 76 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | 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] | 78 | 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] | 79 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 80 | 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] | 81 | 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] | 82 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 83 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 84 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 85 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 86 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 87 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 90 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 92 | if (err >= -1000) |
| 93 | return err; |
| 94 | switch (err) { |
| 95 | case -NFS4ERR_RESOURCE: |
| 96 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 97 | case -NFS4ERR_WRONGSEC: |
| 98 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 99 | case -NFS4ERR_BADOWNER: |
| 100 | case -NFS4ERR_BADNAME: |
| 101 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 102 | case -NFS4ERR_SHARE_DENIED: |
| 103 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 104 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 105 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 106 | case -NFS4ERR_ACCESS: |
| 107 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 108 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 110 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 111 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 113 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
| 117 | * This is our standard bitmap for GETATTR requests. |
| 118 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 119 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | FATTR4_WORD0_TYPE |
| 121 | | FATTR4_WORD0_CHANGE |
| 122 | | FATTR4_WORD0_SIZE |
| 123 | | FATTR4_WORD0_FSID |
| 124 | | FATTR4_WORD0_FILEID, |
| 125 | FATTR4_WORD1_MODE |
| 126 | | FATTR4_WORD1_NUMLINKS |
| 127 | | FATTR4_WORD1_OWNER |
| 128 | | FATTR4_WORD1_OWNER_GROUP |
| 129 | | FATTR4_WORD1_RAWDEV |
| 130 | | FATTR4_WORD1_SPACE_USED |
| 131 | | FATTR4_WORD1_TIME_ACCESS |
| 132 | | FATTR4_WORD1_TIME_METADATA |
| 133 | | FATTR4_WORD1_TIME_MODIFY |
| 134 | }; |
| 135 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 136 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 137 | FATTR4_WORD0_TYPE |
| 138 | | FATTR4_WORD0_CHANGE |
| 139 | | FATTR4_WORD0_SIZE |
| 140 | | FATTR4_WORD0_FSID |
| 141 | | FATTR4_WORD0_FILEID, |
| 142 | FATTR4_WORD1_MODE |
| 143 | | FATTR4_WORD1_NUMLINKS |
| 144 | | FATTR4_WORD1_OWNER |
| 145 | | FATTR4_WORD1_OWNER_GROUP |
| 146 | | FATTR4_WORD1_RAWDEV |
| 147 | | FATTR4_WORD1_SPACE_USED |
| 148 | | FATTR4_WORD1_TIME_ACCESS |
| 149 | | FATTR4_WORD1_TIME_METADATA |
| 150 | | FATTR4_WORD1_TIME_MODIFY, |
| 151 | FATTR4_WORD2_MDSTHRESHOLD |
| 152 | }; |
| 153 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 154 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 155 | FATTR4_WORD0_TYPE |
| 156 | | FATTR4_WORD0_CHANGE |
| 157 | | FATTR4_WORD0_FILEID, |
| 158 | }; |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | const u32 nfs4_statfs_bitmap[2] = { |
| 161 | FATTR4_WORD0_FILES_AVAIL |
| 162 | | FATTR4_WORD0_FILES_FREE |
| 163 | | FATTR4_WORD0_FILES_TOTAL, |
| 164 | FATTR4_WORD1_SPACE_AVAIL |
| 165 | | FATTR4_WORD1_SPACE_FREE |
| 166 | | FATTR4_WORD1_SPACE_TOTAL |
| 167 | }; |
| 168 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 169 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | FATTR4_WORD0_MAXLINK |
| 171 | | FATTR4_WORD0_MAXNAME, |
| 172 | 0 |
| 173 | }; |
| 174 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 175 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | | FATTR4_WORD0_MAXREAD |
| 177 | | FATTR4_WORD0_MAXWRITE |
| 178 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 179 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 180 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 181 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 184 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 185 | FATTR4_WORD0_TYPE |
| 186 | | FATTR4_WORD0_CHANGE |
| 187 | | FATTR4_WORD0_SIZE |
| 188 | | FATTR4_WORD0_FSID |
| 189 | | FATTR4_WORD0_FILEID |
| 190 | | FATTR4_WORD0_FS_LOCATIONS, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
| 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 201 | }; |
| 202 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 203 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | struct nfs4_readdir_arg *readdir) |
| 205 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 206 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 209 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | readdir->cookie = 0; |
| 215 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 216 | if (cookie == 2) |
| 217 | return; |
| 218 | |
| 219 | /* |
| 220 | * NFSv4 servers do not return entries for '.' and '..' |
| 221 | * Therefore, we fake these entries here. We let '.' |
| 222 | * have cookie 0 and '..' have cookie 1. Note that |
| 223 | * when talking to the server, we always send cookie 0 |
| 224 | * instead of 1 or 2. |
| 225 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 226 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | if (cookie == 0) { |
| 229 | *p++ = xdr_one; /* next */ |
| 230 | *p++ = xdr_zero; /* cookie, first word */ |
| 231 | *p++ = xdr_one; /* cookie, second word */ |
| 232 | *p++ = xdr_one; /* entry len */ |
| 233 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 234 | p++; |
| 235 | *p++ = xdr_one; /* bitmap length */ |
| 236 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 237 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 238 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | *p++ = xdr_one; /* next */ |
| 242 | *p++ = xdr_zero; /* cookie, first word */ |
| 243 | *p++ = xdr_two; /* cookie, second word */ |
| 244 | *p++ = xdr_two; /* entry len */ |
| 245 | memcpy(p, "..\0\0", 4); /* entry */ |
| 246 | p++; |
| 247 | *p++ = xdr_one; /* bitmap length */ |
| 248 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 249 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 250 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | readdir->pgbase = (char *)p - (char *)start; |
| 253 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 254 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 257 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 258 | { |
| 259 | int res = 0; |
| 260 | |
| 261 | might_sleep(); |
| 262 | |
| 263 | if (*timeout <= 0) |
| 264 | *timeout = NFS4_POLL_RETRY_MIN; |
| 265 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 266 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 267 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 268 | if (fatal_signal_pending(current)) |
| 269 | res = -ERESTARTSYS; |
| 270 | *timeout <<= 1; |
| 271 | return res; |
| 272 | } |
| 273 | |
| 274 | /* This is the error handling routine for processes that are allowed |
| 275 | * to sleep. |
| 276 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 277 | 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] | 278 | { |
| 279 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 280 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 281 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 282 | int ret = errorcode; |
| 283 | |
| 284 | exception->retry = 0; |
| 285 | switch(errorcode) { |
| 286 | case 0: |
| 287 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 288 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 289 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 290 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 291 | exception->retry = 1; |
| 292 | return 0; |
| 293 | } |
| 294 | if (state == NULL) |
| 295 | break; |
| 296 | nfs4_schedule_stateid_recovery(server, state); |
| 297 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 298 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 299 | case -NFS4ERR_ADMIN_REVOKED: |
| 300 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 301 | if (state == NULL) |
| 302 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 303 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 304 | nfs4_schedule_stateid_recovery(server, state); |
| 305 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 306 | case -NFS4ERR_EXPIRED: |
| 307 | if (state != NULL) |
| 308 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 309 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 310 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 311 | nfs4_schedule_lease_recovery(clp); |
| 312 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 313 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 314 | case -NFS4ERR_BADSESSION: |
| 315 | case -NFS4ERR_BADSLOT: |
| 316 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 317 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 318 | case -NFS4ERR_DEADSESSION: |
| 319 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 320 | case -NFS4ERR_SEQ_MISORDERED: |
| 321 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 322 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 323 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 324 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 325 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 327 | if (exception->timeout > HZ) { |
| 328 | /* We have retried a decent amount, time to |
| 329 | * fail |
| 330 | */ |
| 331 | ret = -EBUSY; |
| 332 | break; |
| 333 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 334 | case -NFS4ERR_GRACE: |
| 335 | case -NFS4ERR_DELAY: |
| 336 | ret = nfs4_delay(server->client, &exception->timeout); |
| 337 | if (ret != 0) |
| 338 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 339 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 340 | case -NFS4ERR_OLD_STATEID: |
| 341 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 342 | break; |
| 343 | case -NFS4ERR_BADOWNER: |
| 344 | /* The following works around a Linux server bug! */ |
| 345 | case -NFS4ERR_BADNAME: |
| 346 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 347 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 348 | exception->retry = 1; |
| 349 | printk(KERN_WARNING "NFS: v4 server %s " |
| 350 | "does not accept raw " |
| 351 | "uid/gids. " |
| 352 | "Reenabling the idmapper.\n", |
| 353 | server->nfs_client->cl_hostname); |
| 354 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | } |
| 356 | /* We failed to handle the error */ |
| 357 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 358 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 359 | ret = nfs4_wait_clnt_recover(clp); |
| 360 | if (ret == 0) |
| 361 | exception->retry = 1; |
| 362 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 366 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | spin_lock(&clp->cl_lock); |
| 369 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 370 | clp->cl_last_renewal = timestamp; |
| 371 | spin_unlock(&clp->cl_lock); |
| 372 | } |
| 373 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 374 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 375 | { |
| 376 | do_renew_lease(server->nfs_client, timestamp); |
| 377 | } |
| 378 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 379 | #if defined(CONFIG_NFS_V4_1) |
| 380 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 381 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 382 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 383 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 384 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 385 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 386 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 387 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 388 | /* just wake up the next guy waiting since |
| 389 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 390 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 391 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 392 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 393 | tbl = res->sr_slot->table; |
| 394 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 395 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 396 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 397 | /* Be nice to the server: try to ensure that the last transmitted |
| 398 | * value for highest_user_slotid <= target_highest_slotid |
| 399 | */ |
| 400 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 401 | send_new_highest_used_slotid = true; |
| 402 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 403 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 404 | send_new_highest_used_slotid = false; |
| 405 | goto out_unlock; |
| 406 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 407 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 408 | |
| 409 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 410 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 411 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 412 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 413 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 414 | if (send_new_highest_used_slotid) |
| 415 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 418 | 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] | 419 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 420 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 421 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 422 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 423 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 424 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 425 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 426 | /* don't increment the sequence number if the task wasn't sent */ |
| 427 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 428 | goto out; |
| 429 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 430 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 431 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 432 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 433 | if (slot->interrupted) { |
| 434 | slot->interrupted = 0; |
| 435 | interrupted = true; |
| 436 | } |
| 437 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 438 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | switch (res->sr_status) { |
| 440 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 441 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 442 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 443 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 444 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 445 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 446 | if (res->sr_status_flags != 0) |
| 447 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 448 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 449 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 450 | case 1: |
| 451 | /* |
| 452 | * sr_status remains 1 if an RPC level error occurred. |
| 453 | * The server may or may not have processed the sequence |
| 454 | * operation.. |
| 455 | * Mark the slot as having hosted an interrupted RPC call. |
| 456 | */ |
| 457 | slot->interrupted = 1; |
| 458 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | case -NFS4ERR_DELAY: |
| 460 | /* The server detected a resend of the RPC call and |
| 461 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 462 | * of RFC5661. |
| 463 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 464 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 465 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 466 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 467 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 469 | case -NFS4ERR_BADSLOT: |
| 470 | /* |
| 471 | * The slot id we used was probably retired. Try again |
| 472 | * using a different slot id. |
| 473 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 474 | goto retry_nowait; |
| 475 | case -NFS4ERR_SEQ_MISORDERED: |
| 476 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 477 | * Was the last operation on this sequence interrupted? |
| 478 | * If so, retry after bumping the sequence number. |
| 479 | */ |
| 480 | if (interrupted) { |
| 481 | ++slot->seq_nr; |
| 482 | goto retry_nowait; |
| 483 | } |
| 484 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 485 | * Could this slot have been previously retired? |
| 486 | * If so, then the server may be expecting seq_nr = 1! |
| 487 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 488 | if (slot->seq_nr != 1) { |
| 489 | slot->seq_nr = 1; |
| 490 | goto retry_nowait; |
| 491 | } |
| 492 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 493 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 494 | ++slot->seq_nr; |
| 495 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | default: |
| 497 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 498 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 499 | } |
| 500 | out: |
| 501 | /* The session may be reset by one of the error handlers. */ |
| 502 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 503 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 504 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 505 | retry_nowait: |
| 506 | if (rpc_restart_call_prepare(task)) { |
| 507 | task->tk_status = 0; |
| 508 | ret = 0; |
| 509 | } |
| 510 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 511 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 512 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | goto out; |
| 514 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 515 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 518 | static int nfs4_sequence_done(struct rpc_task *task, |
| 519 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 520 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 521 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 522 | return 1; |
| 523 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 526 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 527 | struct nfs4_sequence_res *res, int cache_reply) |
| 528 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 529 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 530 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 531 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 532 | if (cache_reply) |
| 533 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 534 | res->sr_slot = NULL; |
| 535 | } |
| 536 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 537 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 538 | { |
| 539 | args->sa_privileged = 1; |
| 540 | } |
| 541 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 542 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 543 | struct nfs4_sequence_args *args, |
| 544 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 545 | struct rpc_task *task) |
| 546 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 547 | struct nfs4_slot *slot; |
| 548 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 549 | |
| 550 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 551 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 552 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 553 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 554 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 555 | tbl = &session->fc_slot_table; |
| 556 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 557 | task->tk_timeout = 0; |
| 558 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 559 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 560 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 561 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 562 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 563 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 564 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 567 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 568 | if (IS_ERR(slot)) { |
| 569 | /* If out of memory, try again in 1/4 second */ |
| 570 | if (slot == ERR_PTR(-ENOMEM)) |
| 571 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 572 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 573 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 574 | } |
| 575 | spin_unlock(&tbl->slot_tbl_lock); |
| 576 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 577 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 578 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 579 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 580 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 581 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 582 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 583 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 584 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 585 | /* |
| 586 | * sr_status is only set in decode_sequence, and so will remain |
| 587 | * set to 1 if an rpc level failure occurs. |
| 588 | */ |
| 589 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 590 | out_success: |
| 591 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 592 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 593 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 594 | /* Privileged tasks are queued with top priority */ |
| 595 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 596 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 597 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 598 | else |
| 599 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 600 | spin_unlock(&tbl->slot_tbl_lock); |
| 601 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 602 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 603 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 605 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 606 | struct nfs4_sequence_args *args, |
| 607 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 608 | struct rpc_task *task) |
| 609 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 610 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 611 | int ret = 0; |
| 612 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 613 | if (session == NULL) { |
| 614 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 616 | } |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 617 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 618 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 619 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 620 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 621 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 622 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | out: |
| 624 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | struct nfs4_sequence_args *seq_args; |
| 631 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | }; |
| 633 | |
| 634 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 635 | { |
| 636 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 637 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 638 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 639 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 640 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 641 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 642 | } |
| 643 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 644 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 645 | { |
| 646 | struct nfs41_call_sync_data *data = calldata; |
| 647 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 648 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 651 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 652 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 653 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | }; |
| 655 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 656 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 657 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 658 | struct rpc_message *msg, |
| 659 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 660 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | { |
| 662 | int ret; |
| 663 | struct rpc_task *task; |
| 664 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 665 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 666 | .seq_args = args, |
| 667 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 668 | }; |
| 669 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 670 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | .rpc_message = msg, |
| 672 | .callback_ops = &nfs41_call_sync_ops, |
| 673 | .callback_data = &data |
| 674 | }; |
| 675 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 676 | task = rpc_run_task(&task_setup); |
| 677 | if (IS_ERR(task)) |
| 678 | ret = PTR_ERR(task); |
| 679 | else { |
| 680 | ret = task->tk_status; |
| 681 | rpc_put_task(task); |
| 682 | } |
| 683 | return ret; |
| 684 | } |
| 685 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 687 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 688 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 689 | struct nfs4_sequence_res *res, int cache_reply) |
| 690 | { |
| 691 | } |
| 692 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 693 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 694 | { |
| 695 | } |
| 696 | |
| 697 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 698 | static int nfs4_sequence_done(struct rpc_task *task, |
| 699 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 700 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 701 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 702 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 703 | #endif /* CONFIG_NFS_V4_1 */ |
| 704 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 705 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 706 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 707 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 708 | struct rpc_message *msg, |
| 709 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 710 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 711 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 712 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 715 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 716 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 717 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 718 | struct rpc_message *msg, |
| 719 | struct nfs4_sequence_args *args, |
| 720 | struct nfs4_sequence_res *res, |
| 721 | int cache_reply) |
| 722 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 723 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 724 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 725 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 726 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 727 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 728 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 730 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 732 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 733 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 734 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 735 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 736 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 737 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 738 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 741 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 742 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 743 | struct nfs_openargs o_arg; |
| 744 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 745 | struct nfs_open_confirmargs c_arg; |
| 746 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 747 | struct nfs4_string owner_name; |
| 748 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 749 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 750 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 751 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 752 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 753 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 754 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 755 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 756 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 757 | int rpc_status; |
| 758 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | }; |
| 760 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 761 | |
| 762 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 763 | { |
| 764 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 765 | p->o_res.seqid = p->o_arg.seqid; |
| 766 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 767 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 768 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 769 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 770 | 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] | 771 | } |
| 772 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 773 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 774 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 775 | const struct iattr *attrs, |
| 776 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 777 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 778 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 779 | struct inode *dir = parent->d_inode; |
| 780 | struct nfs_server *server = NFS_SERVER(dir); |
| 781 | struct nfs4_opendata *p; |
| 782 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 783 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 784 | if (p == NULL) |
| 785 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 786 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 787 | if (p->o_arg.seqid == NULL) |
| 788 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 789 | nfs_sb_active(dentry->d_sb); |
| 790 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | p->dir = parent; |
| 792 | p->owner = sp; |
| 793 | atomic_inc(&sp->so_count); |
| 794 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 795 | p->o_arg.open_flags = flags; |
| 796 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 797 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 798 | * will return permission denied for all bits until close */ |
| 799 | if (!(flags & O_EXCL)) { |
| 800 | /* ask server to check for all possible rights as results |
| 801 | * are cached */ |
| 802 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 803 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 804 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 805 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 806 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 807 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 808 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 809 | p->o_arg.server = server; |
| 810 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 811 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 812 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 813 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 814 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 815 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 816 | p->o_arg.u.attrs = &p->attrs; |
| 817 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 818 | |
| 819 | verf[0] = jiffies; |
| 820 | verf[1] = current->pid; |
| 821 | memcpy(p->o_arg.u.verifier.data, verf, |
| 822 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 824 | p->c_arg.fh = &p->o_res.fh; |
| 825 | p->c_arg.stateid = &p->o_res.stateid; |
| 826 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 827 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 828 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | return p; |
| 830 | err_free: |
| 831 | kfree(p); |
| 832 | err: |
| 833 | dput(parent); |
| 834 | return NULL; |
| 835 | } |
| 836 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 837 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 838 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 839 | struct nfs4_opendata *p = container_of(kref, |
| 840 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 841 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 842 | |
| 843 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 844 | if (p->state != NULL) |
| 845 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 846 | nfs4_put_state_owner(p->owner); |
| 847 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 848 | dput(p->dentry); |
| 849 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 850 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 851 | kfree(p); |
| 852 | } |
| 853 | |
| 854 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 855 | { |
| 856 | if (p != NULL) |
| 857 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 858 | } |
| 859 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 860 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 861 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 862 | int ret; |
| 863 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 864 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 865 | return ret; |
| 866 | } |
| 867 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 868 | 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] | 869 | { |
| 870 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 871 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 872 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 873 | goto out; |
| 874 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 875 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 876 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 877 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 878 | break; |
| 879 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 880 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 881 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 882 | break; |
| 883 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 884 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 885 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 886 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 887 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 888 | return ret; |
| 889 | } |
| 890 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 891 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 892 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 893 | if (delegation == NULL) |
| 894 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 895 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 896 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 897 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 898 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 899 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 900 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 901 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 902 | return 1; |
| 903 | } |
| 904 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 906 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 907 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 908 | case FMODE_WRITE: |
| 909 | state->n_wronly++; |
| 910 | break; |
| 911 | case FMODE_READ: |
| 912 | state->n_rdonly++; |
| 913 | break; |
| 914 | case FMODE_READ|FMODE_WRITE: |
| 915 | state->n_rdwr++; |
| 916 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | 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] | 921 | { |
| 922 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 923 | nfs4_stateid_copy(&state->stateid, stateid); |
| 924 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 925 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 926 | case FMODE_READ: |
| 927 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 928 | break; |
| 929 | case FMODE_WRITE: |
| 930 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 931 | break; |
| 932 | case FMODE_READ|FMODE_WRITE: |
| 933 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 934 | } |
| 935 | } |
| 936 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | 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] | 938 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 939 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 941 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 942 | } |
| 943 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 944 | 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] | 945 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 946 | /* |
| 947 | * Protect the call to nfs4_state_set_mode_locked and |
| 948 | * serialise the stateid update |
| 949 | */ |
| 950 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 951 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 952 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 953 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 954 | } |
| 955 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 957 | write_sequnlock(&state->seqlock); |
| 958 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 960 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | 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] | 964 | { |
| 965 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 966 | struct nfs_delegation *deleg_cur; |
| 967 | int ret = 0; |
| 968 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 970 | |
| 971 | rcu_read_lock(); |
| 972 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 973 | if (deleg_cur == NULL) |
| 974 | goto no_delegation; |
| 975 | |
| 976 | spin_lock(&deleg_cur->lock); |
| 977 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 978 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 979 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 980 | goto no_delegation_unlock; |
| 981 | |
| 982 | if (delegation == NULL) |
| 983 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 984 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 985 | goto no_delegation_unlock; |
| 986 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 987 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 988 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 989 | ret = 1; |
| 990 | no_delegation_unlock: |
| 991 | spin_unlock(&deleg_cur->lock); |
| 992 | no_delegation: |
| 993 | rcu_read_unlock(); |
| 994 | |
| 995 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 997 | ret = 1; |
| 998 | } |
| 999 | |
| 1000 | return ret; |
| 1001 | } |
| 1002 | |
| 1003 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1004 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1005 | { |
| 1006 | struct nfs_delegation *delegation; |
| 1007 | |
| 1008 | rcu_read_lock(); |
| 1009 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1010 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1011 | rcu_read_unlock(); |
| 1012 | return; |
| 1013 | } |
| 1014 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1015 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1018 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1019 | { |
| 1020 | struct nfs4_state *state = opendata->state; |
| 1021 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1022 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1023 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1024 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | nfs4_stateid stateid; |
| 1026 | int ret = -EAGAIN; |
| 1027 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1028 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1029 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1030 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | if (can_open_cached(state, fmode, open_mode)) { |
| 1032 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1033 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1034 | goto out_return_state; |
| 1035 | } |
| 1036 | spin_unlock(&state->owner->so_lock); |
| 1037 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1038 | rcu_read_lock(); |
| 1039 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1040 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1041 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1042 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1043 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1044 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1045 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1046 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1047 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | if (ret != 0) |
| 1049 | goto out; |
| 1050 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1051 | |
| 1052 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1055 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1056 | out: |
| 1057 | return ERR_PTR(ret); |
| 1058 | out_return_state: |
| 1059 | atomic_inc(&state->count); |
| 1060 | return state; |
| 1061 | } |
| 1062 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1063 | static void |
| 1064 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1065 | { |
| 1066 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1067 | struct nfs_delegation *delegation; |
| 1068 | int delegation_flags = 0; |
| 1069 | |
| 1070 | rcu_read_lock(); |
| 1071 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1072 | if (delegation) |
| 1073 | delegation_flags = delegation->flags; |
| 1074 | rcu_read_unlock(); |
| 1075 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1076 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1077 | "returning a delegation for " |
| 1078 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1079 | clp->cl_hostname); |
| 1080 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1081 | nfs_inode_set_delegation(state->inode, |
| 1082 | data->owner->so_cred, |
| 1083 | &data->o_res); |
| 1084 | else |
| 1085 | nfs_inode_reclaim_delegation(state->inode, |
| 1086 | data->owner->so_cred, |
| 1087 | &data->o_res); |
| 1088 | } |
| 1089 | |
| 1090 | /* |
| 1091 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1092 | * and update the nfs4_state. |
| 1093 | */ |
| 1094 | static struct nfs4_state * |
| 1095 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1096 | { |
| 1097 | struct inode *inode = data->state->inode; |
| 1098 | struct nfs4_state *state = data->state; |
| 1099 | int ret; |
| 1100 | |
| 1101 | if (!data->rpc_done) { |
| 1102 | ret = data->rpc_status; |
| 1103 | goto err; |
| 1104 | } |
| 1105 | |
| 1106 | ret = -ESTALE; |
| 1107 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1108 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1109 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1110 | goto err; |
| 1111 | |
| 1112 | ret = -ENOMEM; |
| 1113 | state = nfs4_get_open_state(inode, data->owner); |
| 1114 | if (state == NULL) |
| 1115 | goto err; |
| 1116 | |
| 1117 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1118 | if (ret) |
| 1119 | goto err; |
| 1120 | |
| 1121 | if (data->o_res.delegation_type != 0) |
| 1122 | nfs4_opendata_check_deleg(data, state); |
| 1123 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1124 | data->o_arg.fmode); |
| 1125 | |
| 1126 | return state; |
| 1127 | err: |
| 1128 | return ERR_PTR(ret); |
| 1129 | |
| 1130 | } |
| 1131 | |
| 1132 | static struct nfs4_state * |
| 1133 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1134 | { |
| 1135 | struct inode *inode; |
| 1136 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1137 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1138 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1139 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1140 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1141 | goto out; |
| 1142 | } |
| 1143 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1144 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1145 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1146 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1147 | 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] | 1148 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1149 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1150 | goto err; |
| 1151 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1152 | state = nfs4_get_open_state(inode, data->owner); |
| 1153 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1154 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1155 | if (data->o_res.delegation_type != 0) |
| 1156 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1157 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1158 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1159 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1160 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1161 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1162 | err_put_inode: |
| 1163 | iput(inode); |
| 1164 | err: |
| 1165 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1166 | } |
| 1167 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1168 | static struct nfs4_state * |
| 1169 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1170 | { |
| 1171 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1172 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1173 | return _nfs4_opendata_to_nfs4_state(data); |
| 1174 | } |
| 1175 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1176 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1177 | { |
| 1178 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1179 | struct nfs_open_context *ctx; |
| 1180 | |
| 1181 | spin_lock(&state->inode->i_lock); |
| 1182 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1183 | if (ctx->state != state) |
| 1184 | continue; |
| 1185 | get_nfs_open_context(ctx); |
| 1186 | spin_unlock(&state->inode->i_lock); |
| 1187 | return ctx; |
| 1188 | } |
| 1189 | spin_unlock(&state->inode->i_lock); |
| 1190 | return ERR_PTR(-ENOENT); |
| 1191 | } |
| 1192 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1193 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1194 | { |
| 1195 | struct nfs4_opendata *opendata; |
| 1196 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1197 | 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] | 1198 | if (opendata == NULL) |
| 1199 | return ERR_PTR(-ENOMEM); |
| 1200 | opendata->state = state; |
| 1201 | atomic_inc(&state->count); |
| 1202 | return opendata; |
| 1203 | } |
| 1204 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1205 | 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] | 1206 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1207 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1208 | int ret; |
| 1209 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1210 | opendata->o_arg.open_flags = 0; |
| 1211 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1212 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1213 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1214 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1215 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1216 | if (ret != 0) |
| 1217 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1218 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1219 | if (IS_ERR(newstate)) |
| 1220 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1221 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1222 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1227 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1228 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | int ret; |
| 1230 | |
| 1231 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1232 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1233 | smp_rmb(); |
| 1234 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1235 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1236 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1237 | if (ret != 0) |
| 1238 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1239 | if (newstate != state) |
| 1240 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1241 | } |
| 1242 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1243 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1244 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1245 | if (ret != 0) |
| 1246 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1247 | if (newstate != state) |
| 1248 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1249 | } |
| 1250 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1251 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1252 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1253 | if (ret != 0) |
| 1254 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1255 | if (newstate != state) |
| 1256 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1257 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1258 | /* |
| 1259 | * We may have performed cached opens for all three recoveries. |
| 1260 | * Check if we need to update the current stateid. |
| 1261 | */ |
| 1262 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1263 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1264 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1265 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1266 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1267 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1268 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1269 | return 0; |
| 1270 | } |
| 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | /* |
| 1273 | * OPEN_RECLAIM: |
| 1274 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1276 | 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] | 1277 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1278 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1279 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1280 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | int status; |
| 1282 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1283 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1284 | if (IS_ERR(opendata)) |
| 1285 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1286 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1287 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1288 | rcu_read_lock(); |
| 1289 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1290 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1291 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1292 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1293 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1294 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1295 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | return status; |
| 1297 | } |
| 1298 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1299 | 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] | 1300 | { |
| 1301 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1302 | struct nfs4_exception exception = { }; |
| 1303 | int err; |
| 1304 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1305 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1306 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1307 | break; |
| 1308 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | } while (exception.retry); |
| 1310 | return err; |
| 1311 | } |
| 1312 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1313 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1314 | { |
| 1315 | struct nfs_open_context *ctx; |
| 1316 | int ret; |
| 1317 | |
| 1318 | ctx = nfs4_state_find_open_context(state); |
| 1319 | if (IS_ERR(ctx)) |
| 1320 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1321 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1322 | put_nfs_open_context(ctx); |
| 1323 | return ret; |
| 1324 | } |
| 1325 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1326 | 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] | 1327 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1328 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1329 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1331 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1332 | if (IS_ERR(opendata)) |
| 1333 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1334 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1335 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1336 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1337 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1338 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1341 | 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] | 1342 | { |
| 1343 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1344 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | int err; |
| 1346 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1347 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | switch (err) { |
| 1349 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1350 | case -ENOENT: |
| 1351 | case -ESTALE: |
| 1352 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1353 | case -NFS4ERR_BADSESSION: |
| 1354 | case -NFS4ERR_BADSLOT: |
| 1355 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1356 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1357 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1358 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1359 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1360 | err = -EAGAIN; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1361 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | case -NFS4ERR_STALE_CLIENTID: |
| 1363 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1364 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | case -NFS4ERR_EXPIRED: |
| 1366 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1367 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1368 | err = -EAGAIN; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1369 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1370 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1371 | case -NFS4ERR_ADMIN_REVOKED: |
| 1372 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1373 | nfs_inode_find_state_and_recover(state->inode, |
| 1374 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1375 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1376 | case -ENOMEM: |
| 1377 | err = 0; |
| 1378 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1380 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | err = nfs4_handle_exception(server, err, &exception); |
| 1382 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1383 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | return err; |
| 1385 | } |
| 1386 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1387 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1388 | { |
| 1389 | struct nfs4_opendata *data = calldata; |
| 1390 | |
| 1391 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1392 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1393 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1394 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1395 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1396 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1397 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | static void nfs4_open_confirm_release(void *calldata) |
| 1401 | { |
| 1402 | struct nfs4_opendata *data = calldata; |
| 1403 | struct nfs4_state *state = NULL; |
| 1404 | |
| 1405 | /* If this request hasn't been cancelled, do nothing */ |
| 1406 | if (data->cancelled == 0) |
| 1407 | goto out_free; |
| 1408 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1409 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1410 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1411 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1412 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1413 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1414 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1415 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1419 | .rpc_call_done = nfs4_open_confirm_done, |
| 1420 | .rpc_release = nfs4_open_confirm_release, |
| 1421 | }; |
| 1422 | |
| 1423 | /* |
| 1424 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1425 | */ |
| 1426 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1427 | { |
| 1428 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1429 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1430 | struct rpc_message msg = { |
| 1431 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1432 | .rpc_argp = &data->c_arg, |
| 1433 | .rpc_resp = &data->c_res, |
| 1434 | .rpc_cred = data->owner->so_cred, |
| 1435 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1436 | struct rpc_task_setup task_setup_data = { |
| 1437 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1438 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1439 | .callback_ops = &nfs4_open_confirm_ops, |
| 1440 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1441 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1442 | .flags = RPC_TASK_ASYNC, |
| 1443 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | int status; |
| 1445 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1446 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1447 | data->rpc_done = 0; |
| 1448 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1449 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1450 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1451 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1452 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1453 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1454 | if (status != 0) { |
| 1455 | data->cancelled = 1; |
| 1456 | smp_wmb(); |
| 1457 | } else |
| 1458 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1459 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | return status; |
| 1461 | } |
| 1462 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1463 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | struct nfs4_opendata *data = calldata; |
| 1466 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1467 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1468 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1469 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1470 | /* |
| 1471 | * Check if we still need to send an OPEN call, or if we can use |
| 1472 | * a delegation instead. |
| 1473 | */ |
| 1474 | if (data->state != NULL) { |
| 1475 | struct nfs_delegation *delegation; |
| 1476 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1477 | 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] | 1478 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1479 | rcu_read_lock(); |
| 1480 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1481 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1482 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1483 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1484 | rcu_read_unlock(); |
| 1485 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1486 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1487 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1488 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1489 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1490 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1491 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1492 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1493 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1494 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1495 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1496 | &data->o_res.seq_res, |
| 1497 | task) != 0) |
| 1498 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1499 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1500 | unlock_no_action: |
| 1501 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1502 | out_no_action: |
| 1503 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1504 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1505 | } |
| 1506 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1507 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1508 | { |
| 1509 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1511 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1512 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1513 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1514 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1515 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1516 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1517 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1518 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1519 | case S_IFREG: |
| 1520 | break; |
| 1521 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1522 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1523 | break; |
| 1524 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1525 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1526 | break; |
| 1527 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1528 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1529 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1530 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1531 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1532 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1533 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1534 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1535 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1536 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1537 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1538 | static void nfs4_open_release(void *calldata) |
| 1539 | { |
| 1540 | struct nfs4_opendata *data = calldata; |
| 1541 | struct nfs4_state *state = NULL; |
| 1542 | |
| 1543 | /* If this request hasn't been cancelled, do nothing */ |
| 1544 | if (data->cancelled == 0) |
| 1545 | goto out_free; |
| 1546 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1547 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1548 | goto out_free; |
| 1549 | /* In case we need an open_confirm, no cleanup! */ |
| 1550 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1551 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1552 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1553 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1554 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1555 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1556 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1560 | .rpc_call_prepare = nfs4_open_prepare, |
| 1561 | .rpc_call_done = nfs4_open_done, |
| 1562 | .rpc_release = nfs4_open_release, |
| 1563 | }; |
| 1564 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1565 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1566 | { |
| 1567 | struct inode *dir = data->dir->d_inode; |
| 1568 | struct nfs_server *server = NFS_SERVER(dir); |
| 1569 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1570 | struct nfs_openres *o_res = &data->o_res; |
| 1571 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1572 | struct rpc_message msg = { |
| 1573 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1574 | .rpc_argp = o_arg, |
| 1575 | .rpc_resp = o_res, |
| 1576 | .rpc_cred = data->owner->so_cred, |
| 1577 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1578 | struct rpc_task_setup task_setup_data = { |
| 1579 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1580 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1581 | .callback_ops = &nfs4_open_ops, |
| 1582 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1583 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1584 | .flags = RPC_TASK_ASYNC, |
| 1585 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1586 | int status; |
| 1587 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1588 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1589 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1590 | data->rpc_done = 0; |
| 1591 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1592 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1593 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1594 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1595 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1596 | if (IS_ERR(task)) |
| 1597 | return PTR_ERR(task); |
| 1598 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1599 | if (status != 0) { |
| 1600 | data->cancelled = 1; |
| 1601 | smp_wmb(); |
| 1602 | } else |
| 1603 | status = data->rpc_status; |
| 1604 | rpc_put_task(task); |
| 1605 | |
| 1606 | return status; |
| 1607 | } |
| 1608 | |
| 1609 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1610 | { |
| 1611 | struct inode *dir = data->dir->d_inode; |
| 1612 | struct nfs_openres *o_res = &data->o_res; |
| 1613 | int status; |
| 1614 | |
| 1615 | status = nfs4_run_open_task(data, 1); |
| 1616 | if (status != 0 || !data->rpc_done) |
| 1617 | return status; |
| 1618 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1619 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1620 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1621 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1622 | status = _nfs4_proc_open_confirm(data); |
| 1623 | if (status != 0) |
| 1624 | return status; |
| 1625 | } |
| 1626 | |
| 1627 | return status; |
| 1628 | } |
| 1629 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1630 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1631 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1632 | struct nfs4_state *state, fmode_t fmode, |
| 1633 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1634 | { |
| 1635 | struct nfs_access_entry cache; |
| 1636 | u32 mask; |
| 1637 | |
| 1638 | /* access call failed or for some reason the server doesn't |
| 1639 | * support any access modes -- defer access call until later */ |
| 1640 | if (opendata->o_res.access_supported == 0) |
| 1641 | return 0; |
| 1642 | |
| 1643 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1644 | /* don't check MAY_WRITE - a newly created file may not have |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1645 | * write mode bits, but POSIX allows the creating process to write. |
| 1646 | * use openflags to check for exec, because fmode won't |
| 1647 | * always have FMODE_EXEC set when file open for exec. */ |
| 1648 | if (openflags & __FMODE_EXEC) { |
| 1649 | /* ONLY check for exec rights */ |
| 1650 | mask = MAY_EXEC; |
| 1651 | } else if (fmode & FMODE_READ) |
| 1652 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1653 | |
| 1654 | cache.cred = cred; |
| 1655 | cache.jiffies = jiffies; |
| 1656 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1657 | nfs_access_add_cache(state->inode, &cache); |
| 1658 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1659 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1660 | return 0; |
| 1661 | |
| 1662 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1663 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1664 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1665 | } |
| 1666 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1667 | /* |
| 1668 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1669 | */ |
| 1670 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1671 | { |
| 1672 | struct inode *dir = data->dir->d_inode; |
| 1673 | struct nfs_server *server = NFS_SERVER(dir); |
| 1674 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1675 | struct nfs_openres *o_res = &data->o_res; |
| 1676 | int status; |
| 1677 | |
| 1678 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1679 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1680 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1681 | if (status != 0) { |
| 1682 | if (status == -NFS4ERR_BADNAME && |
| 1683 | !(o_arg->open_flags & O_CREAT)) |
| 1684 | return -ENOENT; |
| 1685 | return status; |
| 1686 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1687 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1688 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1689 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1690 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1691 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1692 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1693 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1695 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1697 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | } |
| 1699 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1700 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1701 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1704 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1705 | { |
| 1706 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1707 | } |
| 1708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | /* |
| 1710 | * OPEN_EXPIRED: |
| 1711 | * reclaim state on the server after a network partition. |
| 1712 | * Assumes caller holds the appropriate lock |
| 1713 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1714 | 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] | 1715 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1716 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1717 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1719 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1720 | if (IS_ERR(opendata)) |
| 1721 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1722 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1723 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1724 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1725 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1726 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1729 | 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] | 1730 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1731 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1732 | struct nfs4_exception exception = { }; |
| 1733 | int err; |
| 1734 | |
| 1735 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1736 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1737 | switch (err) { |
| 1738 | default: |
| 1739 | goto out; |
| 1740 | case -NFS4ERR_GRACE: |
| 1741 | case -NFS4ERR_DELAY: |
| 1742 | nfs4_handle_exception(server, err, &exception); |
| 1743 | err = 0; |
| 1744 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1745 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1746 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1747 | return err; |
| 1748 | } |
| 1749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1751 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1753 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1755 | ctx = nfs4_state_find_open_context(state); |
| 1756 | if (IS_ERR(ctx)) |
| 1757 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1758 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1759 | put_nfs_open_context(ctx); |
| 1760 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1763 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1764 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1765 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1766 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1767 | nfs4_stateid *stateid = &state->stateid; |
| 1768 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1769 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1770 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1771 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1772 | return; |
| 1773 | |
| 1774 | status = nfs41_test_stateid(server, stateid); |
| 1775 | if (status != NFS_OK) { |
| 1776 | /* Free the stateid unless the server explicitly |
| 1777 | * informs us the stateid is unrecognized. */ |
| 1778 | if (status != -NFS4ERR_BAD_STATEID) |
| 1779 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1780 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1781 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1782 | write_seqlock(&state->seqlock); |
| 1783 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1784 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1785 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | /** |
| 1790 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1791 | * |
| 1792 | * @state: NFSv4 state for an inode |
| 1793 | * |
| 1794 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1795 | * Otherwise a negative NFS4ERR value is returned. |
| 1796 | */ |
| 1797 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1798 | { |
| 1799 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1800 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1801 | int status; |
| 1802 | |
| 1803 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1804 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1805 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1806 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1807 | return -NFS4ERR_BAD_STATEID; |
| 1808 | |
| 1809 | status = nfs41_test_stateid(server, stateid); |
| 1810 | if (status != NFS_OK) { |
| 1811 | /* Free the stateid unless the server explicitly |
| 1812 | * informs us the stateid is unrecognized. */ |
| 1813 | if (status != -NFS4ERR_BAD_STATEID) |
| 1814 | nfs41_free_stateid(server, stateid); |
| 1815 | |
| 1816 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1817 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1818 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1819 | } |
| 1820 | return status; |
| 1821 | } |
| 1822 | |
| 1823 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1824 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1825 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1826 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1827 | nfs41_clear_delegation_stateid(state); |
| 1828 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1829 | if (status != NFS_OK) |
| 1830 | status = nfs4_open_expired(sp, state); |
| 1831 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1832 | } |
| 1833 | #endif |
| 1834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1836 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1837 | * fields corresponding to attributes that were used to store the verifier. |
| 1838 | * Make sure we clobber those fields in the later setattr call |
| 1839 | */ |
| 1840 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1841 | { |
| 1842 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1843 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1844 | sattr->ia_valid |= ATTR_ATIME; |
| 1845 | |
| 1846 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1847 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1848 | sattr->ia_valid |= ATTR_MTIME; |
| 1849 | } |
| 1850 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame^] | 1851 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1852 | fmode_t fmode, |
| 1853 | int flags, |
| 1854 | struct nfs4_state **res) |
| 1855 | { |
| 1856 | struct nfs4_state_owner *sp = opendata->owner; |
| 1857 | struct nfs_server *server = sp->so_server; |
| 1858 | struct nfs4_state *state; |
| 1859 | unsigned int seq; |
| 1860 | int ret; |
| 1861 | |
| 1862 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1863 | |
| 1864 | ret = _nfs4_proc_open(opendata); |
| 1865 | if (ret != 0) |
| 1866 | goto out; |
| 1867 | |
| 1868 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1869 | ret = PTR_ERR(state); |
| 1870 | if (IS_ERR(state)) |
| 1871 | goto out; |
| 1872 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1873 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1874 | |
| 1875 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 1876 | if (ret != 0) |
| 1877 | goto out; |
| 1878 | |
| 1879 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 1880 | nfs4_schedule_stateid_recovery(server, state); |
| 1881 | nfs4_wait_clnt_recover(server->nfs_client); |
| 1882 | } |
| 1883 | *res = state; |
| 1884 | out: |
| 1885 | return ret; |
| 1886 | } |
| 1887 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1888 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1889 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1891 | static int _nfs4_do_open(struct inode *dir, |
| 1892 | struct dentry *dentry, |
| 1893 | fmode_t fmode, |
| 1894 | int flags, |
| 1895 | struct iattr *sattr, |
| 1896 | struct rpc_cred *cred, |
| 1897 | struct nfs4_state **res, |
| 1898 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | { |
| 1900 | struct nfs4_state_owner *sp; |
| 1901 | struct nfs4_state *state = NULL; |
| 1902 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1903 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1904 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | |
| 1906 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1908 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1909 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1911 | goto out_err; |
| 1912 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1913 | status = nfs4_recover_expired_lease(server); |
| 1914 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1915 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1916 | if (dentry->d_inode != NULL) |
| 1917 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1918 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1919 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1920 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1921 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1923 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1924 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1925 | if (!opendata->f_attr.mdsthreshold) |
| 1926 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1927 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1928 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1929 | if (dentry->d_inode != NULL) |
| 1930 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1931 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame^] | 1932 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1933 | if (status != 0) |
| 1934 | goto err_opendata_put; |
| 1935 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1936 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1937 | nfs4_exclusive_attrset(opendata, sattr); |
| 1938 | |
| 1939 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1940 | status = nfs4_do_setattr(state->inode, cred, |
| 1941 | opendata->o_res.f_attr, sattr, |
| 1942 | state); |
| 1943 | if (status == 0) |
| 1944 | nfs_setattr_update_inode(state->inode, sattr); |
| 1945 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1946 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1947 | |
| 1948 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1949 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1950 | else |
| 1951 | kfree(opendata->f_attr.mdsthreshold); |
| 1952 | opendata->f_attr.mdsthreshold = NULL; |
| 1953 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1954 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | *res = state; |
| 1957 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1958 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1959 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1960 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1961 | err_put_state_owner: |
| 1962 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | *res = NULL; |
| 1965 | return status; |
| 1966 | } |
| 1967 | |
| 1968 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1969 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1970 | struct dentry *dentry, |
| 1971 | fmode_t fmode, |
| 1972 | int flags, |
| 1973 | struct iattr *sattr, |
| 1974 | struct rpc_cred *cred, |
| 1975 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | { |
| 1977 | struct nfs4_exception exception = { }; |
| 1978 | struct nfs4_state *res; |
| 1979 | int status; |
| 1980 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1981 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1983 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1984 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | if (status == 0) |
| 1986 | break; |
| 1987 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1988 | * book-keeping w.r.t. state-changing operations |
| 1989 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1990 | * It is actually a sign of a bug on the client or on the server. |
| 1991 | * |
| 1992 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1993 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | * have unhashed the old state_owner for us, and that we can |
| 1995 | * therefore safely retry using a new one. We should still warn |
| 1996 | * the user though... |
| 1997 | */ |
| 1998 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1999 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2000 | " returned a bad sequence-id error!\n", |
| 2001 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | exception.retry = 1; |
| 2003 | continue; |
| 2004 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2005 | /* |
| 2006 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2007 | * state before it received the OPEN_CONFIRM. |
| 2008 | * Recover by retrying the request as per the discussion |
| 2009 | * on Page 181 of RFC3530. |
| 2010 | */ |
| 2011 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2012 | exception.retry = 1; |
| 2013 | continue; |
| 2014 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2015 | if (status == -EAGAIN) { |
| 2016 | /* We must have found a delegation */ |
| 2017 | exception.retry = 1; |
| 2018 | continue; |
| 2019 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2021 | status, &exception)); |
| 2022 | } while (exception.retry); |
| 2023 | return res; |
| 2024 | } |
| 2025 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2026 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2027 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2028 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2030 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2032 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | .iap = sattr, |
| 2034 | .server = server, |
| 2035 | .bitmask = server->attr_bitmask, |
| 2036 | }; |
| 2037 | struct nfs_setattrres res = { |
| 2038 | .fattr = fattr, |
| 2039 | .server = server, |
| 2040 | }; |
| 2041 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2043 | .rpc_argp = &arg, |
| 2044 | .rpc_resp = &res, |
| 2045 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2047 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2048 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2050 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2052 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2053 | struct nfs_lockowner lockowner = { |
| 2054 | .l_owner = current->files, |
| 2055 | .l_pid = current->tgid, |
| 2056 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2057 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2058 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2059 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2060 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2061 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2062 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2063 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2065 | 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] | 2066 | if (status == 0 && state != NULL) |
| 2067 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2068 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2071 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2072 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2073 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2075 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2076 | struct nfs4_exception exception = { |
| 2077 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2078 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2079 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | int err; |
| 2081 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2082 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2083 | switch (err) { |
| 2084 | case -NFS4ERR_OPENMODE: |
| 2085 | if (state && !(state->state & FMODE_WRITE)) { |
| 2086 | err = -EBADF; |
| 2087 | if (sattr->ia_valid & ATTR_OPEN) |
| 2088 | err = -EACCES; |
| 2089 | goto out; |
| 2090 | } |
| 2091 | } |
| 2092 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2094 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | return err; |
| 2096 | } |
| 2097 | |
| 2098 | struct nfs4_closedata { |
| 2099 | struct inode *inode; |
| 2100 | struct nfs4_state *state; |
| 2101 | struct nfs_closeargs arg; |
| 2102 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2103 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2104 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2105 | bool roc; |
| 2106 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | }; |
| 2108 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2109 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2110 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2111 | struct nfs4_closedata *calldata = data; |
| 2112 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2113 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2114 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2115 | if (calldata->roc) |
| 2116 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2117 | nfs4_put_open_state(calldata->state); |
| 2118 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2119 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2120 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2121 | kfree(calldata); |
| 2122 | } |
| 2123 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2124 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2125 | fmode_t fmode) |
| 2126 | { |
| 2127 | spin_lock(&state->owner->so_lock); |
| 2128 | if (!(fmode & FMODE_READ)) |
| 2129 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2130 | if (!(fmode & FMODE_WRITE)) |
| 2131 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2132 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2133 | spin_unlock(&state->owner->so_lock); |
| 2134 | } |
| 2135 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2136 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2138 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2141 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2142 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2143 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2144 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | /* hmm. we are done with the inode, and in the process of freeing |
| 2146 | * the state_owner. we keep this around to process errors |
| 2147 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | switch (task->tk_status) { |
| 2149 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2150 | if (calldata->roc) |
| 2151 | pnfs_roc_set_barrier(state->inode, |
| 2152 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2153 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2154 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2155 | nfs4_close_clear_stateid_flags(state, |
| 2156 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | break; |
| 2158 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2159 | case -NFS4ERR_OLD_STATEID: |
| 2160 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2162 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2163 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2165 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2166 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2168 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2169 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2170 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2173 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2175 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2176 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2177 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2178 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2179 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2180 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2181 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2182 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2183 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2184 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2185 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2186 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2187 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2188 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2189 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2190 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2191 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2192 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2193 | } |
| 2194 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2195 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2196 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2197 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2198 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2199 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2200 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2201 | |
| 2202 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2203 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2204 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2205 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2206 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2207 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2208 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2209 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2210 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2211 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2212 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2213 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2214 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2215 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2216 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2217 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2218 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2219 | &calldata->arg.seq_args, |
| 2220 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2221 | task) != 0) |
| 2222 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2223 | out: |
| 2224 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2227 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2228 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2229 | .rpc_call_done = nfs4_close_done, |
| 2230 | .rpc_release = nfs4_free_closedata, |
| 2231 | }; |
| 2232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | /* |
| 2234 | * It is possible for data to be read/written from a mem-mapped file |
| 2235 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2236 | * This means that we can't safely call nfsv4 close on a file until |
| 2237 | * the inode is cleared. This in turn means that we are not good |
| 2238 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2239 | * share state even when we are done with one of the three share |
| 2240 | * stateid's in the inode. |
| 2241 | * |
| 2242 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2243 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2244 | 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] | 2245 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2246 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2248 | struct nfs4_state_owner *sp = state->owner; |
| 2249 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2250 | struct rpc_message msg = { |
| 2251 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2252 | .rpc_cred = state->owner->so_cred, |
| 2253 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2254 | struct rpc_task_setup task_setup_data = { |
| 2255 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2256 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2257 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2258 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2259 | .flags = RPC_TASK_ASYNC, |
| 2260 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2261 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2263 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2265 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2266 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2267 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2269 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2270 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2272 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2273 | if (calldata->arg.seqid == NULL) |
| 2274 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2275 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2276 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2277 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2278 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2279 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2280 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2281 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2282 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2283 | msg.rpc_argp = &calldata->arg; |
| 2284 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2285 | task_setup_data.callback_data = calldata; |
| 2286 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2287 | if (IS_ERR(task)) |
| 2288 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2289 | status = 0; |
| 2290 | if (wait) |
| 2291 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2292 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2293 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2294 | out_free_calldata: |
| 2295 | kfree(calldata); |
| 2296 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2297 | nfs4_put_open_state(state); |
| 2298 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2299 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2302 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2303 | 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] | 2304 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | struct nfs4_state *state; |
| 2306 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2307 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2308 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2309 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2310 | if (IS_ERR(state)) |
| 2311 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2312 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2313 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2316 | 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] | 2317 | { |
| 2318 | if (ctx->state == NULL) |
| 2319 | return; |
| 2320 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2321 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2322 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2323 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | |
| 2326 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2327 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2328 | struct nfs4_server_caps_arg args = { |
| 2329 | .fhandle = fhandle, |
| 2330 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | struct nfs4_server_caps_res res = {}; |
| 2332 | struct rpc_message msg = { |
| 2333 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2334 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | .rpc_resp = &res, |
| 2336 | }; |
| 2337 | int status; |
| 2338 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2339 | 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] | 2340 | if (status == 0) { |
| 2341 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2342 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2343 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2344 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2345 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2346 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2348 | server->caps |= NFS_CAP_ACLS; |
| 2349 | if (res.has_links != 0) |
| 2350 | server->caps |= NFS_CAP_HARDLINKS; |
| 2351 | if (res.has_symlinks != 0) |
| 2352 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2353 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2354 | server->caps |= NFS_CAP_FILEID; |
| 2355 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2356 | server->caps |= NFS_CAP_MODE; |
| 2357 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2358 | server->caps |= NFS_CAP_NLINK; |
| 2359 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2360 | server->caps |= NFS_CAP_OWNER; |
| 2361 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2362 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2363 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2364 | server->caps |= NFS_CAP_ATIME; |
| 2365 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2366 | server->caps |= NFS_CAP_CTIME; |
| 2367 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2368 | server->caps |= NFS_CAP_MTIME; |
| 2369 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2370 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2371 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2372 | 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] | 2373 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2374 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | return status; |
| 2378 | } |
| 2379 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2380 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | { |
| 2382 | struct nfs4_exception exception = { }; |
| 2383 | int err; |
| 2384 | do { |
| 2385 | err = nfs4_handle_exception(server, |
| 2386 | _nfs4_server_capabilities(server, fhandle), |
| 2387 | &exception); |
| 2388 | } while (exception.retry); |
| 2389 | return err; |
| 2390 | } |
| 2391 | |
| 2392 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2393 | struct nfs_fsinfo *info) |
| 2394 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | struct nfs4_lookup_root_arg args = { |
| 2396 | .bitmask = nfs4_fattr_bitmap, |
| 2397 | }; |
| 2398 | struct nfs4_lookup_res res = { |
| 2399 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2400 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | .fh = fhandle, |
| 2402 | }; |
| 2403 | struct rpc_message msg = { |
| 2404 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2405 | .rpc_argp = &args, |
| 2406 | .rpc_resp = &res, |
| 2407 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2408 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2409 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2410 | 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] | 2411 | } |
| 2412 | |
| 2413 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2414 | struct nfs_fsinfo *info) |
| 2415 | { |
| 2416 | struct nfs4_exception exception = { }; |
| 2417 | int err; |
| 2418 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2419 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2420 | switch (err) { |
| 2421 | case 0: |
| 2422 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2423 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2424 | default: |
| 2425 | err = nfs4_handle_exception(server, err, &exception); |
| 2426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2428 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | return err; |
| 2430 | } |
| 2431 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2432 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2433 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2434 | { |
| 2435 | struct rpc_auth *auth; |
| 2436 | int ret; |
| 2437 | |
| 2438 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2439 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2440 | ret = -EIO; |
| 2441 | goto out; |
| 2442 | } |
| 2443 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2444 | out: |
| 2445 | return ret; |
| 2446 | } |
| 2447 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2448 | 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] | 2449 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2451 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2452 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2454 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2455 | if (len < 0) |
| 2456 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2457 | |
| 2458 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2459 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2460 | * thus has already been tried. */ |
| 2461 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2462 | continue; |
| 2463 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2464 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2465 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2466 | continue; |
| 2467 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2468 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2469 | /* |
| 2470 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2471 | * to access the mount. It could also mean that we tried to mount |
| 2472 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2473 | * existing mount programs don't handle -EACCES very well so it should |
| 2474 | * be mapped to -EPERM instead. |
| 2475 | */ |
| 2476 | if (status == -EACCES) |
| 2477 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2478 | return status; |
| 2479 | } |
| 2480 | |
| 2481 | /* |
| 2482 | * get the file handle for the "/" directory on the server |
| 2483 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2484 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2485 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2486 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2487 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2488 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2489 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2490 | /* |
| 2491 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2492 | * by nfs4_map_errors() as this function exits. |
| 2493 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2494 | 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] | 2495 | if (status == 0) |
| 2496 | status = nfs4_server_capabilities(server, fhandle); |
| 2497 | if (status == 0) |
| 2498 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2499 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2502 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2503 | struct nfs_fsinfo *info) |
| 2504 | { |
| 2505 | int error; |
| 2506 | struct nfs_fattr *fattr = info->fattr; |
| 2507 | |
| 2508 | error = nfs4_server_capabilities(server, mntfh); |
| 2509 | if (error < 0) { |
| 2510 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2511 | return error; |
| 2512 | } |
| 2513 | |
| 2514 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2515 | if (error < 0) { |
| 2516 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2517 | return error; |
| 2518 | } |
| 2519 | |
| 2520 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2521 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2522 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2523 | |
| 2524 | return error; |
| 2525 | } |
| 2526 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2527 | /* |
| 2528 | * Get locations and (maybe) other attributes of a referral. |
| 2529 | * Note that we'll actually follow the referral later when |
| 2530 | * we detect fsid mismatch in inode revalidation |
| 2531 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2532 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2533 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2534 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2535 | { |
| 2536 | int status = -ENOMEM; |
| 2537 | struct page *page = NULL; |
| 2538 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2539 | |
| 2540 | page = alloc_page(GFP_KERNEL); |
| 2541 | if (page == NULL) |
| 2542 | goto out; |
| 2543 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2544 | if (locations == NULL) |
| 2545 | goto out; |
| 2546 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2547 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2548 | if (status != 0) |
| 2549 | goto out; |
| 2550 | /* Make sure server returned a different fsid for the referral */ |
| 2551 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2552 | dprintk("%s: server did not return a different fsid for" |
| 2553 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2554 | status = -EIO; |
| 2555 | goto out; |
| 2556 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2557 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2558 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2559 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2560 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2561 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2562 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2563 | out: |
| 2564 | if (page) |
| 2565 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2566 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2567 | return status; |
| 2568 | } |
| 2569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2571 | { |
| 2572 | struct nfs4_getattr_arg args = { |
| 2573 | .fh = fhandle, |
| 2574 | .bitmask = server->attr_bitmask, |
| 2575 | }; |
| 2576 | struct nfs4_getattr_res res = { |
| 2577 | .fattr = fattr, |
| 2578 | .server = server, |
| 2579 | }; |
| 2580 | struct rpc_message msg = { |
| 2581 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2582 | .rpc_argp = &args, |
| 2583 | .rpc_resp = &res, |
| 2584 | }; |
| 2585 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2586 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2587 | 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] | 2588 | } |
| 2589 | |
| 2590 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2591 | { |
| 2592 | struct nfs4_exception exception = { }; |
| 2593 | int err; |
| 2594 | do { |
| 2595 | err = nfs4_handle_exception(server, |
| 2596 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2597 | &exception); |
| 2598 | } while (exception.retry); |
| 2599 | return err; |
| 2600 | } |
| 2601 | |
| 2602 | /* |
| 2603 | * The file is not closed if it is opened due to the a request to change |
| 2604 | * the size of the file. The open call will not be needed once the |
| 2605 | * VFS layer lookup-intents are implemented. |
| 2606 | * |
| 2607 | * Close is called when the inode is destroyed. |
| 2608 | * If we haven't opened the file for O_WRONLY, we |
| 2609 | * need to in the size_change case to obtain a stateid. |
| 2610 | * |
| 2611 | * Got race? |
| 2612 | * Because OPEN is always done by name in nfsv4, it is |
| 2613 | * possible that we opened a different file by the same |
| 2614 | * name. We can recognize this race condition, but we |
| 2615 | * can't do anything about it besides returning an error. |
| 2616 | * |
| 2617 | * This will be fixed with VFS changes (lookup-intent). |
| 2618 | */ |
| 2619 | static int |
| 2620 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2621 | struct iattr *sattr) |
| 2622 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2623 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2624 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2625 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | int status; |
| 2627 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2628 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2629 | pnfs_return_layout(inode); |
| 2630 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2631 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2633 | /* Deal with open(O_TRUNC) */ |
| 2634 | if (sattr->ia_valid & ATTR_OPEN) |
| 2635 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2636 | |
| 2637 | /* Optimization: if the end result is no change, don't RPC */ |
| 2638 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2639 | return 0; |
| 2640 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2641 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2642 | if (sattr->ia_valid & ATTR_FILE) { |
| 2643 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2644 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2645 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2646 | if (ctx) { |
| 2647 | cred = ctx->cred; |
| 2648 | state = ctx->state; |
| 2649 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2653 | if (status == 0) |
| 2654 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | return status; |
| 2656 | } |
| 2657 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2658 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2659 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2660 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2661 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2662 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2663 | int status; |
| 2664 | struct nfs4_lookup_arg args = { |
| 2665 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2666 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2667 | .name = name, |
| 2668 | }; |
| 2669 | struct nfs4_lookup_res res = { |
| 2670 | .server = server, |
| 2671 | .fattr = fattr, |
| 2672 | .fh = fhandle, |
| 2673 | }; |
| 2674 | struct rpc_message msg = { |
| 2675 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2676 | .rpc_argp = &args, |
| 2677 | .rpc_resp = &res, |
| 2678 | }; |
| 2679 | |
| 2680 | nfs_fattr_init(fattr); |
| 2681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2683 | 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] | 2684 | dprintk("NFS reply lookup: %d\n", status); |
| 2685 | return status; |
| 2686 | } |
| 2687 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2688 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2689 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2690 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2691 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2692 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2693 | fattr->nlink = 2; |
| 2694 | } |
| 2695 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2696 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2697 | struct qstr *name, struct nfs_fh *fhandle, |
| 2698 | struct nfs_fattr *fattr) |
| 2699 | { |
| 2700 | struct nfs4_exception exception = { }; |
| 2701 | struct rpc_clnt *client = *clnt; |
| 2702 | int err; |
| 2703 | do { |
| 2704 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2705 | switch (err) { |
| 2706 | case -NFS4ERR_BADNAME: |
| 2707 | err = -ENOENT; |
| 2708 | goto out; |
| 2709 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2710 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2711 | goto out; |
| 2712 | case -NFS4ERR_WRONGSEC: |
| 2713 | err = -EPERM; |
| 2714 | if (client != *clnt) |
| 2715 | goto out; |
| 2716 | |
| 2717 | client = nfs4_create_sec_client(client, dir, name); |
| 2718 | if (IS_ERR(client)) |
| 2719 | return PTR_ERR(client); |
| 2720 | |
| 2721 | exception.retry = 1; |
| 2722 | break; |
| 2723 | default: |
| 2724 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2725 | } |
| 2726 | } while (exception.retry); |
| 2727 | |
| 2728 | out: |
| 2729 | if (err == 0) |
| 2730 | *clnt = client; |
| 2731 | else if (client != *clnt) |
| 2732 | rpc_shutdown_client(client); |
| 2733 | |
| 2734 | return err; |
| 2735 | } |
| 2736 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2737 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2738 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2740 | int status; |
| 2741 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2742 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2743 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2744 | if (client != NFS_CLIENT(dir)) { |
| 2745 | rpc_shutdown_client(client); |
| 2746 | nfs_fixup_secinfo_attributes(fattr); |
| 2747 | } |
| 2748 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2751 | struct rpc_clnt * |
| 2752 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2753 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2754 | { |
| 2755 | int status; |
| 2756 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2757 | |
| 2758 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2759 | if (status < 0) { |
| 2760 | rpc_shutdown_client(client); |
| 2761 | return ERR_PTR(status); |
| 2762 | } |
| 2763 | return client; |
| 2764 | } |
| 2765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2767 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2768 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | struct nfs4_accessargs args = { |
| 2770 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2771 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2773 | struct nfs4_accessres res = { |
| 2774 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2775 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | struct rpc_message msg = { |
| 2777 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2778 | .rpc_argp = &args, |
| 2779 | .rpc_resp = &res, |
| 2780 | .rpc_cred = entry->cred, |
| 2781 | }; |
| 2782 | int mode = entry->mask; |
| 2783 | int status; |
| 2784 | |
| 2785 | /* |
| 2786 | * Determine which access bits we want to ask for... |
| 2787 | */ |
| 2788 | if (mode & MAY_READ) |
| 2789 | args.access |= NFS4_ACCESS_READ; |
| 2790 | if (S_ISDIR(inode->i_mode)) { |
| 2791 | if (mode & MAY_WRITE) |
| 2792 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2793 | if (mode & MAY_EXEC) |
| 2794 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2795 | } else { |
| 2796 | if (mode & MAY_WRITE) |
| 2797 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2798 | if (mode & MAY_EXEC) |
| 2799 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2800 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2801 | |
| 2802 | res.fattr = nfs_alloc_fattr(); |
| 2803 | if (res.fattr == NULL) |
| 2804 | return -ENOMEM; |
| 2805 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2806 | 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] | 2807 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2808 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2809 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2811 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | return status; |
| 2813 | } |
| 2814 | |
| 2815 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2816 | { |
| 2817 | struct nfs4_exception exception = { }; |
| 2818 | int err; |
| 2819 | do { |
| 2820 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2821 | _nfs4_proc_access(inode, entry), |
| 2822 | &exception); |
| 2823 | } while (exception.retry); |
| 2824 | return err; |
| 2825 | } |
| 2826 | |
| 2827 | /* |
| 2828 | * TODO: For the time being, we don't try to get any attributes |
| 2829 | * along with any of the zero-copy operations READ, READDIR, |
| 2830 | * READLINK, WRITE. |
| 2831 | * |
| 2832 | * In the case of the first three, we want to put the GETATTR |
| 2833 | * after the read-type operation -- this is because it is hard |
| 2834 | * to predict the length of a GETATTR response in v4, and thus |
| 2835 | * align the READ data correctly. This means that the GETATTR |
| 2836 | * may end up partially falling into the page cache, and we should |
| 2837 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2838 | * To do this efficiently, we need to know the total length |
| 2839 | * of data received, which doesn't seem to be available outside |
| 2840 | * of the RPC layer. |
| 2841 | * |
| 2842 | * In the case of WRITE, we also want to put the GETATTR after |
| 2843 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2844 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | * |
| 2846 | * Both of these changes to the XDR layer would in fact be quite |
| 2847 | * minor, but I decided to leave them for a subsequent patch. |
| 2848 | */ |
| 2849 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2850 | unsigned int pgbase, unsigned int pglen) |
| 2851 | { |
| 2852 | struct nfs4_readlink args = { |
| 2853 | .fh = NFS_FH(inode), |
| 2854 | .pgbase = pgbase, |
| 2855 | .pglen = pglen, |
| 2856 | .pages = &page, |
| 2857 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2858 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | struct rpc_message msg = { |
| 2860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2861 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2862 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | }; |
| 2864 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2865 | 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] | 2866 | } |
| 2867 | |
| 2868 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2869 | unsigned int pgbase, unsigned int pglen) |
| 2870 | { |
| 2871 | struct nfs4_exception exception = { }; |
| 2872 | int err; |
| 2873 | do { |
| 2874 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2875 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2876 | &exception); |
| 2877 | } while (exception.retry); |
| 2878 | return err; |
| 2879 | } |
| 2880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2882 | * 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] | 2883 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | static int |
| 2885 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2886 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2888 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | int status = 0; |
| 2891 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2892 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2893 | if (IS_ERR(ctx)) |
| 2894 | return PTR_ERR(ctx); |
| 2895 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2896 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2897 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2898 | flags, sattr, ctx->cred, |
| 2899 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2900 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | if (IS_ERR(state)) { |
| 2902 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2903 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2905 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2906 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2907 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2909 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | return status; |
| 2911 | } |
| 2912 | |
| 2913 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2914 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2915 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2916 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2918 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2920 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2921 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2922 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2925 | .rpc_argp = &args, |
| 2926 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2928 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2929 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2930 | 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] | 2931 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2932 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | return status; |
| 2934 | } |
| 2935 | |
| 2936 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2937 | { |
| 2938 | struct nfs4_exception exception = { }; |
| 2939 | int err; |
| 2940 | do { |
| 2941 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2942 | _nfs4_proc_remove(dir, name), |
| 2943 | &exception); |
| 2944 | } while (exception.retry); |
| 2945 | return err; |
| 2946 | } |
| 2947 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2948 | 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] | 2949 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2950 | struct nfs_server *server = NFS_SERVER(dir); |
| 2951 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2952 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2954 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2956 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | } |
| 2958 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2959 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2960 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2961 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2962 | &data->args.seq_args, |
| 2963 | &data->res.seq_res, |
| 2964 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2967 | 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] | 2968 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2969 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2970 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2971 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2972 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2973 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2974 | return 0; |
| 2975 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2976 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2979 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2980 | { |
| 2981 | struct nfs_server *server = NFS_SERVER(dir); |
| 2982 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2983 | struct nfs_renameres *res = msg->rpc_resp; |
| 2984 | |
| 2985 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2986 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2987 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2988 | } |
| 2989 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2990 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2991 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2992 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2993 | &data->args.seq_args, |
| 2994 | &data->res.seq_res, |
| 2995 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2999 | struct inode *new_dir) |
| 3000 | { |
| 3001 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3002 | |
| 3003 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3004 | return 0; |
| 3005 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3006 | return 0; |
| 3007 | |
| 3008 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3009 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3010 | return 1; |
| 3011 | } |
| 3012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3014 | struct inode *new_dir, struct qstr *new_name) |
| 3015 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3016 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3017 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | .old_dir = NFS_FH(old_dir), |
| 3019 | .new_dir = NFS_FH(new_dir), |
| 3020 | .old_name = old_name, |
| 3021 | .new_name = new_name, |
| 3022 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3023 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3024 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3025 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | struct rpc_message msg = { |
| 3027 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3028 | .rpc_argp = &arg, |
| 3029 | .rpc_resp = &res, |
| 3030 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3031 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3033 | 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] | 3034 | if (!status) { |
| 3035 | update_changeattr(old_dir, &res.old_cinfo); |
| 3036 | update_changeattr(new_dir, &res.new_cinfo); |
| 3037 | } |
| 3038 | return status; |
| 3039 | } |
| 3040 | |
| 3041 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3042 | struct inode *new_dir, struct qstr *new_name) |
| 3043 | { |
| 3044 | struct nfs4_exception exception = { }; |
| 3045 | int err; |
| 3046 | do { |
| 3047 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3048 | _nfs4_proc_rename(old_dir, old_name, |
| 3049 | new_dir, new_name), |
| 3050 | &exception); |
| 3051 | } while (exception.retry); |
| 3052 | return err; |
| 3053 | } |
| 3054 | |
| 3055 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3056 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3057 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | struct nfs4_link_arg arg = { |
| 3059 | .fh = NFS_FH(inode), |
| 3060 | .dir_fh = NFS_FH(dir), |
| 3061 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3062 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3064 | struct nfs4_link_res res = { |
| 3065 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3066 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | struct rpc_message msg = { |
| 3068 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3069 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3070 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3072 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3074 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3075 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3076 | goto out; |
| 3077 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3078 | 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] | 3079 | if (!status) { |
| 3080 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3081 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3082 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3083 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3084 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | return status; |
| 3086 | } |
| 3087 | |
| 3088 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3089 | { |
| 3090 | struct nfs4_exception exception = { }; |
| 3091 | int err; |
| 3092 | do { |
| 3093 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3094 | _nfs4_proc_link(inode, dir, name), |
| 3095 | &exception); |
| 3096 | } while (exception.retry); |
| 3097 | return err; |
| 3098 | } |
| 3099 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3100 | struct nfs4_createdata { |
| 3101 | struct rpc_message msg; |
| 3102 | struct nfs4_create_arg arg; |
| 3103 | struct nfs4_create_res res; |
| 3104 | struct nfs_fh fh; |
| 3105 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3106 | }; |
| 3107 | |
| 3108 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3109 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3110 | { |
| 3111 | struct nfs4_createdata *data; |
| 3112 | |
| 3113 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3114 | if (data != NULL) { |
| 3115 | struct nfs_server *server = NFS_SERVER(dir); |
| 3116 | |
| 3117 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3118 | data->msg.rpc_argp = &data->arg; |
| 3119 | data->msg.rpc_resp = &data->res; |
| 3120 | data->arg.dir_fh = NFS_FH(dir); |
| 3121 | data->arg.server = server; |
| 3122 | data->arg.name = name; |
| 3123 | data->arg.attrs = sattr; |
| 3124 | data->arg.ftype = ftype; |
| 3125 | data->arg.bitmask = server->attr_bitmask; |
| 3126 | data->res.server = server; |
| 3127 | data->res.fh = &data->fh; |
| 3128 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3129 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3130 | } |
| 3131 | return data; |
| 3132 | } |
| 3133 | |
| 3134 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3135 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3136 | 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] | 3137 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3138 | if (status == 0) { |
| 3139 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3140 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3141 | } |
| 3142 | return status; |
| 3143 | } |
| 3144 | |
| 3145 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3146 | { |
| 3147 | kfree(data); |
| 3148 | } |
| 3149 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3150 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3151 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3153 | struct nfs4_createdata *data; |
| 3154 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3156 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3157 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3158 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3159 | status = -ENOMEM; |
| 3160 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3161 | if (data == NULL) |
| 3162 | goto out; |
| 3163 | |
| 3164 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3165 | data->arg.u.symlink.pages = &page; |
| 3166 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3168 | status = nfs4_do_create(dir, dentry, data); |
| 3169 | |
| 3170 | nfs4_free_createdata(data); |
| 3171 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | return status; |
| 3173 | } |
| 3174 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3175 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3176 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | { |
| 3178 | struct nfs4_exception exception = { }; |
| 3179 | int err; |
| 3180 | do { |
| 3181 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3182 | _nfs4_proc_symlink(dir, dentry, page, |
| 3183 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | &exception); |
| 3185 | } while (exception.retry); |
| 3186 | return err; |
| 3187 | } |
| 3188 | |
| 3189 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3190 | struct iattr *sattr) |
| 3191 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3192 | struct nfs4_createdata *data; |
| 3193 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3195 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3196 | if (data == NULL) |
| 3197 | goto out; |
| 3198 | |
| 3199 | status = nfs4_do_create(dir, dentry, data); |
| 3200 | |
| 3201 | nfs4_free_createdata(data); |
| 3202 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | return status; |
| 3204 | } |
| 3205 | |
| 3206 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3207 | struct iattr *sattr) |
| 3208 | { |
| 3209 | struct nfs4_exception exception = { }; |
| 3210 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3211 | |
| 3212 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | do { |
| 3214 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3215 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3216 | &exception); |
| 3217 | } while (exception.retry); |
| 3218 | return err; |
| 3219 | } |
| 3220 | |
| 3221 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3222 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | { |
| 3224 | struct inode *dir = dentry->d_inode; |
| 3225 | struct nfs4_readdir_arg args = { |
| 3226 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3227 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | .pgbase = 0, |
| 3229 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3230 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3231 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | }; |
| 3233 | struct nfs4_readdir_res res; |
| 3234 | struct rpc_message msg = { |
| 3235 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3236 | .rpc_argp = &args, |
| 3237 | .rpc_resp = &res, |
| 3238 | .rpc_cred = cred, |
| 3239 | }; |
| 3240 | int status; |
| 3241 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3242 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3243 | dentry->d_parent->d_name.name, |
| 3244 | dentry->d_name.name, |
| 3245 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3246 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3248 | 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] | 3249 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3250 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3251 | status += args.pgbase; |
| 3252 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3253 | |
| 3254 | nfs_invalidate_atime(dir); |
| 3255 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3256 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | return status; |
| 3258 | } |
| 3259 | |
| 3260 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3261 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | { |
| 3263 | struct nfs4_exception exception = { }; |
| 3264 | int err; |
| 3265 | do { |
| 3266 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3267 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3268 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | &exception); |
| 3270 | } while (exception.retry); |
| 3271 | return err; |
| 3272 | } |
| 3273 | |
| 3274 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3275 | struct iattr *sattr, dev_t rdev) |
| 3276 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3277 | struct nfs4_createdata *data; |
| 3278 | int mode = sattr->ia_mode; |
| 3279 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3281 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3282 | if (data == NULL) |
| 3283 | goto out; |
| 3284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3286 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3288 | data->arg.ftype = NF4BLK; |
| 3289 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3290 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | } |
| 3292 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3293 | data->arg.ftype = NF4CHR; |
| 3294 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3295 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3296 | } else if (!S_ISSOCK(mode)) { |
| 3297 | status = -EINVAL; |
| 3298 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3301 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3302 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3303 | nfs4_free_createdata(data); |
| 3304 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | return status; |
| 3306 | } |
| 3307 | |
| 3308 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3309 | struct iattr *sattr, dev_t rdev) |
| 3310 | { |
| 3311 | struct nfs4_exception exception = { }; |
| 3312 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3313 | |
| 3314 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | do { |
| 3316 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3317 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3318 | &exception); |
| 3319 | } while (exception.retry); |
| 3320 | return err; |
| 3321 | } |
| 3322 | |
| 3323 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3324 | struct nfs_fsstat *fsstat) |
| 3325 | { |
| 3326 | struct nfs4_statfs_arg args = { |
| 3327 | .fh = fhandle, |
| 3328 | .bitmask = server->attr_bitmask, |
| 3329 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3330 | struct nfs4_statfs_res res = { |
| 3331 | .fsstat = fsstat, |
| 3332 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | struct rpc_message msg = { |
| 3334 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3335 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3336 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | }; |
| 3338 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3339 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3340 | 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] | 3341 | } |
| 3342 | |
| 3343 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3344 | { |
| 3345 | struct nfs4_exception exception = { }; |
| 3346 | int err; |
| 3347 | do { |
| 3348 | err = nfs4_handle_exception(server, |
| 3349 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3350 | &exception); |
| 3351 | } while (exception.retry); |
| 3352 | return err; |
| 3353 | } |
| 3354 | |
| 3355 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3356 | struct nfs_fsinfo *fsinfo) |
| 3357 | { |
| 3358 | struct nfs4_fsinfo_arg args = { |
| 3359 | .fh = fhandle, |
| 3360 | .bitmask = server->attr_bitmask, |
| 3361 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3362 | struct nfs4_fsinfo_res res = { |
| 3363 | .fsinfo = fsinfo, |
| 3364 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | struct rpc_message msg = { |
| 3366 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3367 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3368 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | }; |
| 3370 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3371 | 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] | 3372 | } |
| 3373 | |
| 3374 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3375 | { |
| 3376 | struct nfs4_exception exception = { }; |
| 3377 | int err; |
| 3378 | |
| 3379 | do { |
| 3380 | err = nfs4_handle_exception(server, |
| 3381 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3382 | &exception); |
| 3383 | } while (exception.retry); |
| 3384 | return err; |
| 3385 | } |
| 3386 | |
| 3387 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3388 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3389 | int error; |
| 3390 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3391 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3392 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3393 | if (error == 0) { |
| 3394 | /* block layout checks this! */ |
| 3395 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3396 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3397 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3398 | |
| 3399 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3403 | struct nfs_pathconf *pathconf) |
| 3404 | { |
| 3405 | struct nfs4_pathconf_arg args = { |
| 3406 | .fh = fhandle, |
| 3407 | .bitmask = server->attr_bitmask, |
| 3408 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3409 | struct nfs4_pathconf_res res = { |
| 3410 | .pathconf = pathconf, |
| 3411 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | struct rpc_message msg = { |
| 3413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3414 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3415 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | }; |
| 3417 | |
| 3418 | /* None of the pathconf attributes are mandatory to implement */ |
| 3419 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3420 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3421 | return 0; |
| 3422 | } |
| 3423 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3424 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3425 | 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] | 3426 | } |
| 3427 | |
| 3428 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3429 | struct nfs_pathconf *pathconf) |
| 3430 | { |
| 3431 | struct nfs4_exception exception = { }; |
| 3432 | int err; |
| 3433 | |
| 3434 | do { |
| 3435 | err = nfs4_handle_exception(server, |
| 3436 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3437 | &exception); |
| 3438 | } while (exception.retry); |
| 3439 | return err; |
| 3440 | } |
| 3441 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3442 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3443 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3444 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3445 | } |
| 3446 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3447 | 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] | 3448 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3449 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3451 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3452 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3453 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3455 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3456 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3458 | renew_lease(server, data->timestamp); |
| 3459 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | } |
| 3461 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3462 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3463 | { |
| 3464 | |
| 3465 | dprintk("--> %s\n", __func__); |
| 3466 | |
| 3467 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3468 | return -EAGAIN; |
| 3469 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3470 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3471 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3474 | 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] | 3475 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3477 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3478 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3479 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3482 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3483 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3484 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3485 | &data->args.seq_args, |
| 3486 | &data->res.seq_res, |
| 3487 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3490 | 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] | 3491 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3492 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3494 | 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] | 3495 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3496 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3498 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3500 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3501 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3502 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3505 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3506 | { |
| 3507 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3508 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3509 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3510 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3513 | static |
| 3514 | 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] | 3515 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3516 | const struct nfs_pgio_header *hdr = data->header; |
| 3517 | |
| 3518 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3519 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3520 | return false; |
| 3521 | /* Otherwise, request attributes if and only if we don't hold |
| 3522 | * a delegation |
| 3523 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3524 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3525 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3526 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3527 | 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] | 3528 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3529 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3530 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3531 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3532 | data->args.bitmask = NULL; |
| 3533 | data->res.fattr = NULL; |
| 3534 | } else |
| 3535 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3536 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3537 | if (!data->write_done_cb) |
| 3538 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3539 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | data->timestamp = jiffies; |
| 3541 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3542 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3543 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3546 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3547 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3548 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3549 | &data->args.seq_args, |
| 3550 | &data->res.seq_res, |
| 3551 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3554 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3555 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3556 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3557 | &data->args.seq_args, |
| 3558 | &data->res.seq_res, |
| 3559 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | } |
| 3561 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3562 | 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] | 3563 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3565 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3566 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3567 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3568 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3570 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3573 | 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] | 3574 | { |
| 3575 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3576 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3577 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3580 | 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] | 3581 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3582 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3583 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3584 | if (data->commit_done_cb == NULL) |
| 3585 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3586 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3587 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3588 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3591 | struct nfs4_renewdata { |
| 3592 | struct nfs_client *client; |
| 3593 | unsigned long timestamp; |
| 3594 | }; |
| 3595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | /* |
| 3597 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3598 | * standalone procedure for queueing an asynchronous RENEW. |
| 3599 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3600 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3601 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3602 | struct nfs4_renewdata *data = calldata; |
| 3603 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3604 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3605 | if (atomic_read(&clp->cl_count) > 1) |
| 3606 | nfs4_schedule_state_renewal(clp); |
| 3607 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3608 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3609 | } |
| 3610 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3611 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3613 | struct nfs4_renewdata *data = calldata; |
| 3614 | struct nfs_client *clp = data->client; |
| 3615 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | |
| 3617 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3618 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3619 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3620 | return; |
| 3621 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3622 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3623 | return; |
| 3624 | } |
| 3625 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3627 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3630 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3631 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3632 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3633 | }; |
| 3634 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3635 | 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] | 3636 | { |
| 3637 | struct rpc_message msg = { |
| 3638 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3639 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3640 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3642 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3644 | if (renew_flags == 0) |
| 3645 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3646 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3647 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3648 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3649 | if (data == NULL) |
| 3650 | return -ENOMEM; |
| 3651 | data->client = clp; |
| 3652 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3654 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | } |
| 3656 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3657 | 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] | 3658 | { |
| 3659 | struct rpc_message msg = { |
| 3660 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3661 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3662 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | }; |
| 3664 | unsigned long now = jiffies; |
| 3665 | int status; |
| 3666 | |
| 3667 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3668 | if (status < 0) |
| 3669 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3670 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | return 0; |
| 3672 | } |
| 3673 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3674 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3675 | { |
| 3676 | return (server->caps & NFS_CAP_ACLS) |
| 3677 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3678 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3679 | } |
| 3680 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3681 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3682 | * 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] | 3683 | * the stack. |
| 3684 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3685 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3686 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3687 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3688 | struct page **pages, unsigned int *pgbase) |
| 3689 | { |
| 3690 | struct page *newpage, **spages; |
| 3691 | int rc = 0; |
| 3692 | size_t len; |
| 3693 | spages = pages; |
| 3694 | |
| 3695 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3696 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3697 | newpage = alloc_page(GFP_KERNEL); |
| 3698 | |
| 3699 | if (newpage == NULL) |
| 3700 | goto unwind; |
| 3701 | memcpy(page_address(newpage), buf, len); |
| 3702 | buf += len; |
| 3703 | buflen -= len; |
| 3704 | *pages++ = newpage; |
| 3705 | rc++; |
| 3706 | } while (buflen != 0); |
| 3707 | |
| 3708 | return rc; |
| 3709 | |
| 3710 | unwind: |
| 3711 | for(; rc > 0; rc--) |
| 3712 | __free_page(spages[rc-1]); |
| 3713 | return -ENOMEM; |
| 3714 | } |
| 3715 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3716 | struct nfs4_cached_acl { |
| 3717 | int cached; |
| 3718 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3719 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3720 | }; |
| 3721 | |
| 3722 | 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] | 3723 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3724 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3725 | |
| 3726 | spin_lock(&inode->i_lock); |
| 3727 | kfree(nfsi->nfs4_acl); |
| 3728 | nfsi->nfs4_acl = acl; |
| 3729 | spin_unlock(&inode->i_lock); |
| 3730 | } |
| 3731 | |
| 3732 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3733 | { |
| 3734 | nfs4_set_cached_acl(inode, NULL); |
| 3735 | } |
| 3736 | |
| 3737 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3738 | { |
| 3739 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3740 | struct nfs4_cached_acl *acl; |
| 3741 | int ret = -ENOENT; |
| 3742 | |
| 3743 | spin_lock(&inode->i_lock); |
| 3744 | acl = nfsi->nfs4_acl; |
| 3745 | if (acl == NULL) |
| 3746 | goto out; |
| 3747 | if (buf == NULL) /* user is just asking for length */ |
| 3748 | goto out_len; |
| 3749 | if (acl->cached == 0) |
| 3750 | goto out; |
| 3751 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3752 | if (acl->len > buflen) |
| 3753 | goto out; |
| 3754 | memcpy(buf, acl->data, acl->len); |
| 3755 | out_len: |
| 3756 | ret = acl->len; |
| 3757 | out: |
| 3758 | spin_unlock(&inode->i_lock); |
| 3759 | return ret; |
| 3760 | } |
| 3761 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3762 | 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] | 3763 | { |
| 3764 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3765 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3766 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3767 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3768 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3769 | if (acl == NULL) |
| 3770 | goto out; |
| 3771 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3772 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3773 | } else { |
| 3774 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3775 | if (acl == NULL) |
| 3776 | goto out; |
| 3777 | acl->cached = 0; |
| 3778 | } |
| 3779 | acl->len = acl_len; |
| 3780 | out: |
| 3781 | nfs4_set_cached_acl(inode, acl); |
| 3782 | } |
| 3783 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3784 | /* |
| 3785 | * The getxattr API returns the required buffer length when called with a |
| 3786 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3787 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3788 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3789 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3790 | * the cache. If not so, we throw away the page, and cache the required |
| 3791 | * length. The next getxattr call will then produce another round trip to |
| 3792 | * the server, this time with the input buf of the required size. |
| 3793 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3794 | 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] | 3795 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3796 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3797 | struct nfs_getaclargs args = { |
| 3798 | .fh = NFS_FH(inode), |
| 3799 | .acl_pages = pages, |
| 3800 | .acl_len = buflen, |
| 3801 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3802 | struct nfs_getaclres res = { |
| 3803 | .acl_len = buflen, |
| 3804 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3805 | struct rpc_message msg = { |
| 3806 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3807 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3808 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3809 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3810 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3811 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3812 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3813 | /* As long as we're doing a round trip to the server anyway, |
| 3814 | * let's be prepared for a page of acl data. */ |
| 3815 | if (npages == 0) |
| 3816 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3817 | if (npages > ARRAY_SIZE(pages)) |
| 3818 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3819 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3820 | for (i = 0; i < npages; i++) { |
| 3821 | pages[i] = alloc_page(GFP_KERNEL); |
| 3822 | if (!pages[i]) |
| 3823 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3824 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3825 | |
| 3826 | /* for decoding across pages */ |
| 3827 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3828 | if (!res.acl_scratch) |
| 3829 | goto out_free; |
| 3830 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3831 | args.acl_len = npages * PAGE_SIZE; |
| 3832 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3833 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3834 | 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] | 3835 | __func__, buf, buflen, npages, args.acl_len); |
| 3836 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3837 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3838 | if (ret) |
| 3839 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3840 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3841 | /* Handle the case where the passed-in buffer is too short */ |
| 3842 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3843 | /* Did the user only issue a request for the acl length? */ |
| 3844 | if (buf == NULL) |
| 3845 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3846 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3847 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3848 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3849 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 3850 | if (buf) { |
| 3851 | if (res.acl_len > buflen) { |
| 3852 | ret = -ERANGE; |
| 3853 | goto out_free; |
| 3854 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3855 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 3856 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3857 | out_ok: |
| 3858 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3859 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3860 | for (i = 0; i < npages; i++) |
| 3861 | if (pages[i]) |
| 3862 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3863 | if (res.acl_scratch) |
| 3864 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3865 | return ret; |
| 3866 | } |
| 3867 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3868 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3869 | { |
| 3870 | struct nfs4_exception exception = { }; |
| 3871 | ssize_t ret; |
| 3872 | do { |
| 3873 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3874 | if (ret >= 0) |
| 3875 | break; |
| 3876 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3877 | } while (exception.retry); |
| 3878 | return ret; |
| 3879 | } |
| 3880 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3881 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3882 | { |
| 3883 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3884 | int ret; |
| 3885 | |
| 3886 | if (!nfs4_server_supports_acls(server)) |
| 3887 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3888 | ret = nfs_revalidate_inode(server, inode); |
| 3889 | if (ret < 0) |
| 3890 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3891 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3892 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3893 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3894 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3895 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3896 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3897 | return ret; |
| 3898 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3901 | 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] | 3902 | { |
| 3903 | struct nfs_server *server = NFS_SERVER(inode); |
| 3904 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3905 | struct nfs_setaclargs arg = { |
| 3906 | .fh = NFS_FH(inode), |
| 3907 | .acl_pages = pages, |
| 3908 | .acl_len = buflen, |
| 3909 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3910 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3911 | struct rpc_message msg = { |
| 3912 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3913 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3914 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3915 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3916 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3917 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3918 | |
| 3919 | if (!nfs4_server_supports_acls(server)) |
| 3920 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3921 | if (npages > ARRAY_SIZE(pages)) |
| 3922 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3923 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3924 | if (i < 0) |
| 3925 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3926 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3927 | 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] | 3928 | |
| 3929 | /* |
| 3930 | * Free each page after tx, so the only ref left is |
| 3931 | * held by the network stack |
| 3932 | */ |
| 3933 | for (; i > 0; i--) |
| 3934 | put_page(pages[i-1]); |
| 3935 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3936 | /* |
| 3937 | * Acl update can result in inode attribute update. |
| 3938 | * so mark the attribute cache invalid. |
| 3939 | */ |
| 3940 | spin_lock(&inode->i_lock); |
| 3941 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3942 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3943 | nfs_access_zap_cache(inode); |
| 3944 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3945 | return ret; |
| 3946 | } |
| 3947 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3948 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3949 | { |
| 3950 | struct nfs4_exception exception = { }; |
| 3951 | int err; |
| 3952 | do { |
| 3953 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3954 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3955 | &exception); |
| 3956 | } while (exception.retry); |
| 3957 | return err; |
| 3958 | } |
| 3959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3961 | 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] | 3962 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3963 | struct nfs_client *clp = server->nfs_client; |
| 3964 | |
| 3965 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | return 0; |
| 3967 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3968 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3969 | case -NFS4ERR_ADMIN_REVOKED: |
| 3970 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3971 | if (state == NULL) |
| 3972 | break; |
| 3973 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3974 | case -NFS4ERR_OPENMODE: |
| 3975 | if (state == NULL) |
| 3976 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3977 | nfs4_schedule_stateid_recovery(server, state); |
| 3978 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3979 | case -NFS4ERR_EXPIRED: |
| 3980 | if (state != NULL) |
| 3981 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3983 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3984 | nfs4_schedule_lease_recovery(clp); |
| 3985 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3986 | #if defined(CONFIG_NFS_V4_1) |
| 3987 | case -NFS4ERR_BADSESSION: |
| 3988 | case -NFS4ERR_BADSLOT: |
| 3989 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3990 | case -NFS4ERR_DEADSESSION: |
| 3991 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3992 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3993 | case -NFS4ERR_SEQ_MISORDERED: |
| 3994 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3995 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3996 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3997 | task->tk_status = 0; |
| 3998 | return -EAGAIN; |
| 3999 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4001 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4002 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4004 | task->tk_status = 0; |
| 4005 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4006 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | case -NFS4ERR_OLD_STATEID: |
| 4008 | task->tk_status = 0; |
| 4009 | return -EAGAIN; |
| 4010 | } |
| 4011 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4012 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4013 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4014 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4015 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4016 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4017 | task->tk_status = 0; |
| 4018 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4021 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4022 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4023 | { |
| 4024 | __be32 verf[2]; |
| 4025 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4026 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4027 | /* An impossible timestamp guarantees this value |
| 4028 | * will never match a generated boot time. */ |
| 4029 | verf[0] = 0; |
| 4030 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4031 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4032 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4033 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4034 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4035 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4036 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4037 | } |
| 4038 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4039 | static unsigned int |
| 4040 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4041 | char *buf, size_t len) |
| 4042 | { |
| 4043 | unsigned int result; |
| 4044 | |
| 4045 | rcu_read_lock(); |
| 4046 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4047 | clp->cl_ipaddr, |
| 4048 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4049 | RPC_DISPLAY_ADDR), |
| 4050 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4051 | RPC_DISPLAY_PROTO)); |
| 4052 | rcu_read_unlock(); |
| 4053 | return result; |
| 4054 | } |
| 4055 | |
| 4056 | static unsigned int |
| 4057 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4058 | char *buf, size_t len) |
| 4059 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4060 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4061 | |
| 4062 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4063 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4064 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4065 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4066 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4067 | } |
| 4068 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4069 | /** |
| 4070 | * nfs4_proc_setclientid - Negotiate client ID |
| 4071 | * @clp: state data structure |
| 4072 | * @program: RPC program for NFSv4 callback service |
| 4073 | * @port: IP port number for NFS4 callback service |
| 4074 | * @cred: RPC credential to use for this call |
| 4075 | * @res: where to place the result |
| 4076 | * |
| 4077 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4078 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4079 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4080 | unsigned short port, struct rpc_cred *cred, |
| 4081 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | { |
| 4083 | nfs4_verifier sc_verifier; |
| 4084 | struct nfs4_setclientid setclientid = { |
| 4085 | .sc_verifier = &sc_verifier, |
| 4086 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4087 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | }; |
| 4089 | struct rpc_message msg = { |
| 4090 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4091 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4092 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4093 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4095 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4097 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4098 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4099 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4100 | setclientid.sc_name_len = |
| 4101 | nfs4_init_uniform_client_string(clp, |
| 4102 | setclientid.sc_name, |
| 4103 | sizeof(setclientid.sc_name)); |
| 4104 | else |
| 4105 | setclientid.sc_name_len = |
| 4106 | nfs4_init_nonuniform_client_string(clp, |
| 4107 | setclientid.sc_name, |
| 4108 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4109 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4110 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4111 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4112 | sizeof(setclientid.sc_netid), |
| 4113 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4114 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4115 | rcu_read_unlock(); |
| 4116 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4117 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4119 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4120 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4121 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4122 | setclientid.sc_name_len, setclientid.sc_name); |
| 4123 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4124 | dprintk("NFS reply setclientid: %d\n", status); |
| 4125 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | } |
| 4127 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4128 | /** |
| 4129 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4130 | * @clp: state data structure |
| 4131 | * @res: result of a previous SETCLIENTID |
| 4132 | * @cred: RPC credential to use for this call |
| 4133 | * |
| 4134 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4135 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4136 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4137 | struct nfs4_setclientid_res *arg, |
| 4138 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | { |
| 4140 | struct nfs_fsinfo fsinfo; |
| 4141 | struct rpc_message msg = { |
| 4142 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4143 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4145 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | }; |
| 4147 | unsigned long now; |
| 4148 | int status; |
| 4149 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4150 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4151 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4152 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4154 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | if (status == 0) { |
| 4156 | spin_lock(&clp->cl_lock); |
| 4157 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4158 | clp->cl_last_renewal = now; |
| 4159 | spin_unlock(&clp->cl_lock); |
| 4160 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4161 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | return status; |
| 4163 | } |
| 4164 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4165 | struct nfs4_delegreturndata { |
| 4166 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4167 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4168 | struct nfs_fh fh; |
| 4169 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4170 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4171 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4172 | int rpc_status; |
| 4173 | }; |
| 4174 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4175 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4176 | { |
| 4177 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4178 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4179 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4180 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4181 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4182 | switch (task->tk_status) { |
| 4183 | case -NFS4ERR_STALE_STATEID: |
| 4184 | case -NFS4ERR_EXPIRED: |
| 4185 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4186 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4187 | break; |
| 4188 | default: |
| 4189 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4190 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4191 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4192 | return; |
| 4193 | } |
| 4194 | } |
| 4195 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | static void nfs4_delegreturn_release(void *calldata) |
| 4199 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4200 | kfree(calldata); |
| 4201 | } |
| 4202 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4203 | #if defined(CONFIG_NFS_V4_1) |
| 4204 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4205 | { |
| 4206 | struct nfs4_delegreturndata *d_data; |
| 4207 | |
| 4208 | d_data = (struct nfs4_delegreturndata *)data; |
| 4209 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4210 | nfs4_setup_sequence(d_data->res.server, |
| 4211 | &d_data->args.seq_args, |
| 4212 | &d_data->res.seq_res, |
| 4213 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4214 | } |
| 4215 | #endif /* CONFIG_NFS_V4_1 */ |
| 4216 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4217 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4218 | #if defined(CONFIG_NFS_V4_1) |
| 4219 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4220 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4221 | .rpc_call_done = nfs4_delegreturn_done, |
| 4222 | .rpc_release = nfs4_delegreturn_release, |
| 4223 | }; |
| 4224 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4225 | 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] | 4226 | { |
| 4227 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4228 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4229 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4230 | struct rpc_message msg = { |
| 4231 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4232 | .rpc_cred = cred, |
| 4233 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4234 | struct rpc_task_setup task_setup_data = { |
| 4235 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4236 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4237 | .callback_ops = &nfs4_delegreturn_ops, |
| 4238 | .flags = RPC_TASK_ASYNC, |
| 4239 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4240 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4241 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4242 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4243 | if (data == NULL) |
| 4244 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4245 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4246 | data->args.fhandle = &data->fh; |
| 4247 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4248 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4249 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4250 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4251 | data->res.fattr = &data->fattr; |
| 4252 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4253 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4254 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4255 | data->rpc_status = 0; |
| 4256 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4257 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4258 | msg.rpc_argp = &data->args; |
| 4259 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4260 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4261 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4262 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4263 | if (!issync) |
| 4264 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4265 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4266 | if (status != 0) |
| 4267 | goto out; |
| 4268 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4269 | if (status == 0) |
| 4270 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4271 | else |
| 4272 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4273 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4274 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4275 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | } |
| 4277 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4278 | 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] | 4279 | { |
| 4280 | struct nfs_server *server = NFS_SERVER(inode); |
| 4281 | struct nfs4_exception exception = { }; |
| 4282 | int err; |
| 4283 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4284 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | switch (err) { |
| 4286 | case -NFS4ERR_STALE_STATEID: |
| 4287 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | case 0: |
| 4289 | return 0; |
| 4290 | } |
| 4291 | err = nfs4_handle_exception(server, err, &exception); |
| 4292 | } while (exception.retry); |
| 4293 | return err; |
| 4294 | } |
| 4295 | |
| 4296 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4297 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4298 | |
| 4299 | /* |
| 4300 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4301 | */ |
| 4302 | static unsigned long |
| 4303 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4304 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4305 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | timeout <<= 1; |
| 4307 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4308 | return NFS4_LOCK_MAXTIMEOUT; |
| 4309 | return timeout; |
| 4310 | } |
| 4311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4313 | { |
| 4314 | struct inode *inode = state->inode; |
| 4315 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4316 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4317 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4319 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4321 | struct nfs_lockt_res res = { |
| 4322 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | }; |
| 4324 | struct rpc_message msg = { |
| 4325 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4326 | .rpc_argp = &arg, |
| 4327 | .rpc_resp = &res, |
| 4328 | .rpc_cred = state->owner->so_cred, |
| 4329 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | struct nfs4_lock_state *lsp; |
| 4331 | int status; |
| 4332 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4333 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4334 | status = nfs4_set_lock_state(state, request); |
| 4335 | if (status != 0) |
| 4336 | goto out; |
| 4337 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4338 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4339 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4340 | 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] | 4341 | switch (status) { |
| 4342 | case 0: |
| 4343 | request->fl_type = F_UNLCK; |
| 4344 | break; |
| 4345 | case -NFS4ERR_DENIED: |
| 4346 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4348 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4349 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | return status; |
| 4351 | } |
| 4352 | |
| 4353 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4354 | { |
| 4355 | struct nfs4_exception exception = { }; |
| 4356 | int err; |
| 4357 | |
| 4358 | do { |
| 4359 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4360 | _nfs4_proc_getlk(state, cmd, request), |
| 4361 | &exception); |
| 4362 | } while (exception.retry); |
| 4363 | return err; |
| 4364 | } |
| 4365 | |
| 4366 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4367 | { |
| 4368 | int res = 0; |
| 4369 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4370 | case FL_POSIX: |
| 4371 | res = posix_lock_file_wait(file, fl); |
| 4372 | break; |
| 4373 | case FL_FLOCK: |
| 4374 | res = flock_lock_file_wait(file, fl); |
| 4375 | break; |
| 4376 | default: |
| 4377 | BUG(); |
| 4378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | return res; |
| 4380 | } |
| 4381 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4382 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4383 | struct nfs_locku_args arg; |
| 4384 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4385 | struct nfs4_lock_state *lsp; |
| 4386 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4387 | struct file_lock fl; |
| 4388 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4389 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4390 | }; |
| 4391 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4392 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4393 | struct nfs_open_context *ctx, |
| 4394 | struct nfs4_lock_state *lsp, |
| 4395 | struct nfs_seqid *seqid) |
| 4396 | { |
| 4397 | struct nfs4_unlockdata *p; |
| 4398 | struct inode *inode = lsp->ls_state->inode; |
| 4399 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4400 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4401 | if (p == NULL) |
| 4402 | return NULL; |
| 4403 | p->arg.fh = NFS_FH(inode); |
| 4404 | p->arg.fl = &p->fl; |
| 4405 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4406 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4407 | p->arg.stateid = &lsp->ls_stateid; |
| 4408 | p->lsp = lsp; |
| 4409 | atomic_inc(&lsp->ls_count); |
| 4410 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4411 | p->ctx = get_nfs_open_context(ctx); |
| 4412 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4413 | p->server = NFS_SERVER(inode); |
| 4414 | return p; |
| 4415 | } |
| 4416 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4417 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4418 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4419 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4420 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4421 | nfs4_put_lock_state(calldata->lsp); |
| 4422 | put_nfs_open_context(calldata->ctx); |
| 4423 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4424 | } |
| 4425 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4426 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4427 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4428 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4429 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4430 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4431 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4432 | switch (task->tk_status) { |
| 4433 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4434 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4435 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4436 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4437 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4438 | case -NFS4ERR_BAD_STATEID: |
| 4439 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4440 | case -NFS4ERR_STALE_STATEID: |
| 4441 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4442 | break; |
| 4443 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4444 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4445 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4446 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4447 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4450 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4451 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4452 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4454 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4455 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4456 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4457 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4458 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 4459 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4460 | return; |
| 4461 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4462 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4463 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4464 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4465 | &calldata->res.seq_res, |
| 4466 | task) != 0) |
| 4467 | nfs_release_seqid(calldata->arg.seqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4470 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4471 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4472 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4473 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4474 | }; |
| 4475 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4476 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4477 | struct nfs_open_context *ctx, |
| 4478 | struct nfs4_lock_state *lsp, |
| 4479 | struct nfs_seqid *seqid) |
| 4480 | { |
| 4481 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4482 | struct rpc_message msg = { |
| 4483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4484 | .rpc_cred = ctx->cred, |
| 4485 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4486 | struct rpc_task_setup task_setup_data = { |
| 4487 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4488 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4489 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4490 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4491 | .flags = RPC_TASK_ASYNC, |
| 4492 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4493 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4494 | /* Ensure this is an unlock - when canceling a lock, the |
| 4495 | * canceled lock is passed in, and it won't be an unlock. |
| 4496 | */ |
| 4497 | fl->fl_type = F_UNLCK; |
| 4498 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4499 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4500 | if (data == NULL) { |
| 4501 | nfs_free_seqid(seqid); |
| 4502 | return ERR_PTR(-ENOMEM); |
| 4503 | } |
| 4504 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4505 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4506 | msg.rpc_argp = &data->arg; |
| 4507 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4508 | task_setup_data.callback_data = data; |
| 4509 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4510 | } |
| 4511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4513 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4514 | struct inode *inode = state->inode; |
| 4515 | struct nfs4_state_owner *sp = state->owner; |
| 4516 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4517 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4518 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4519 | struct rpc_task *task; |
| 4520 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4521 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4523 | status = nfs4_set_lock_state(state, request); |
| 4524 | /* Unlock _before_ we do the RPC call */ |
| 4525 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4526 | /* Exclude nfs_delegation_claim_locks() */ |
| 4527 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4528 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4529 | down_read(&nfsi->rwsem); |
| 4530 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4531 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4532 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4533 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4534 | } |
| 4535 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4536 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4537 | if (status != 0) |
| 4538 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4539 | /* Is this a delegated lock? */ |
| 4540 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4541 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4542 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4543 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4544 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4545 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4546 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4547 | 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] | 4548 | status = PTR_ERR(task); |
| 4549 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4550 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4551 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4552 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4553 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4554 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4555 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4558 | struct nfs4_lockdata { |
| 4559 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4560 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4561 | struct nfs4_lock_state *lsp; |
| 4562 | struct nfs_open_context *ctx; |
| 4563 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4564 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4565 | int rpc_status; |
| 4566 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4567 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4568 | }; |
| 4569 | |
| 4570 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4571 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4572 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4573 | { |
| 4574 | struct nfs4_lockdata *p; |
| 4575 | struct inode *inode = lsp->ls_state->inode; |
| 4576 | struct nfs_server *server = NFS_SERVER(inode); |
| 4577 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4578 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4579 | if (p == NULL) |
| 4580 | return NULL; |
| 4581 | |
| 4582 | p->arg.fh = NFS_FH(inode); |
| 4583 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4584 | 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] | 4585 | if (p->arg.open_seqid == NULL) |
| 4586 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4587 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4588 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4589 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4590 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4591 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4592 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4593 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4594 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4595 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4596 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4597 | atomic_inc(&lsp->ls_count); |
| 4598 | p->ctx = get_nfs_open_context(ctx); |
| 4599 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4600 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4601 | out_free_seqid: |
| 4602 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4603 | out_free: |
| 4604 | kfree(p); |
| 4605 | return NULL; |
| 4606 | } |
| 4607 | |
| 4608 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4609 | { |
| 4610 | struct nfs4_lockdata *data = calldata; |
| 4611 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4613 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4614 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4615 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4616 | /* Do we need to do an open_to_lock_owner? */ |
| 4617 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4618 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4619 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4620 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4621 | data->arg.open_stateid = &state->stateid; |
| 4622 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4623 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4624 | } else |
| 4625 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4626 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4627 | if (nfs4_setup_sequence(data->server, |
| 4628 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4629 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4630 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4631 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4632 | nfs_release_seqid(data->arg.open_seqid); |
| 4633 | out_release_lock_seqid: |
| 4634 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4635 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4636 | } |
| 4637 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4638 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4639 | { |
| 4640 | struct nfs4_lockdata *data = calldata; |
| 4641 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4642 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4643 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4644 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4645 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4646 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4647 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4648 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4649 | if (data->rpc_status == 0) |
| 4650 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4651 | else |
| 4652 | goto out; |
| 4653 | } |
| 4654 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4655 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4656 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4657 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4658 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4659 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4660 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | static void nfs4_lock_release(void *calldata) |
| 4664 | { |
| 4665 | struct nfs4_lockdata *data = calldata; |
| 4666 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4667 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4668 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4669 | if (data->cancelled != 0) { |
| 4670 | struct rpc_task *task; |
| 4671 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4672 | data->arg.lock_seqid); |
| 4673 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4674 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4675 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4676 | } else |
| 4677 | nfs_free_seqid(data->arg.lock_seqid); |
| 4678 | nfs4_put_lock_state(data->lsp); |
| 4679 | put_nfs_open_context(data->ctx); |
| 4680 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4681 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4685 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4686 | .rpc_call_done = nfs4_lock_done, |
| 4687 | .rpc_release = nfs4_lock_release, |
| 4688 | }; |
| 4689 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4690 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4691 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4692 | switch (error) { |
| 4693 | case -NFS4ERR_ADMIN_REVOKED: |
| 4694 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4695 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4696 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4697 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4698 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4699 | break; |
| 4700 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4701 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4702 | case -NFS4ERR_EXPIRED: |
| 4703 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4704 | }; |
| 4705 | } |
| 4706 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4707 | 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] | 4708 | { |
| 4709 | struct nfs4_lockdata *data; |
| 4710 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4711 | struct rpc_message msg = { |
| 4712 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4713 | .rpc_cred = state->owner->so_cred, |
| 4714 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4715 | struct rpc_task_setup task_setup_data = { |
| 4716 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4717 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4718 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4719 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4720 | .flags = RPC_TASK_ASYNC, |
| 4721 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4722 | int ret; |
| 4723 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4724 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4725 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4726 | fl->fl_u.nfs4_fl.owner, |
| 4727 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4728 | if (data == NULL) |
| 4729 | return -ENOMEM; |
| 4730 | if (IS_SETLKW(cmd)) |
| 4731 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4732 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4733 | msg.rpc_argp = &data->arg; |
| 4734 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4735 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4736 | if (recovery_type > NFS_LOCK_NEW) { |
| 4737 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4738 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4739 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4740 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4741 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4742 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4743 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4744 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4745 | if (ret == 0) { |
| 4746 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4747 | if (ret) |
| 4748 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4749 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4750 | } else |
| 4751 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4752 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4753 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4754 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4758 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4759 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4760 | struct nfs4_exception exception = { |
| 4761 | .inode = state->inode, |
| 4762 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4763 | int err; |
| 4764 | |
| 4765 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4766 | /* Cache the lock if possible... */ |
| 4767 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4768 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4769 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4770 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4771 | break; |
| 4772 | nfs4_handle_exception(server, err, &exception); |
| 4773 | } while (exception.retry); |
| 4774 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4778 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4779 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4780 | struct nfs4_exception exception = { |
| 4781 | .inode = state->inode, |
| 4782 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4783 | int err; |
| 4784 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4785 | err = nfs4_set_lock_state(state, request); |
| 4786 | if (err != 0) |
| 4787 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4788 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4789 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4790 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4791 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4792 | switch (err) { |
| 4793 | default: |
| 4794 | goto out; |
| 4795 | case -NFS4ERR_GRACE: |
| 4796 | case -NFS4ERR_DELAY: |
| 4797 | nfs4_handle_exception(server, err, &exception); |
| 4798 | err = 0; |
| 4799 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4800 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4801 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4802 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | } |
| 4804 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4805 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4806 | /** |
| 4807 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4808 | * |
| 4809 | * @state: NFSv4 state for an inode |
| 4810 | * |
| 4811 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4812 | * Otherwise a negative NFS4ERR value is returned. |
| 4813 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4814 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4815 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4816 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4817 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4818 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4819 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4820 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4821 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4822 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4823 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4824 | /* Free the stateid unless the server |
| 4825 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4826 | if (status != -NFS4ERR_BAD_STATEID) |
| 4827 | nfs41_free_stateid(server, |
| 4828 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4829 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4830 | ret = status; |
| 4831 | } |
| 4832 | } |
| 4833 | }; |
| 4834 | |
| 4835 | return ret; |
| 4836 | } |
| 4837 | |
| 4838 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4839 | { |
| 4840 | int status = NFS_OK; |
| 4841 | |
| 4842 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4843 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4844 | if (status != NFS_OK) |
| 4845 | status = nfs4_lock_expired(state, request); |
| 4846 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4847 | } |
| 4848 | #endif |
| 4849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4851 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4852 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4853 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4854 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4855 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4856 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4858 | if ((fl_flags & FL_POSIX) && |
| 4859 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4860 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4861 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4862 | status = nfs4_set_lock_state(state, request); |
| 4863 | if (status != 0) |
| 4864 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4865 | request->fl_flags |= FL_ACCESS; |
| 4866 | status = do_vfs_lock(request->fl_file, request); |
| 4867 | if (status < 0) |
| 4868 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4869 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4870 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4871 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4872 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4873 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4874 | status = do_vfs_lock(request->fl_file, request); |
| 4875 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4876 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4877 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 4878 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4879 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4880 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4881 | goto out; |
| 4882 | down_read(&nfsi->rwsem); |
| 4883 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 4884 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4885 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4886 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4887 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4888 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4889 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4890 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4891 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4892 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4893 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4894 | out: |
| 4895 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | return status; |
| 4897 | } |
| 4898 | |
| 4899 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4900 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4901 | struct nfs4_exception exception = { |
| 4902 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4903 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4904 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | int err; |
| 4906 | |
| 4907 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4908 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4909 | if (err == -NFS4ERR_DENIED) |
| 4910 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4912 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | } while (exception.retry); |
| 4914 | return err; |
| 4915 | } |
| 4916 | |
| 4917 | static int |
| 4918 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4919 | { |
| 4920 | struct nfs_open_context *ctx; |
| 4921 | struct nfs4_state *state; |
| 4922 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4923 | int status; |
| 4924 | |
| 4925 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4926 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | state = ctx->state; |
| 4928 | |
| 4929 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4930 | return -EINVAL; |
| 4931 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4932 | if (IS_GETLK(cmd)) { |
| 4933 | if (state != NULL) |
| 4934 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4935 | return 0; |
| 4936 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | |
| 4938 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4939 | return -EINVAL; |
| 4940 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4941 | if (request->fl_type == F_UNLCK) { |
| 4942 | if (state != NULL) |
| 4943 | return nfs4_proc_unlck(state, cmd, request); |
| 4944 | return 0; |
| 4945 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4947 | if (state == NULL) |
| 4948 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4949 | /* |
| 4950 | * Don't rely on the VFS having checked the file open mode, |
| 4951 | * since it won't do this for flock() locks. |
| 4952 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4953 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4954 | case F_RDLCK: |
| 4955 | if (!(filp->f_mode & FMODE_READ)) |
| 4956 | return -EBADF; |
| 4957 | break; |
| 4958 | case F_WRLCK: |
| 4959 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4960 | return -EBADF; |
| 4961 | } |
| 4962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | do { |
| 4964 | status = nfs4_proc_setlk(state, cmd, request); |
| 4965 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4966 | break; |
| 4967 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4968 | status = -ERESTARTSYS; |
| 4969 | if (signalled()) |
| 4970 | break; |
| 4971 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | return status; |
| 4973 | } |
| 4974 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4975 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4976 | { |
| 4977 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4978 | struct nfs4_exception exception = { }; |
| 4979 | int err; |
| 4980 | |
| 4981 | err = nfs4_set_lock_state(state, fl); |
| 4982 | if (err != 0) |
| 4983 | goto out; |
| 4984 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4985 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4986 | switch (err) { |
| 4987 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4988 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4989 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4990 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4991 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4992 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4993 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4994 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 4995 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 4996 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4997 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 4998 | err = -EAGAIN; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4999 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5000 | case -NFS4ERR_BADSESSION: |
| 5001 | case -NFS4ERR_BADSLOT: |
| 5002 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5003 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5004 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5005 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5006 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5007 | err = -EAGAIN; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5008 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5009 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5010 | case -NFS4ERR_ADMIN_REVOKED: |
| 5011 | case -NFS4ERR_BAD_STATEID: |
| 5012 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5013 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5014 | err = 0; |
| 5015 | goto out; |
| 5016 | case -ENOMEM: |
| 5017 | case -NFS4ERR_DENIED: |
| 5018 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5019 | err = 0; |
| 5020 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5021 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5022 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5023 | err = nfs4_handle_exception(server, err, &exception); |
| 5024 | } while (exception.retry); |
| 5025 | out: |
| 5026 | return err; |
| 5027 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5028 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5029 | struct nfs_release_lockowner_data { |
| 5030 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5031 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5032 | struct nfs_release_lockowner_args args; |
| 5033 | }; |
| 5034 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5035 | static void nfs4_release_lockowner_release(void *calldata) |
| 5036 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5037 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5038 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5039 | kfree(calldata); |
| 5040 | } |
| 5041 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5042 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5043 | .rpc_release = nfs4_release_lockowner_release, |
| 5044 | }; |
| 5045 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5046 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5047 | { |
| 5048 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5049 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5050 | struct rpc_message msg = { |
| 5051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5052 | }; |
| 5053 | |
| 5054 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5055 | return -EINVAL; |
| 5056 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5057 | if (!data) |
| 5058 | return -ENOMEM; |
| 5059 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5060 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5061 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5062 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5063 | data->args.lock_owner.s_dev = server->s_dev; |
| 5064 | msg.rpc_argp = &data->args; |
| 5065 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5066 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5067 | } |
| 5068 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5069 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5070 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5071 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5072 | const void *buf, size_t buflen, |
| 5073 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5074 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5075 | if (strcmp(key, "") != 0) |
| 5076 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5077 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5078 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5081 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5082 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5083 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5084 | if (strcmp(key, "") != 0) |
| 5085 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5086 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5087 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5088 | } |
| 5089 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5090 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5091 | size_t list_len, const char *name, |
| 5092 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5093 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5094 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5095 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5096 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5097 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5098 | |
| 5099 | if (list && len <= list_len) |
| 5100 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5101 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5104 | /* |
| 5105 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5106 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5107 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5108 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5109 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5110 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5111 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5112 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5113 | return; |
| 5114 | |
| 5115 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5116 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5117 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5118 | fattr->nlink = 2; |
| 5119 | } |
| 5120 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5121 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5122 | const struct qstr *name, |
| 5123 | struct nfs4_fs_locations *fs_locations, |
| 5124 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5125 | { |
| 5126 | struct nfs_server *server = NFS_SERVER(dir); |
| 5127 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5128 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5129 | }; |
| 5130 | struct nfs4_fs_locations_arg args = { |
| 5131 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5132 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5133 | .page = page, |
| 5134 | .bitmask = bitmask, |
| 5135 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5136 | struct nfs4_fs_locations_res res = { |
| 5137 | .fs_locations = fs_locations, |
| 5138 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5139 | struct rpc_message msg = { |
| 5140 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5141 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5142 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5143 | }; |
| 5144 | int status; |
| 5145 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5146 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5147 | |
| 5148 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5149 | * is not supported */ |
| 5150 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5151 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5152 | else |
| 5153 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5154 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5155 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5156 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5157 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5158 | 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] | 5159 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5160 | return status; |
| 5161 | } |
| 5162 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5163 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5164 | const struct qstr *name, |
| 5165 | struct nfs4_fs_locations *fs_locations, |
| 5166 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5167 | { |
| 5168 | struct nfs4_exception exception = { }; |
| 5169 | int err; |
| 5170 | do { |
| 5171 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5172 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5173 | &exception); |
| 5174 | } while (exception.retry); |
| 5175 | return err; |
| 5176 | } |
| 5177 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5178 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5179 | { |
| 5180 | int status; |
| 5181 | struct nfs4_secinfo_arg args = { |
| 5182 | .dir_fh = NFS_FH(dir), |
| 5183 | .name = name, |
| 5184 | }; |
| 5185 | struct nfs4_secinfo_res res = { |
| 5186 | .flavors = flavors, |
| 5187 | }; |
| 5188 | struct rpc_message msg = { |
| 5189 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5190 | .rpc_argp = &args, |
| 5191 | .rpc_resp = &res, |
| 5192 | }; |
| 5193 | |
| 5194 | dprintk("NFS call secinfo %s\n", name->name); |
| 5195 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5196 | dprintk("NFS reply secinfo: %d\n", status); |
| 5197 | return status; |
| 5198 | } |
| 5199 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5200 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5201 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5202 | { |
| 5203 | struct nfs4_exception exception = { }; |
| 5204 | int err; |
| 5205 | do { |
| 5206 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5207 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5208 | &exception); |
| 5209 | } while (exception.retry); |
| 5210 | return err; |
| 5211 | } |
| 5212 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5213 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5214 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5215 | * Check the exchange flags returned by the server for invalid flags, having |
| 5216 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5217 | * DS flags set. |
| 5218 | */ |
| 5219 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5220 | { |
| 5221 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5222 | goto out_inval; |
| 5223 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5224 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5225 | goto out_inval; |
| 5226 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5227 | goto out_inval; |
| 5228 | return NFS_OK; |
| 5229 | out_inval: |
| 5230 | return -NFS4ERR_INVAL; |
| 5231 | } |
| 5232 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5233 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5234 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5235 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5236 | { |
| 5237 | if (a->server_scope_sz == b->server_scope_sz && |
| 5238 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5239 | return true; |
| 5240 | |
| 5241 | return false; |
| 5242 | } |
| 5243 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5244 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5245 | * nfs4_proc_bind_conn_to_session() |
| 5246 | * |
| 5247 | * The 4.1 client currently uses the same TCP connection for the |
| 5248 | * fore and backchannel. |
| 5249 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5250 | 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] | 5251 | { |
| 5252 | int status; |
| 5253 | struct nfs41_bind_conn_to_session_res res; |
| 5254 | struct rpc_message msg = { |
| 5255 | .rpc_proc = |
| 5256 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5257 | .rpc_argp = clp, |
| 5258 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5259 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5260 | }; |
| 5261 | |
| 5262 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5263 | |
| 5264 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5265 | if (unlikely(res.session == NULL)) { |
| 5266 | status = -ENOMEM; |
| 5267 | goto out; |
| 5268 | } |
| 5269 | |
| 5270 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5271 | if (status == 0) { |
| 5272 | if (memcmp(res.session->sess_id.data, |
| 5273 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5274 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5275 | status = -EIO; |
| 5276 | goto out_session; |
| 5277 | } |
| 5278 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5279 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5280 | __func__); |
| 5281 | status = -EIO; |
| 5282 | goto out_session; |
| 5283 | } |
| 5284 | if (res.use_conn_in_rdma_mode) { |
| 5285 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5286 | __func__); |
| 5287 | status = -EIO; |
| 5288 | goto out_session; |
| 5289 | } |
| 5290 | } |
| 5291 | out_session: |
| 5292 | kfree(res.session); |
| 5293 | out: |
| 5294 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5295 | return status; |
| 5296 | } |
| 5297 | |
| 5298 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5299 | * nfs4_proc_exchange_id() |
| 5300 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5301 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5302 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5303 | * Since the clientid has expired, all compounds using sessions |
| 5304 | * associated with the stale clientid will be returning |
| 5305 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5306 | * be in some phase of session reset. |
| 5307 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5308 | 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] | 5309 | { |
| 5310 | nfs4_verifier verifier; |
| 5311 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5312 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5313 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5314 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5315 | }; |
| 5316 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5317 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5318 | }; |
| 5319 | int status; |
| 5320 | struct rpc_message msg = { |
| 5321 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5322 | .rpc_argp = &args, |
| 5323 | .rpc_resp = &res, |
| 5324 | .rpc_cred = cred, |
| 5325 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5326 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5327 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5328 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5329 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5330 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5331 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5332 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5333 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5334 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5335 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5336 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5337 | status = -ENOMEM; |
| 5338 | goto out; |
| 5339 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5340 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5341 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5342 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5343 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5344 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5345 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5346 | } |
| 5347 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5348 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5349 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5350 | status = -ENOMEM; |
| 5351 | goto out_server_scope; |
| 5352 | } |
| 5353 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5354 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5355 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5356 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5357 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5358 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5359 | clp->cl_clientid = res.clientid; |
| 5360 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5361 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5362 | clp->cl_seqid = res.seqid; |
| 5363 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5364 | kfree(clp->cl_serverowner); |
| 5365 | clp->cl_serverowner = res.server_owner; |
| 5366 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5367 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5368 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5369 | kfree(clp->cl_implid); |
| 5370 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5371 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5372 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5373 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5374 | res.server_scope)) { |
| 5375 | dprintk("%s: server_scope mismatch detected\n", |
| 5376 | __func__); |
| 5377 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5378 | kfree(clp->cl_serverscope); |
| 5379 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5380 | } |
| 5381 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5382 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5383 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5384 | goto out; |
| 5385 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5386 | } else |
| 5387 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5388 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5389 | out_server_owner: |
| 5390 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5391 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5392 | kfree(res.server_scope); |
| 5393 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5394 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5395 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5396 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5397 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5398 | clp->cl_implid->date.seconds, |
| 5399 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5400 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5401 | return status; |
| 5402 | } |
| 5403 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5404 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5405 | struct rpc_cred *cred) |
| 5406 | { |
| 5407 | struct rpc_message msg = { |
| 5408 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5409 | .rpc_argp = clp, |
| 5410 | .rpc_cred = cred, |
| 5411 | }; |
| 5412 | int status; |
| 5413 | |
| 5414 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5415 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5416 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5417 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5418 | return status; |
| 5419 | } |
| 5420 | |
| 5421 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5422 | struct rpc_cred *cred) |
| 5423 | { |
| 5424 | unsigned int loop; |
| 5425 | int ret; |
| 5426 | |
| 5427 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5428 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5429 | switch (ret) { |
| 5430 | case -NFS4ERR_DELAY: |
| 5431 | case -NFS4ERR_CLIENTID_BUSY: |
| 5432 | ssleep(1); |
| 5433 | break; |
| 5434 | default: |
| 5435 | return ret; |
| 5436 | } |
| 5437 | } |
| 5438 | return 0; |
| 5439 | } |
| 5440 | |
| 5441 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5442 | { |
| 5443 | struct rpc_cred *cred; |
| 5444 | int ret = 0; |
| 5445 | |
| 5446 | if (clp->cl_mvops->minor_version < 1) |
| 5447 | goto out; |
| 5448 | if (clp->cl_exchange_flags == 0) |
| 5449 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5450 | if (clp->cl_preserve_clid) |
| 5451 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5452 | cred = nfs4_get_exchange_id_cred(clp); |
| 5453 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5454 | if (cred) |
| 5455 | put_rpccred(cred); |
| 5456 | switch (ret) { |
| 5457 | case 0: |
| 5458 | case -NFS4ERR_STALE_CLIENTID: |
| 5459 | clp->cl_exchange_flags = 0; |
| 5460 | } |
| 5461 | out: |
| 5462 | return ret; |
| 5463 | } |
| 5464 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5465 | struct nfs4_get_lease_time_data { |
| 5466 | struct nfs4_get_lease_time_args *args; |
| 5467 | struct nfs4_get_lease_time_res *res; |
| 5468 | struct nfs_client *clp; |
| 5469 | }; |
| 5470 | |
| 5471 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5472 | void *calldata) |
| 5473 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5474 | struct nfs4_get_lease_time_data *data = |
| 5475 | (struct nfs4_get_lease_time_data *)calldata; |
| 5476 | |
| 5477 | dprintk("--> %s\n", __func__); |
| 5478 | /* just setup sequence, do not trigger session recovery |
| 5479 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5480 | nfs41_setup_sequence(data->clp->cl_session, |
| 5481 | &data->args->la_seq_args, |
| 5482 | &data->res->lr_seq_res, |
| 5483 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5484 | dprintk("<-- %s\n", __func__); |
| 5485 | } |
| 5486 | |
| 5487 | /* |
| 5488 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5489 | * from sequence operation or clientid errors. |
| 5490 | */ |
| 5491 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5492 | { |
| 5493 | struct nfs4_get_lease_time_data *data = |
| 5494 | (struct nfs4_get_lease_time_data *)calldata; |
| 5495 | |
| 5496 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5497 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5498 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5499 | switch (task->tk_status) { |
| 5500 | case -NFS4ERR_DELAY: |
| 5501 | case -NFS4ERR_GRACE: |
| 5502 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5503 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5504 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5505 | /* fall through */ |
| 5506 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5507 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5508 | return; |
| 5509 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5510 | dprintk("<-- %s\n", __func__); |
| 5511 | } |
| 5512 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5513 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5514 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5515 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5516 | }; |
| 5517 | |
| 5518 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5519 | { |
| 5520 | struct rpc_task *task; |
| 5521 | struct nfs4_get_lease_time_args args; |
| 5522 | struct nfs4_get_lease_time_res res = { |
| 5523 | .lr_fsinfo = fsinfo, |
| 5524 | }; |
| 5525 | struct nfs4_get_lease_time_data data = { |
| 5526 | .args = &args, |
| 5527 | .res = &res, |
| 5528 | .clp = clp, |
| 5529 | }; |
| 5530 | struct rpc_message msg = { |
| 5531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5532 | .rpc_argp = &args, |
| 5533 | .rpc_resp = &res, |
| 5534 | }; |
| 5535 | struct rpc_task_setup task_setup = { |
| 5536 | .rpc_client = clp->cl_rpcclient, |
| 5537 | .rpc_message = &msg, |
| 5538 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5539 | .callback_data = &data, |
| 5540 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5541 | }; |
| 5542 | int status; |
| 5543 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5544 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5545 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5546 | dprintk("--> %s\n", __func__); |
| 5547 | task = rpc_run_task(&task_setup); |
| 5548 | |
| 5549 | if (IS_ERR(task)) |
| 5550 | status = PTR_ERR(task); |
| 5551 | else { |
| 5552 | status = task->tk_status; |
| 5553 | rpc_put_task(task); |
| 5554 | } |
| 5555 | dprintk("<-- %s return %d\n", __func__, status); |
| 5556 | |
| 5557 | return status; |
| 5558 | } |
| 5559 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5560 | /* |
| 5561 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5562 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5563 | * use them. |
| 5564 | * |
| 5565 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5566 | * always set csa_cachethis to FALSE because the current implementation |
| 5567 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5568 | */ |
| 5569 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5570 | { |
| 5571 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5572 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5573 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5574 | |
| 5575 | if (mxrqst_sz == 0) |
| 5576 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5577 | if (mxresp_sz == 0) |
| 5578 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5579 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5580 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5581 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5582 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5583 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5584 | |
| 5585 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5586 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5587 | __func__, |
| 5588 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5589 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5590 | |
| 5591 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5592 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5593 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5594 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5595 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5596 | args->bc_attrs.max_reqs = 1; |
| 5597 | |
| 5598 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5599 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5600 | __func__, |
| 5601 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5602 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5603 | args->bc_attrs.max_reqs); |
| 5604 | } |
| 5605 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5606 | 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] | 5607 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5608 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5609 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5610 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5611 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5612 | return -EINVAL; |
| 5613 | /* |
| 5614 | * Our requested max_ops is the minimum we need; we're not |
| 5615 | * prepared to break up compounds into smaller pieces than that. |
| 5616 | * So, no point even trying to continue if the server won't |
| 5617 | * cooperate: |
| 5618 | */ |
| 5619 | if (rcvd->max_ops < sent->max_ops) |
| 5620 | return -EINVAL; |
| 5621 | if (rcvd->max_reqs == 0) |
| 5622 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5623 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5624 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5625 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5626 | } |
| 5627 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5628 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5629 | { |
| 5630 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5631 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5632 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5633 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5634 | return -EINVAL; |
| 5635 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5636 | return -EINVAL; |
| 5637 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5638 | return -EINVAL; |
| 5639 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5640 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5641 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5642 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5643 | return -EINVAL; |
| 5644 | return 0; |
| 5645 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5646 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5647 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5648 | struct nfs4_session *session) |
| 5649 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5650 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5651 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5652 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5653 | if (ret) |
| 5654 | return ret; |
| 5655 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5656 | } |
| 5657 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5658 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5659 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5660 | { |
| 5661 | struct nfs4_session *session = clp->cl_session; |
| 5662 | struct nfs41_create_session_args args = { |
| 5663 | .client = clp, |
| 5664 | .cb_program = NFS4_CALLBACK, |
| 5665 | }; |
| 5666 | struct nfs41_create_session_res res = { |
| 5667 | .client = clp, |
| 5668 | }; |
| 5669 | struct rpc_message msg = { |
| 5670 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5671 | .rpc_argp = &args, |
| 5672 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5673 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5674 | }; |
| 5675 | int status; |
| 5676 | |
| 5677 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5678 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5679 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5680 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5681 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5682 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5683 | /* Verify the session's negotiated channel_attrs values */ |
| 5684 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5685 | /* Increment the clientid slot sequence id */ |
| 5686 | clp->cl_seqid++; |
| 5687 | } |
| 5688 | |
| 5689 | return status; |
| 5690 | } |
| 5691 | |
| 5692 | /* |
| 5693 | * Issues a CREATE_SESSION operation to the server. |
| 5694 | * It is the responsibility of the caller to verify the session is |
| 5695 | * expired before calling this routine. |
| 5696 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5697 | 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] | 5698 | { |
| 5699 | int status; |
| 5700 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5701 | struct nfs4_session *session = clp->cl_session; |
| 5702 | |
| 5703 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5704 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5705 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5706 | if (status) |
| 5707 | goto out; |
| 5708 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5709 | /* Init or reset the session slot tables */ |
| 5710 | status = nfs4_setup_session_slot_tables(session); |
| 5711 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5712 | if (status) |
| 5713 | goto out; |
| 5714 | |
| 5715 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5716 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5717 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5718 | out: |
| 5719 | dprintk("<-- %s\n", __func__); |
| 5720 | return status; |
| 5721 | } |
| 5722 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5723 | /* |
| 5724 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5725 | * The caller must serialize access to this routine. |
| 5726 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5727 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5728 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5729 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5730 | struct rpc_message msg = { |
| 5731 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5732 | .rpc_argp = session, |
| 5733 | .rpc_cred = cred, |
| 5734 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5735 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5736 | |
| 5737 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5738 | |
| 5739 | /* session is still being setup */ |
| 5740 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5741 | return status; |
| 5742 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5743 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5744 | |
| 5745 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5746 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5747 | "Session has been destroyed regardless...\n", status); |
| 5748 | |
| 5749 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5750 | return status; |
| 5751 | } |
| 5752 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5753 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5754 | * Renew the cl_session lease. |
| 5755 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5756 | struct nfs4_sequence_data { |
| 5757 | struct nfs_client *clp; |
| 5758 | struct nfs4_sequence_args args; |
| 5759 | struct nfs4_sequence_res res; |
| 5760 | }; |
| 5761 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5762 | static void nfs41_sequence_release(void *data) |
| 5763 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5764 | struct nfs4_sequence_data *calldata = data; |
| 5765 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5766 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5767 | if (atomic_read(&clp->cl_count) > 1) |
| 5768 | nfs4_schedule_state_renewal(clp); |
| 5769 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5770 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5771 | } |
| 5772 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5773 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5774 | { |
| 5775 | switch(task->tk_status) { |
| 5776 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5777 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5778 | return -EAGAIN; |
| 5779 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5780 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5781 | } |
| 5782 | return 0; |
| 5783 | } |
| 5784 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5785 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5786 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5787 | struct nfs4_sequence_data *calldata = data; |
| 5788 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5789 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5790 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5791 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5792 | |
| 5793 | if (task->tk_status < 0) { |
| 5794 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5795 | if (atomic_read(&clp->cl_count) == 1) |
| 5796 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5797 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5798 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5799 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5800 | return; |
| 5801 | } |
| 5802 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5803 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5804 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5805 | dprintk("<-- %s\n", __func__); |
| 5806 | } |
| 5807 | |
| 5808 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5809 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5810 | struct nfs4_sequence_data *calldata = data; |
| 5811 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5812 | struct nfs4_sequence_args *args; |
| 5813 | struct nfs4_sequence_res *res; |
| 5814 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5815 | args = task->tk_msg.rpc_argp; |
| 5816 | res = task->tk_msg.rpc_resp; |
| 5817 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5818 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5822 | .rpc_call_done = nfs41_sequence_call_done, |
| 5823 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5824 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5825 | }; |
| 5826 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5827 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5828 | struct rpc_cred *cred, |
| 5829 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5830 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5831 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5832 | struct rpc_message msg = { |
| 5833 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5834 | .rpc_cred = cred, |
| 5835 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5836 | struct rpc_task_setup task_setup_data = { |
| 5837 | .rpc_client = clp->cl_rpcclient, |
| 5838 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5839 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5840 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5841 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5842 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5843 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5844 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5845 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5846 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5847 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5848 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5849 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5850 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5851 | if (is_privileged) |
| 5852 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5853 | msg.rpc_argp = &calldata->args; |
| 5854 | msg.rpc_resp = &calldata->res; |
| 5855 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5856 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5857 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5858 | return rpc_run_task(&task_setup_data); |
| 5859 | } |
| 5860 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5861 | 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] | 5862 | { |
| 5863 | struct rpc_task *task; |
| 5864 | int ret = 0; |
| 5865 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5866 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5867 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5868 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5869 | if (IS_ERR(task)) |
| 5870 | ret = PTR_ERR(task); |
| 5871 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5872 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5873 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5874 | return ret; |
| 5875 | } |
| 5876 | |
| 5877 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5878 | { |
| 5879 | struct rpc_task *task; |
| 5880 | int ret; |
| 5881 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5882 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5883 | if (IS_ERR(task)) { |
| 5884 | ret = PTR_ERR(task); |
| 5885 | goto out; |
| 5886 | } |
| 5887 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5888 | if (!ret) { |
| 5889 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5890 | |
| 5891 | if (task->tk_status == 0) |
| 5892 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5893 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5894 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5895 | rpc_put_task(task); |
| 5896 | out: |
| 5897 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5898 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5899 | } |
| 5900 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5901 | struct nfs4_reclaim_complete_data { |
| 5902 | struct nfs_client *clp; |
| 5903 | struct nfs41_reclaim_complete_args arg; |
| 5904 | struct nfs41_reclaim_complete_res res; |
| 5905 | }; |
| 5906 | |
| 5907 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5908 | { |
| 5909 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5910 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5911 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 5912 | &calldata->arg.seq_args, |
| 5913 | &calldata->res.seq_res, |
| 5914 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5915 | } |
| 5916 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5917 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5918 | { |
| 5919 | switch(task->tk_status) { |
| 5920 | case 0: |
| 5921 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5922 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5923 | break; |
| 5924 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5925 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5926 | /* fall through */ |
| 5927 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5928 | return -EAGAIN; |
| 5929 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5930 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5931 | } |
| 5932 | return 0; |
| 5933 | } |
| 5934 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5935 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5936 | { |
| 5937 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5938 | struct nfs_client *clp = calldata->clp; |
| 5939 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5940 | |
| 5941 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5942 | if (!nfs41_sequence_done(task, res)) |
| 5943 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5944 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5945 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5946 | rpc_restart_call_prepare(task); |
| 5947 | return; |
| 5948 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5949 | dprintk("<-- %s\n", __func__); |
| 5950 | } |
| 5951 | |
| 5952 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5953 | { |
| 5954 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5955 | |
| 5956 | kfree(calldata); |
| 5957 | } |
| 5958 | |
| 5959 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5960 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5961 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5962 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5963 | }; |
| 5964 | |
| 5965 | /* |
| 5966 | * Issue a global reclaim complete. |
| 5967 | */ |
| 5968 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5969 | { |
| 5970 | struct nfs4_reclaim_complete_data *calldata; |
| 5971 | struct rpc_task *task; |
| 5972 | struct rpc_message msg = { |
| 5973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5974 | }; |
| 5975 | struct rpc_task_setup task_setup_data = { |
| 5976 | .rpc_client = clp->cl_rpcclient, |
| 5977 | .rpc_message = &msg, |
| 5978 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5979 | .flags = RPC_TASK_ASYNC, |
| 5980 | }; |
| 5981 | int status = -ENOMEM; |
| 5982 | |
| 5983 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5984 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5985 | if (calldata == NULL) |
| 5986 | goto out; |
| 5987 | calldata->clp = clp; |
| 5988 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5989 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5990 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5991 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5992 | msg.rpc_argp = &calldata->arg; |
| 5993 | msg.rpc_resp = &calldata->res; |
| 5994 | task_setup_data.callback_data = calldata; |
| 5995 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5996 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5997 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5998 | goto out; |
| 5999 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6000 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6001 | if (status == 0) |
| 6002 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6003 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6004 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6005 | out: |
| 6006 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6007 | return status; |
| 6008 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6009 | |
| 6010 | static void |
| 6011 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6012 | { |
| 6013 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6014 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6015 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6016 | |
| 6017 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6018 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6019 | * right now covering the LAYOUTGET we are about to send. |
| 6020 | * However, that is not so catastrophic, and there seems |
| 6021 | * to be no way to prevent it completely. |
| 6022 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6023 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6024 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6025 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6026 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6027 | NFS_I(lgp->args.inode)->layout, |
| 6028 | lgp->args.ctx->state)) { |
| 6029 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6030 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6034 | { |
| 6035 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6036 | struct inode *inode = lgp->args.inode; |
| 6037 | struct nfs_server *server = NFS_SERVER(inode); |
| 6038 | struct pnfs_layout_hdr *lo; |
| 6039 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6040 | |
| 6041 | dprintk("--> %s\n", __func__); |
| 6042 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6043 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6044 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6045 | |
| 6046 | switch (task->tk_status) { |
| 6047 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6048 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6049 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6050 | case -NFS4ERR_RECALLCONFLICT: |
| 6051 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6052 | break; |
| 6053 | case -NFS4ERR_EXPIRED: |
| 6054 | case -NFS4ERR_BAD_STATEID: |
| 6055 | spin_lock(&inode->i_lock); |
| 6056 | lo = NFS_I(inode)->layout; |
| 6057 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6058 | spin_unlock(&inode->i_lock); |
| 6059 | /* If the open stateid was bad, then recover it. */ |
| 6060 | state = lgp->args.ctx->state; |
| 6061 | } else { |
| 6062 | LIST_HEAD(head); |
| 6063 | |
| 6064 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6065 | spin_unlock(&inode->i_lock); |
| 6066 | /* Mark the bad layout state as invalid, then |
| 6067 | * retry using the open stateid. */ |
| 6068 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6069 | } |
| 6070 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6071 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6072 | rpc_restart_call_prepare(task); |
| 6073 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6074 | dprintk("<-- %s\n", __func__); |
| 6075 | } |
| 6076 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6077 | static size_t max_response_pages(struct nfs_server *server) |
| 6078 | { |
| 6079 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6080 | return nfs_page_array_len(0, max_resp_sz); |
| 6081 | } |
| 6082 | |
| 6083 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6084 | { |
| 6085 | int i; |
| 6086 | |
| 6087 | if (!pages) |
| 6088 | return; |
| 6089 | |
| 6090 | for (i = 0; i < size; i++) { |
| 6091 | if (!pages[i]) |
| 6092 | break; |
| 6093 | __free_page(pages[i]); |
| 6094 | } |
| 6095 | kfree(pages); |
| 6096 | } |
| 6097 | |
| 6098 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6099 | { |
| 6100 | struct page **pages; |
| 6101 | int i; |
| 6102 | |
| 6103 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6104 | if (!pages) { |
| 6105 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6106 | return NULL; |
| 6107 | } |
| 6108 | |
| 6109 | for (i = 0; i < size; i++) { |
| 6110 | pages[i] = alloc_page(gfp_flags); |
| 6111 | if (!pages[i]) { |
| 6112 | dprintk("%s: failed to allocate page\n", __func__); |
| 6113 | nfs4_free_pages(pages, size); |
| 6114 | return NULL; |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | return pages; |
| 6119 | } |
| 6120 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6121 | static void nfs4_layoutget_release(void *calldata) |
| 6122 | { |
| 6123 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6124 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6125 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6126 | |
| 6127 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6128 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6129 | put_nfs_open_context(lgp->args.ctx); |
| 6130 | kfree(calldata); |
| 6131 | dprintk("<-- %s\n", __func__); |
| 6132 | } |
| 6133 | |
| 6134 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6135 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6136 | .rpc_call_done = nfs4_layoutget_done, |
| 6137 | .rpc_release = nfs4_layoutget_release, |
| 6138 | }; |
| 6139 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6140 | struct pnfs_layout_segment * |
| 6141 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6142 | { |
| 6143 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6144 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6145 | struct rpc_task *task; |
| 6146 | struct rpc_message msg = { |
| 6147 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6148 | .rpc_argp = &lgp->args, |
| 6149 | .rpc_resp = &lgp->res, |
| 6150 | }; |
| 6151 | struct rpc_task_setup task_setup_data = { |
| 6152 | .rpc_client = server->client, |
| 6153 | .rpc_message = &msg, |
| 6154 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6155 | .callback_data = lgp, |
| 6156 | .flags = RPC_TASK_ASYNC, |
| 6157 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6158 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6159 | int status = 0; |
| 6160 | |
| 6161 | dprintk("--> %s\n", __func__); |
| 6162 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6163 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6164 | if (!lgp->args.layout.pages) { |
| 6165 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6166 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6167 | } |
| 6168 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6169 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6170 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6171 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6172 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6173 | task = rpc_run_task(&task_setup_data); |
| 6174 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6175 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6176 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6177 | if (status == 0) |
| 6178 | status = task->tk_status; |
| 6179 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6180 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6181 | rpc_put_task(task); |
| 6182 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6183 | if (status) |
| 6184 | return ERR_PTR(status); |
| 6185 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6186 | } |
| 6187 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6188 | static void |
| 6189 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6190 | { |
| 6191 | struct nfs4_layoutreturn *lrp = calldata; |
| 6192 | |
| 6193 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6194 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6195 | &lrp->args.seq_args, |
| 6196 | &lrp->res.seq_res, |
| 6197 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6198 | } |
| 6199 | |
| 6200 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6201 | { |
| 6202 | struct nfs4_layoutreturn *lrp = calldata; |
| 6203 | struct nfs_server *server; |
| 6204 | |
| 6205 | dprintk("--> %s\n", __func__); |
| 6206 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6207 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6208 | return; |
| 6209 | |
| 6210 | server = NFS_SERVER(lrp->args.inode); |
| 6211 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6212 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6213 | return; |
| 6214 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6215 | dprintk("<-- %s\n", __func__); |
| 6216 | } |
| 6217 | |
| 6218 | static void nfs4_layoutreturn_release(void *calldata) |
| 6219 | { |
| 6220 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6221 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6222 | |
| 6223 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6224 | spin_lock(&lo->plh_inode->i_lock); |
| 6225 | if (lrp->res.lrs_present) |
| 6226 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6227 | lo->plh_block_lgets--; |
| 6228 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6229 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6230 | kfree(calldata); |
| 6231 | dprintk("<-- %s\n", __func__); |
| 6232 | } |
| 6233 | |
| 6234 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6235 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6236 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6237 | .rpc_release = nfs4_layoutreturn_release, |
| 6238 | }; |
| 6239 | |
| 6240 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6241 | { |
| 6242 | struct rpc_task *task; |
| 6243 | struct rpc_message msg = { |
| 6244 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6245 | .rpc_argp = &lrp->args, |
| 6246 | .rpc_resp = &lrp->res, |
| 6247 | }; |
| 6248 | struct rpc_task_setup task_setup_data = { |
| 6249 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6250 | .rpc_message = &msg, |
| 6251 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6252 | .callback_data = lrp, |
| 6253 | }; |
| 6254 | int status; |
| 6255 | |
| 6256 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6257 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6258 | task = rpc_run_task(&task_setup_data); |
| 6259 | if (IS_ERR(task)) |
| 6260 | return PTR_ERR(task); |
| 6261 | status = task->tk_status; |
| 6262 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6263 | rpc_put_task(task); |
| 6264 | return status; |
| 6265 | } |
| 6266 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6267 | /* |
| 6268 | * Retrieve the list of Data Server devices from the MDS. |
| 6269 | */ |
| 6270 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6271 | const struct nfs_fh *fh, |
| 6272 | struct pnfs_devicelist *devlist) |
| 6273 | { |
| 6274 | struct nfs4_getdevicelist_args args = { |
| 6275 | .fh = fh, |
| 6276 | .layoutclass = server->pnfs_curr_ld->id, |
| 6277 | }; |
| 6278 | struct nfs4_getdevicelist_res res = { |
| 6279 | .devlist = devlist, |
| 6280 | }; |
| 6281 | struct rpc_message msg = { |
| 6282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6283 | .rpc_argp = &args, |
| 6284 | .rpc_resp = &res, |
| 6285 | }; |
| 6286 | int status; |
| 6287 | |
| 6288 | dprintk("--> %s\n", __func__); |
| 6289 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6290 | &res.seq_res, 0); |
| 6291 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6292 | return status; |
| 6293 | } |
| 6294 | |
| 6295 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6296 | const struct nfs_fh *fh, |
| 6297 | struct pnfs_devicelist *devlist) |
| 6298 | { |
| 6299 | struct nfs4_exception exception = { }; |
| 6300 | int err; |
| 6301 | |
| 6302 | do { |
| 6303 | err = nfs4_handle_exception(server, |
| 6304 | _nfs4_getdevicelist(server, fh, devlist), |
| 6305 | &exception); |
| 6306 | } while (exception.retry); |
| 6307 | |
| 6308 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6309 | err, devlist->num_devs); |
| 6310 | |
| 6311 | return err; |
| 6312 | } |
| 6313 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6314 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6315 | static int |
| 6316 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6317 | { |
| 6318 | struct nfs4_getdeviceinfo_args args = { |
| 6319 | .pdev = pdev, |
| 6320 | }; |
| 6321 | struct nfs4_getdeviceinfo_res res = { |
| 6322 | .pdev = pdev, |
| 6323 | }; |
| 6324 | struct rpc_message msg = { |
| 6325 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6326 | .rpc_argp = &args, |
| 6327 | .rpc_resp = &res, |
| 6328 | }; |
| 6329 | int status; |
| 6330 | |
| 6331 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6332 | 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] | 6333 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6334 | |
| 6335 | return status; |
| 6336 | } |
| 6337 | |
| 6338 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6339 | { |
| 6340 | struct nfs4_exception exception = { }; |
| 6341 | int err; |
| 6342 | |
| 6343 | do { |
| 6344 | err = nfs4_handle_exception(server, |
| 6345 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6346 | &exception); |
| 6347 | } while (exception.retry); |
| 6348 | return err; |
| 6349 | } |
| 6350 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6351 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6352 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6353 | { |
| 6354 | struct nfs4_layoutcommit_data *data = calldata; |
| 6355 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6356 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6357 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6358 | nfs41_setup_sequence(session, |
| 6359 | &data->args.seq_args, |
| 6360 | &data->res.seq_res, |
| 6361 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6362 | } |
| 6363 | |
| 6364 | static void |
| 6365 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6366 | { |
| 6367 | struct nfs4_layoutcommit_data *data = calldata; |
| 6368 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6369 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6370 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6371 | return; |
| 6372 | |
| 6373 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6374 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6375 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6376 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6377 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6378 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6379 | break; |
| 6380 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6381 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6382 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6383 | break; |
| 6384 | default: |
| 6385 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6386 | rpc_restart_call_prepare(task); |
| 6387 | return; |
| 6388 | } |
| 6389 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6390 | } |
| 6391 | |
| 6392 | static void nfs4_layoutcommit_release(void *calldata) |
| 6393 | { |
| 6394 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6395 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6396 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6397 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6398 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6399 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6400 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6401 | list_del_init(&lseg->pls_lc_list); |
| 6402 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6403 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6404 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6405 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6406 | |
| 6407 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6408 | smp_mb__after_clear_bit(); |
| 6409 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6410 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6411 | put_rpccred(data->cred); |
| 6412 | kfree(data); |
| 6413 | } |
| 6414 | |
| 6415 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6416 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6417 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6418 | .rpc_release = nfs4_layoutcommit_release, |
| 6419 | }; |
| 6420 | |
| 6421 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6422 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6423 | { |
| 6424 | struct rpc_message msg = { |
| 6425 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6426 | .rpc_argp = &data->args, |
| 6427 | .rpc_resp = &data->res, |
| 6428 | .rpc_cred = data->cred, |
| 6429 | }; |
| 6430 | struct rpc_task_setup task_setup_data = { |
| 6431 | .task = &data->task, |
| 6432 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6433 | .rpc_message = &msg, |
| 6434 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6435 | .callback_data = data, |
| 6436 | .flags = RPC_TASK_ASYNC, |
| 6437 | }; |
| 6438 | struct rpc_task *task; |
| 6439 | int status = 0; |
| 6440 | |
| 6441 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6442 | "lbw: %llu inode %lu\n", |
| 6443 | data->task.tk_pid, sync, |
| 6444 | data->args.lastbytewritten, |
| 6445 | data->args.inode->i_ino); |
| 6446 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6447 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6448 | task = rpc_run_task(&task_setup_data); |
| 6449 | if (IS_ERR(task)) |
| 6450 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6451 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6452 | goto out; |
| 6453 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6454 | if (status != 0) |
| 6455 | goto out; |
| 6456 | status = task->tk_status; |
| 6457 | out: |
| 6458 | dprintk("%s: status %d\n", __func__, status); |
| 6459 | rpc_put_task(task); |
| 6460 | return status; |
| 6461 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6462 | |
| 6463 | static int |
| 6464 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6465 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6466 | { |
| 6467 | struct nfs41_secinfo_no_name_args args = { |
| 6468 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6469 | }; |
| 6470 | struct nfs4_secinfo_res res = { |
| 6471 | .flavors = flavors, |
| 6472 | }; |
| 6473 | struct rpc_message msg = { |
| 6474 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6475 | .rpc_argp = &args, |
| 6476 | .rpc_resp = &res, |
| 6477 | }; |
| 6478 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6479 | } |
| 6480 | |
| 6481 | static int |
| 6482 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6483 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6484 | { |
| 6485 | struct nfs4_exception exception = { }; |
| 6486 | int err; |
| 6487 | do { |
| 6488 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6489 | switch (err) { |
| 6490 | case 0: |
| 6491 | case -NFS4ERR_WRONGSEC: |
| 6492 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6493 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6494 | default: |
| 6495 | err = nfs4_handle_exception(server, err, &exception); |
| 6496 | } |
| 6497 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6498 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6499 | return err; |
| 6500 | } |
| 6501 | |
| 6502 | static int |
| 6503 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6504 | struct nfs_fsinfo *info) |
| 6505 | { |
| 6506 | int err; |
| 6507 | struct page *page; |
| 6508 | rpc_authflavor_t flavor; |
| 6509 | struct nfs4_secinfo_flavors *flavors; |
| 6510 | |
| 6511 | page = alloc_page(GFP_KERNEL); |
| 6512 | if (!page) { |
| 6513 | err = -ENOMEM; |
| 6514 | goto out; |
| 6515 | } |
| 6516 | |
| 6517 | flavors = page_address(page); |
| 6518 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6519 | |
| 6520 | /* |
| 6521 | * Fall back on "guess and check" method if |
| 6522 | * the server doesn't support SECINFO_NO_NAME |
| 6523 | */ |
| 6524 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6525 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6526 | goto out_freepage; |
| 6527 | } |
| 6528 | if (err) |
| 6529 | goto out_freepage; |
| 6530 | |
| 6531 | flavor = nfs_find_best_sec(flavors); |
| 6532 | if (err == 0) |
| 6533 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6534 | |
| 6535 | out_freepage: |
| 6536 | put_page(page); |
| 6537 | if (err == -EACCES) |
| 6538 | return -EPERM; |
| 6539 | out: |
| 6540 | return err; |
| 6541 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6542 | |
| 6543 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6544 | { |
| 6545 | int status; |
| 6546 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6547 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6548 | }; |
| 6549 | struct nfs41_test_stateid_res res; |
| 6550 | struct rpc_message msg = { |
| 6551 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6552 | .rpc_argp = &args, |
| 6553 | .rpc_resp = &res, |
| 6554 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6555 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6556 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6557 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6558 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6559 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6560 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6561 | if (status != NFS_OK) { |
| 6562 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6563 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6564 | } |
| 6565 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6566 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6567 | } |
| 6568 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6569 | /** |
| 6570 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6571 | * |
| 6572 | * @server: server / transport on which to perform the operation |
| 6573 | * @stateid: state ID to test |
| 6574 | * |
| 6575 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6576 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6577 | * failed or the state ID is not currently valid. |
| 6578 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6579 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6580 | { |
| 6581 | struct nfs4_exception exception = { }; |
| 6582 | int err; |
| 6583 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6584 | err = _nfs41_test_stateid(server, stateid); |
| 6585 | if (err != -NFS4ERR_DELAY) |
| 6586 | break; |
| 6587 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6588 | } while (exception.retry); |
| 6589 | return err; |
| 6590 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6591 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6592 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6593 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6594 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6595 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6596 | }; |
| 6597 | struct nfs41_free_stateid_res res; |
| 6598 | struct rpc_message msg = { |
| 6599 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6600 | .rpc_argp = &args, |
| 6601 | .rpc_resp = &res, |
| 6602 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6603 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6604 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6605 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6606 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6607 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6608 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6609 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6610 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6611 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6612 | } |
| 6613 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6614 | /** |
| 6615 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6616 | * |
| 6617 | * @server: server / transport on which to perform the operation |
| 6618 | * @stateid: state ID to release |
| 6619 | * |
| 6620 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6621 | * negative NFS4ERR value is returned. |
| 6622 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6623 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6624 | { |
| 6625 | struct nfs4_exception exception = { }; |
| 6626 | int err; |
| 6627 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6628 | err = _nfs4_free_stateid(server, stateid); |
| 6629 | if (err != -NFS4ERR_DELAY) |
| 6630 | break; |
| 6631 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6632 | } while (exception.retry); |
| 6633 | return err; |
| 6634 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6635 | |
| 6636 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6637 | const nfs4_stateid *s2) |
| 6638 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6639 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6640 | return false; |
| 6641 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6642 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6643 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6644 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6645 | return true; |
| 6646 | |
| 6647 | return false; |
| 6648 | } |
| 6649 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6650 | #endif /* CONFIG_NFS_V4_1 */ |
| 6651 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6652 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6653 | const nfs4_stateid *s2) |
| 6654 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6655 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6659 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6660 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6661 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6662 | .recover_open = nfs4_open_reclaim, |
| 6663 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6664 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6665 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6666 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6667 | }; |
| 6668 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6669 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6670 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6671 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6672 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6673 | .recover_open = nfs4_open_reclaim, |
| 6674 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6675 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6676 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6677 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6678 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6679 | }; |
| 6680 | #endif /* CONFIG_NFS_V4_1 */ |
| 6681 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6682 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6683 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6684 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6685 | .recover_open = nfs4_open_expired, |
| 6686 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6687 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6688 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6689 | }; |
| 6690 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6691 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6692 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6693 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6694 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6695 | .recover_open = nfs41_open_expired, |
| 6696 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6697 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6698 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6699 | }; |
| 6700 | #endif /* CONFIG_NFS_V4_1 */ |
| 6701 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6702 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6703 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6704 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6705 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6706 | }; |
| 6707 | |
| 6708 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6709 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6710 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6711 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6712 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6713 | }; |
| 6714 | #endif |
| 6715 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6716 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6717 | .minor_version = 0, |
| 6718 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6719 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6720 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6721 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6722 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6723 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6724 | }; |
| 6725 | |
| 6726 | #if defined(CONFIG_NFS_V4_1) |
| 6727 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6728 | .minor_version = 1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6729 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6730 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6731 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6732 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6733 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6734 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6735 | }; |
| 6736 | #endif |
| 6737 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6738 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6739 | [0] = &nfs_v4_0_minor_ops, |
| 6740 | #if defined(CONFIG_NFS_V4_1) |
| 6741 | [1] = &nfs_v4_1_minor_ops, |
| 6742 | #endif |
| 6743 | }; |
| 6744 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6745 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6746 | .create = nfs_create, |
| 6747 | .lookup = nfs_lookup, |
| 6748 | .atomic_open = nfs_atomic_open, |
| 6749 | .link = nfs_link, |
| 6750 | .unlink = nfs_unlink, |
| 6751 | .symlink = nfs_symlink, |
| 6752 | .mkdir = nfs_mkdir, |
| 6753 | .rmdir = nfs_rmdir, |
| 6754 | .mknod = nfs_mknod, |
| 6755 | .rename = nfs_rename, |
| 6756 | .permission = nfs_permission, |
| 6757 | .getattr = nfs_getattr, |
| 6758 | .setattr = nfs_setattr, |
| 6759 | .getxattr = generic_getxattr, |
| 6760 | .setxattr = generic_setxattr, |
| 6761 | .listxattr = generic_listxattr, |
| 6762 | .removexattr = generic_removexattr, |
| 6763 | }; |
| 6764 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6765 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6766 | .permission = nfs_permission, |
| 6767 | .getattr = nfs_getattr, |
| 6768 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6769 | .getxattr = generic_getxattr, |
| 6770 | .setxattr = generic_setxattr, |
| 6771 | .listxattr = generic_listxattr, |
| 6772 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6773 | }; |
| 6774 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6775 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6776 | .version = 4, /* protocol version */ |
| 6777 | .dentry_ops = &nfs4_dentry_operations, |
| 6778 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6779 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6780 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6781 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6782 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6783 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6784 | .getattr = nfs4_proc_getattr, |
| 6785 | .setattr = nfs4_proc_setattr, |
| 6786 | .lookup = nfs4_proc_lookup, |
| 6787 | .access = nfs4_proc_access, |
| 6788 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6789 | .create = nfs4_proc_create, |
| 6790 | .remove = nfs4_proc_remove, |
| 6791 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6792 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | .unlink_done = nfs4_proc_unlink_done, |
| 6794 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6795 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6796 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6797 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6798 | .link = nfs4_proc_link, |
| 6799 | .symlink = nfs4_proc_symlink, |
| 6800 | .mkdir = nfs4_proc_mkdir, |
| 6801 | .rmdir = nfs4_proc_remove, |
| 6802 | .readdir = nfs4_proc_readdir, |
| 6803 | .mknod = nfs4_proc_mknod, |
| 6804 | .statfs = nfs4_proc_statfs, |
| 6805 | .fsinfo = nfs4_proc_fsinfo, |
| 6806 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6807 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6808 | .decode_dirent = nfs4_decode_dirent, |
| 6809 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6810 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6811 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6812 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6813 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6814 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6815 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6816 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6817 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6818 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6819 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6820 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6821 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6822 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6823 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6824 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6825 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6826 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6827 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6828 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6829 | .create_server = nfs4_create_server, |
| 6830 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6831 | }; |
| 6832 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6833 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6834 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6835 | .list = nfs4_xattr_list_nfs4_acl, |
| 6836 | .get = nfs4_xattr_get_nfs4_acl, |
| 6837 | .set = nfs4_xattr_set_nfs4_acl, |
| 6838 | }; |
| 6839 | |
| 6840 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6841 | &nfs4_xattr_nfs4_acl_handler, |
| 6842 | NULL |
| 6843 | }; |
| 6844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6845 | /* |
| 6846 | * Local variables: |
| 6847 | * c-basic-offset: 8 |
| 6848 | * End: |
| 6849 | */ |