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: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 96 | case -NFS4ERR_LAYOUTTRYLATER: |
| 97 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 98 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 99 | case -NFS4ERR_WRONGSEC: |
| 100 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 101 | case -NFS4ERR_BADOWNER: |
| 102 | case -NFS4ERR_BADNAME: |
| 103 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 104 | case -NFS4ERR_SHARE_DENIED: |
| 105 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 106 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 107 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 108 | case -NFS4ERR_ACCESS: |
| 109 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 110 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 112 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 113 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 115 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* |
| 119 | * This is our standard bitmap for GETATTR requests. |
| 120 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 121 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | FATTR4_WORD0_TYPE |
| 123 | | FATTR4_WORD0_CHANGE |
| 124 | | FATTR4_WORD0_SIZE |
| 125 | | FATTR4_WORD0_FSID |
| 126 | | FATTR4_WORD0_FILEID, |
| 127 | FATTR4_WORD1_MODE |
| 128 | | FATTR4_WORD1_NUMLINKS |
| 129 | | FATTR4_WORD1_OWNER |
| 130 | | FATTR4_WORD1_OWNER_GROUP |
| 131 | | FATTR4_WORD1_RAWDEV |
| 132 | | FATTR4_WORD1_SPACE_USED |
| 133 | | FATTR4_WORD1_TIME_ACCESS |
| 134 | | FATTR4_WORD1_TIME_METADATA |
| 135 | | FATTR4_WORD1_TIME_MODIFY |
| 136 | }; |
| 137 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 138 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 139 | FATTR4_WORD0_TYPE |
| 140 | | FATTR4_WORD0_CHANGE |
| 141 | | FATTR4_WORD0_SIZE |
| 142 | | FATTR4_WORD0_FSID |
| 143 | | FATTR4_WORD0_FILEID, |
| 144 | FATTR4_WORD1_MODE |
| 145 | | FATTR4_WORD1_NUMLINKS |
| 146 | | FATTR4_WORD1_OWNER |
| 147 | | FATTR4_WORD1_OWNER_GROUP |
| 148 | | FATTR4_WORD1_RAWDEV |
| 149 | | FATTR4_WORD1_SPACE_USED |
| 150 | | FATTR4_WORD1_TIME_ACCESS |
| 151 | | FATTR4_WORD1_TIME_METADATA |
| 152 | | FATTR4_WORD1_TIME_MODIFY, |
| 153 | FATTR4_WORD2_MDSTHRESHOLD |
| 154 | }; |
| 155 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 156 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 157 | FATTR4_WORD0_TYPE |
| 158 | | FATTR4_WORD0_CHANGE |
| 159 | | FATTR4_WORD0_FILEID, |
| 160 | }; |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | const u32 nfs4_statfs_bitmap[2] = { |
| 163 | FATTR4_WORD0_FILES_AVAIL |
| 164 | | FATTR4_WORD0_FILES_FREE |
| 165 | | FATTR4_WORD0_FILES_TOTAL, |
| 166 | FATTR4_WORD1_SPACE_AVAIL |
| 167 | | FATTR4_WORD1_SPACE_FREE |
| 168 | | FATTR4_WORD1_SPACE_TOTAL |
| 169 | }; |
| 170 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 171 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | FATTR4_WORD0_MAXLINK |
| 173 | | FATTR4_WORD0_MAXNAME, |
| 174 | 0 |
| 175 | }; |
| 176 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 177 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | | FATTR4_WORD0_MAXREAD |
| 179 | | FATTR4_WORD0_MAXWRITE |
| 180 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 181 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 182 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 183 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 186 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 187 | FATTR4_WORD0_TYPE |
| 188 | | FATTR4_WORD0_CHANGE |
| 189 | | FATTR4_WORD0_SIZE |
| 190 | | FATTR4_WORD0_FSID |
| 191 | | FATTR4_WORD0_FILEID |
| 192 | | FATTR4_WORD0_FS_LOCATIONS, |
| 193 | FATTR4_WORD1_MODE |
| 194 | | FATTR4_WORD1_NUMLINKS |
| 195 | | FATTR4_WORD1_OWNER |
| 196 | | FATTR4_WORD1_OWNER_GROUP |
| 197 | | FATTR4_WORD1_RAWDEV |
| 198 | | FATTR4_WORD1_SPACE_USED |
| 199 | | FATTR4_WORD1_TIME_ACCESS |
| 200 | | FATTR4_WORD1_TIME_METADATA |
| 201 | | FATTR4_WORD1_TIME_MODIFY |
| 202 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 203 | }; |
| 204 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 205 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | struct nfs4_readdir_arg *readdir) |
| 207 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 208 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 211 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | readdir->cookie = 0; |
| 217 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 218 | if (cookie == 2) |
| 219 | return; |
| 220 | |
| 221 | /* |
| 222 | * NFSv4 servers do not return entries for '.' and '..' |
| 223 | * Therefore, we fake these entries here. We let '.' |
| 224 | * have cookie 0 and '..' have cookie 1. Note that |
| 225 | * when talking to the server, we always send cookie 0 |
| 226 | * instead of 1 or 2. |
| 227 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 228 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | if (cookie == 0) { |
| 231 | *p++ = xdr_one; /* next */ |
| 232 | *p++ = xdr_zero; /* cookie, first word */ |
| 233 | *p++ = xdr_one; /* cookie, second word */ |
| 234 | *p++ = xdr_one; /* entry len */ |
| 235 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 236 | p++; |
| 237 | *p++ = xdr_one; /* bitmap length */ |
| 238 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 239 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 240 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | *p++ = xdr_one; /* next */ |
| 244 | *p++ = xdr_zero; /* cookie, first word */ |
| 245 | *p++ = xdr_two; /* cookie, second word */ |
| 246 | *p++ = xdr_two; /* entry len */ |
| 247 | memcpy(p, "..\0\0", 4); /* entry */ |
| 248 | p++; |
| 249 | *p++ = xdr_one; /* bitmap length */ |
| 250 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 251 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 252 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | readdir->pgbase = (char *)p - (char *)start; |
| 255 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 256 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 259 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 260 | { |
| 261 | int res = 0; |
| 262 | |
| 263 | might_sleep(); |
| 264 | |
| 265 | if (*timeout <= 0) |
| 266 | *timeout = NFS4_POLL_RETRY_MIN; |
| 267 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 268 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 269 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 270 | if (fatal_signal_pending(current)) |
| 271 | res = -ERESTARTSYS; |
| 272 | *timeout <<= 1; |
| 273 | return res; |
| 274 | } |
| 275 | |
| 276 | /* This is the error handling routine for processes that are allowed |
| 277 | * to sleep. |
| 278 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 279 | 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] | 280 | { |
| 281 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 282 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 283 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 284 | int ret = errorcode; |
| 285 | |
| 286 | exception->retry = 0; |
| 287 | switch(errorcode) { |
| 288 | case 0: |
| 289 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 290 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 291 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 292 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 293 | exception->retry = 1; |
| 294 | return 0; |
| 295 | } |
| 296 | if (state == NULL) |
| 297 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 298 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 299 | if (ret < 0) |
| 300 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 301 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 302 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 303 | case -NFS4ERR_ADMIN_REVOKED: |
| 304 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 305 | if (state == NULL) |
| 306 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 307 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 308 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 309 | if (ret < 0) |
| 310 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 311 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 312 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 313 | if (state != NULL) { |
| 314 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 315 | if (ret < 0) |
| 316 | break; |
| 317 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 318 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 319 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 320 | nfs4_schedule_lease_recovery(clp); |
| 321 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 322 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 323 | case -NFS4ERR_BADSESSION: |
| 324 | case -NFS4ERR_BADSLOT: |
| 325 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 326 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 327 | case -NFS4ERR_DEADSESSION: |
| 328 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 329 | case -NFS4ERR_SEQ_MISORDERED: |
| 330 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 331 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 332 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 333 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 334 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 335 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 336 | if (exception->timeout > HZ) { |
| 337 | /* We have retried a decent amount, time to |
| 338 | * fail |
| 339 | */ |
| 340 | ret = -EBUSY; |
| 341 | break; |
| 342 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 343 | case -NFS4ERR_GRACE: |
| 344 | case -NFS4ERR_DELAY: |
| 345 | ret = nfs4_delay(server->client, &exception->timeout); |
| 346 | if (ret != 0) |
| 347 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 348 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 349 | case -NFS4ERR_OLD_STATEID: |
| 350 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 351 | break; |
| 352 | case -NFS4ERR_BADOWNER: |
| 353 | /* The following works around a Linux server bug! */ |
| 354 | case -NFS4ERR_BADNAME: |
| 355 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 356 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 357 | exception->retry = 1; |
| 358 | printk(KERN_WARNING "NFS: v4 server %s " |
| 359 | "does not accept raw " |
| 360 | "uid/gids. " |
| 361 | "Reenabling the idmapper.\n", |
| 362 | server->nfs_client->cl_hostname); |
| 363 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 364 | } |
| 365 | /* We failed to handle the error */ |
| 366 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 367 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 368 | ret = nfs4_wait_clnt_recover(clp); |
| 369 | if (ret == 0) |
| 370 | exception->retry = 1; |
| 371 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 375 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | spin_lock(&clp->cl_lock); |
| 378 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 379 | clp->cl_last_renewal = timestamp; |
| 380 | spin_unlock(&clp->cl_lock); |
| 381 | } |
| 382 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 383 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 384 | { |
| 385 | do_renew_lease(server->nfs_client, timestamp); |
| 386 | } |
| 387 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 388 | #if defined(CONFIG_NFS_V4_1) |
| 389 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 390 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 391 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 392 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 393 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 394 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 395 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 396 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 397 | /* just wake up the next guy waiting since |
| 398 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 399 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 400 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 401 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 402 | tbl = res->sr_slot->table; |
| 403 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 404 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 405 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 406 | /* Be nice to the server: try to ensure that the last transmitted |
| 407 | * value for highest_user_slotid <= target_highest_slotid |
| 408 | */ |
| 409 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 410 | send_new_highest_used_slotid = true; |
| 411 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 412 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 413 | send_new_highest_used_slotid = false; |
| 414 | goto out_unlock; |
| 415 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 416 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 417 | |
| 418 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 419 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 420 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 421 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 422 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 423 | if (send_new_highest_used_slotid) |
| 424 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 425 | } |
| 426 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 427 | 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] | 428 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 429 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 430 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 431 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 432 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 433 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 434 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 435 | /* don't increment the sequence number if the task wasn't sent */ |
| 436 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 437 | goto out; |
| 438 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 439 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 440 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 441 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 442 | if (slot->interrupted) { |
| 443 | slot->interrupted = 0; |
| 444 | interrupted = true; |
| 445 | } |
| 446 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 447 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 448 | switch (res->sr_status) { |
| 449 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 450 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 451 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 452 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 453 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 454 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 455 | if (res->sr_status_flags != 0) |
| 456 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 457 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 458 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 459 | case 1: |
| 460 | /* |
| 461 | * sr_status remains 1 if an RPC level error occurred. |
| 462 | * The server may or may not have processed the sequence |
| 463 | * operation.. |
| 464 | * Mark the slot as having hosted an interrupted RPC call. |
| 465 | */ |
| 466 | slot->interrupted = 1; |
| 467 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | case -NFS4ERR_DELAY: |
| 469 | /* The server detected a resend of the RPC call and |
| 470 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 471 | * of RFC5661. |
| 472 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 473 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 474 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 475 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 476 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 477 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 478 | case -NFS4ERR_BADSLOT: |
| 479 | /* |
| 480 | * The slot id we used was probably retired. Try again |
| 481 | * using a different slot id. |
| 482 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 483 | goto retry_nowait; |
| 484 | case -NFS4ERR_SEQ_MISORDERED: |
| 485 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 486 | * Was the last operation on this sequence interrupted? |
| 487 | * If so, retry after bumping the sequence number. |
| 488 | */ |
| 489 | if (interrupted) { |
| 490 | ++slot->seq_nr; |
| 491 | goto retry_nowait; |
| 492 | } |
| 493 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 494 | * Could this slot have been previously retired? |
| 495 | * If so, then the server may be expecting seq_nr = 1! |
| 496 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 497 | if (slot->seq_nr != 1) { |
| 498 | slot->seq_nr = 1; |
| 499 | goto retry_nowait; |
| 500 | } |
| 501 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 502 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 503 | ++slot->seq_nr; |
| 504 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 505 | default: |
| 506 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 507 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 508 | } |
| 509 | out: |
| 510 | /* The session may be reset by one of the error handlers. */ |
| 511 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 512 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 513 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 514 | retry_nowait: |
| 515 | if (rpc_restart_call_prepare(task)) { |
| 516 | task->tk_status = 0; |
| 517 | ret = 0; |
| 518 | } |
| 519 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 520 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 521 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 522 | goto out; |
| 523 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 524 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 525 | } |
| 526 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 527 | static int nfs4_sequence_done(struct rpc_task *task, |
| 528 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 529 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 530 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 531 | return 1; |
| 532 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 535 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 536 | struct nfs4_sequence_res *res, int cache_reply) |
| 537 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 538 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 539 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 540 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 541 | if (cache_reply) |
| 542 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 543 | res->sr_slot = NULL; |
| 544 | } |
| 545 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 546 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 547 | { |
| 548 | args->sa_privileged = 1; |
| 549 | } |
| 550 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 551 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 552 | struct nfs4_sequence_args *args, |
| 553 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 554 | struct rpc_task *task) |
| 555 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 556 | struct nfs4_slot *slot; |
| 557 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 558 | |
| 559 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 560 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 561 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 562 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 563 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 564 | tbl = &session->fc_slot_table; |
| 565 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 566 | task->tk_timeout = 0; |
| 567 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 568 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 569 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 570 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 571 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 572 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 573 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 574 | } |
| 575 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 576 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 577 | if (IS_ERR(slot)) { |
| 578 | /* If out of memory, try again in 1/4 second */ |
| 579 | if (slot == ERR_PTR(-ENOMEM)) |
| 580 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 581 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 582 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 583 | } |
| 584 | spin_unlock(&tbl->slot_tbl_lock); |
| 585 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 586 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 587 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 588 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 589 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 590 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 591 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 592 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 593 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 594 | /* |
| 595 | * sr_status is only set in decode_sequence, and so will remain |
| 596 | * set to 1 if an rpc level failure occurs. |
| 597 | */ |
| 598 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 599 | out_success: |
| 600 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 602 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 603 | /* Privileged tasks are queued with top priority */ |
| 604 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 605 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 606 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 607 | else |
| 608 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 609 | spin_unlock(&tbl->slot_tbl_lock); |
| 610 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 611 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 612 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 614 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | struct nfs4_sequence_args *args, |
| 616 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | struct rpc_task *task) |
| 618 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 619 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 620 | int ret = 0; |
| 621 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 622 | if (session == NULL) { |
| 623 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 625 | } |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 626 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 627 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 628 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 629 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 630 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 631 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | out: |
| 633 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 634 | return ret; |
| 635 | } |
| 636 | |
| 637 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 638 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 639 | struct nfs4_sequence_args *seq_args; |
| 640 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 641 | }; |
| 642 | |
| 643 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 644 | { |
| 645 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 646 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 647 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 648 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 649 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 650 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 651 | } |
| 652 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 653 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 654 | { |
| 655 | struct nfs41_call_sync_data *data = calldata; |
| 656 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 657 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 660 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 662 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | }; |
| 664 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 665 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 666 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | struct rpc_message *msg, |
| 668 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 669 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 670 | { |
| 671 | int ret; |
| 672 | struct rpc_task *task; |
| 673 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 674 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 675 | .seq_args = args, |
| 676 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | }; |
| 678 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 679 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | .rpc_message = msg, |
| 681 | .callback_ops = &nfs41_call_sync_ops, |
| 682 | .callback_data = &data |
| 683 | }; |
| 684 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 685 | task = rpc_run_task(&task_setup); |
| 686 | if (IS_ERR(task)) |
| 687 | ret = PTR_ERR(task); |
| 688 | else { |
| 689 | ret = task->tk_status; |
| 690 | rpc_put_task(task); |
| 691 | } |
| 692 | return ret; |
| 693 | } |
| 694 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 695 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 696 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 697 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 698 | struct nfs4_sequence_res *res, int cache_reply) |
| 699 | { |
| 700 | } |
| 701 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 702 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 703 | { |
| 704 | } |
| 705 | |
| 706 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 707 | static int nfs4_sequence_done(struct rpc_task *task, |
| 708 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 709 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 710 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 711 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 712 | #endif /* CONFIG_NFS_V4_1 */ |
| 713 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 714 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 715 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 716 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 717 | struct rpc_message *msg, |
| 718 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 719 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 720 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 721 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 724 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 725 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 726 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 727 | struct rpc_message *msg, |
| 728 | struct nfs4_sequence_args *args, |
| 729 | struct nfs4_sequence_res *res, |
| 730 | int cache_reply) |
| 731 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 732 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 733 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 734 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 735 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 736 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 737 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 739 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 741 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 742 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 743 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 744 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 745 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 746 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 747 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 750 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 751 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 752 | struct nfs_openargs o_arg; |
| 753 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 754 | struct nfs_open_confirmargs c_arg; |
| 755 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 756 | struct nfs4_string owner_name; |
| 757 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 760 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 762 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 764 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 765 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 766 | int rpc_status; |
| 767 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 768 | }; |
| 769 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 770 | |
| 771 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 772 | { |
| 773 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 774 | p->o_res.seqid = p->o_arg.seqid; |
| 775 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 776 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 777 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 778 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 779 | 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] | 780 | } |
| 781 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 782 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 783 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 784 | const struct iattr *attrs, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 785 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 786 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 787 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 788 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 789 | struct inode *dir = parent->d_inode; |
| 790 | struct nfs_server *server = NFS_SERVER(dir); |
| 791 | struct nfs4_opendata *p; |
| 792 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 793 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 794 | if (p == NULL) |
| 795 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 796 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | if (p->o_arg.seqid == NULL) |
| 798 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 799 | nfs_sb_active(dentry->d_sb); |
| 800 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 801 | p->dir = parent; |
| 802 | p->owner = sp; |
| 803 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 804 | p->o_arg.open_flags = flags; |
| 805 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 806 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 807 | * will return permission denied for all bits until close */ |
| 808 | if (!(flags & O_EXCL)) { |
| 809 | /* ask server to check for all possible rights as results |
| 810 | * are cached */ |
| 811 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 812 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 813 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 814 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 815 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 816 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 817 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | p->o_arg.server = server; |
| 819 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 820 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 821 | p->o_arg.claim = claim; |
| 822 | switch (claim) { |
| 823 | case NFS4_OPEN_CLAIM_NULL: |
| 824 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 825 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 826 | p->o_arg.fh = NFS_FH(dir); |
| 827 | break; |
| 828 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 829 | case NFS4_OPEN_CLAIM_FH: |
| 830 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 831 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 832 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 833 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 834 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 835 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 836 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 837 | p->o_arg.u.attrs = &p->attrs; |
| 838 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 839 | |
| 840 | verf[0] = jiffies; |
| 841 | verf[1] = current->pid; |
| 842 | memcpy(p->o_arg.u.verifier.data, verf, |
| 843 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 844 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 845 | p->c_arg.fh = &p->o_res.fh; |
| 846 | p->c_arg.stateid = &p->o_res.stateid; |
| 847 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 848 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 849 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 850 | return p; |
| 851 | err_free: |
| 852 | kfree(p); |
| 853 | err: |
| 854 | dput(parent); |
| 855 | return NULL; |
| 856 | } |
| 857 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 858 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 859 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 860 | struct nfs4_opendata *p = container_of(kref, |
| 861 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 862 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 863 | |
| 864 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 865 | if (p->state != NULL) |
| 866 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 867 | nfs4_put_state_owner(p->owner); |
| 868 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 869 | dput(p->dentry); |
| 870 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 871 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 872 | kfree(p); |
| 873 | } |
| 874 | |
| 875 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 876 | { |
| 877 | if (p != NULL) |
| 878 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 879 | } |
| 880 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 881 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 882 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 883 | int ret; |
| 884 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 885 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 886 | return ret; |
| 887 | } |
| 888 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 889 | 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] | 890 | { |
| 891 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 892 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 893 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | goto out; |
| 895 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 896 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 897 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 898 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 899 | break; |
| 900 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 901 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 902 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 903 | break; |
| 904 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 905 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 906 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 907 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 908 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 909 | return ret; |
| 910 | } |
| 911 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 912 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 913 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 914 | if (delegation == NULL) |
| 915 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 916 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 917 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 918 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 919 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 920 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 921 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 922 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 923 | return 1; |
| 924 | } |
| 925 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 926 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 927 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 929 | case FMODE_WRITE: |
| 930 | state->n_wronly++; |
| 931 | break; |
| 932 | case FMODE_READ: |
| 933 | state->n_rdonly++; |
| 934 | break; |
| 935 | case FMODE_READ|FMODE_WRITE: |
| 936 | state->n_rdwr++; |
| 937 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 939 | } |
| 940 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 941 | 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] | 942 | { |
| 943 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 944 | nfs4_stateid_copy(&state->stateid, stateid); |
| 945 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 947 | case FMODE_READ: |
| 948 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 949 | break; |
| 950 | case FMODE_WRITE: |
| 951 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 952 | break; |
| 953 | case FMODE_READ|FMODE_WRITE: |
| 954 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 955 | } |
| 956 | } |
| 957 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 958 | 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] | 959 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 960 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 962 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 963 | } |
| 964 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 965 | 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] | 966 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 967 | /* |
| 968 | * Protect the call to nfs4_state_set_mode_locked and |
| 969 | * serialise the stateid update |
| 970 | */ |
| 971 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 972 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 973 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 974 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 975 | } |
| 976 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 977 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 978 | write_sequnlock(&state->seqlock); |
| 979 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 980 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 981 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 984 | 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] | 985 | { |
| 986 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 987 | struct nfs_delegation *deleg_cur; |
| 988 | int ret = 0; |
| 989 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 991 | |
| 992 | rcu_read_lock(); |
| 993 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 994 | if (deleg_cur == NULL) |
| 995 | goto no_delegation; |
| 996 | |
| 997 | spin_lock(&deleg_cur->lock); |
| 998 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 999 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1001 | goto no_delegation_unlock; |
| 1002 | |
| 1003 | if (delegation == NULL) |
| 1004 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1005 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1006 | goto no_delegation_unlock; |
| 1007 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1008 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1009 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1010 | ret = 1; |
| 1011 | no_delegation_unlock: |
| 1012 | spin_unlock(&deleg_cur->lock); |
| 1013 | no_delegation: |
| 1014 | rcu_read_unlock(); |
| 1015 | |
| 1016 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1018 | ret = 1; |
| 1019 | } |
| 1020 | |
| 1021 | return ret; |
| 1022 | } |
| 1023 | |
| 1024 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1026 | { |
| 1027 | struct nfs_delegation *delegation; |
| 1028 | |
| 1029 | rcu_read_lock(); |
| 1030 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1032 | rcu_read_unlock(); |
| 1033 | return; |
| 1034 | } |
| 1035 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1036 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1039 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1040 | { |
| 1041 | struct nfs4_state *state = opendata->state; |
| 1042 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1043 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1044 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1046 | nfs4_stateid stateid; |
| 1047 | int ret = -EAGAIN; |
| 1048 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1049 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1050 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1051 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1052 | if (can_open_cached(state, fmode, open_mode)) { |
| 1053 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1054 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1055 | goto out_return_state; |
| 1056 | } |
| 1057 | spin_unlock(&state->owner->so_lock); |
| 1058 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1059 | rcu_read_lock(); |
| 1060 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1061 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1062 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1063 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1064 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1065 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1066 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1067 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1068 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1069 | if (ret != 0) |
| 1070 | goto out; |
| 1071 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1072 | |
| 1073 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1074 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1075 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1077 | out: |
| 1078 | return ERR_PTR(ret); |
| 1079 | out_return_state: |
| 1080 | atomic_inc(&state->count); |
| 1081 | return state; |
| 1082 | } |
| 1083 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1084 | static void |
| 1085 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1086 | { |
| 1087 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1088 | struct nfs_delegation *delegation; |
| 1089 | int delegation_flags = 0; |
| 1090 | |
| 1091 | rcu_read_lock(); |
| 1092 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1093 | if (delegation) |
| 1094 | delegation_flags = delegation->flags; |
| 1095 | rcu_read_unlock(); |
| 1096 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1097 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1098 | "returning a delegation for " |
| 1099 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1100 | clp->cl_hostname); |
| 1101 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1102 | nfs_inode_set_delegation(state->inode, |
| 1103 | data->owner->so_cred, |
| 1104 | &data->o_res); |
| 1105 | else |
| 1106 | nfs_inode_reclaim_delegation(state->inode, |
| 1107 | data->owner->so_cred, |
| 1108 | &data->o_res); |
| 1109 | } |
| 1110 | |
| 1111 | /* |
| 1112 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1113 | * and update the nfs4_state. |
| 1114 | */ |
| 1115 | static struct nfs4_state * |
| 1116 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1117 | { |
| 1118 | struct inode *inode = data->state->inode; |
| 1119 | struct nfs4_state *state = data->state; |
| 1120 | int ret; |
| 1121 | |
| 1122 | if (!data->rpc_done) { |
| 1123 | ret = data->rpc_status; |
| 1124 | goto err; |
| 1125 | } |
| 1126 | |
| 1127 | ret = -ESTALE; |
| 1128 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1129 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1130 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1131 | goto err; |
| 1132 | |
| 1133 | ret = -ENOMEM; |
| 1134 | state = nfs4_get_open_state(inode, data->owner); |
| 1135 | if (state == NULL) |
| 1136 | goto err; |
| 1137 | |
| 1138 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1139 | if (ret) |
| 1140 | goto err; |
| 1141 | |
| 1142 | if (data->o_res.delegation_type != 0) |
| 1143 | nfs4_opendata_check_deleg(data, state); |
| 1144 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1145 | data->o_arg.fmode); |
| 1146 | |
| 1147 | return state; |
| 1148 | err: |
| 1149 | return ERR_PTR(ret); |
| 1150 | |
| 1151 | } |
| 1152 | |
| 1153 | static struct nfs4_state * |
| 1154 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1155 | { |
| 1156 | struct inode *inode; |
| 1157 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1158 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1159 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1160 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1161 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1162 | goto out; |
| 1163 | } |
| 1164 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1165 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1166 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1167 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1168 | 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] | 1169 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1170 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1171 | goto err; |
| 1172 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1173 | state = nfs4_get_open_state(inode, data->owner); |
| 1174 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1175 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1176 | if (data->o_res.delegation_type != 0) |
| 1177 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1178 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1179 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1180 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1181 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1182 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1183 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1184 | err_put_inode: |
| 1185 | iput(inode); |
| 1186 | err: |
| 1187 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1188 | } |
| 1189 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1190 | static struct nfs4_state * |
| 1191 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1192 | { |
| 1193 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1194 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1195 | return _nfs4_opendata_to_nfs4_state(data); |
| 1196 | } |
| 1197 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1199 | { |
| 1200 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1201 | struct nfs_open_context *ctx; |
| 1202 | |
| 1203 | spin_lock(&state->inode->i_lock); |
| 1204 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1205 | if (ctx->state != state) |
| 1206 | continue; |
| 1207 | get_nfs_open_context(ctx); |
| 1208 | spin_unlock(&state->inode->i_lock); |
| 1209 | return ctx; |
| 1210 | } |
| 1211 | spin_unlock(&state->inode->i_lock); |
| 1212 | return ERR_PTR(-ENOENT); |
| 1213 | } |
| 1214 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 1215 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1216 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1217 | { |
| 1218 | struct nfs4_opendata *opendata; |
| 1219 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 1220 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
| 1221 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1222 | if (opendata == NULL) |
| 1223 | return ERR_PTR(-ENOMEM); |
| 1224 | opendata->state = state; |
| 1225 | atomic_inc(&state->count); |
| 1226 | return opendata; |
| 1227 | } |
| 1228 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1229 | 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] | 1230 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1231 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1232 | int ret; |
| 1233 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1234 | opendata->o_arg.open_flags = 0; |
| 1235 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1236 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1237 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1238 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1239 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1240 | if (ret != 0) |
| 1241 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1242 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1243 | if (IS_ERR(newstate)) |
| 1244 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1245 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1246 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1251 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1252 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1253 | int ret; |
| 1254 | |
| 1255 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1256 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1257 | smp_rmb(); |
| 1258 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1259 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1260 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1261 | if (ret != 0) |
| 1262 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1263 | if (newstate != state) |
| 1264 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1265 | } |
| 1266 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1267 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1268 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1269 | if (ret != 0) |
| 1270 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1271 | if (newstate != state) |
| 1272 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1273 | } |
| 1274 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1275 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1276 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1277 | if (ret != 0) |
| 1278 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1279 | if (newstate != state) |
| 1280 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1281 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1282 | /* |
| 1283 | * We may have performed cached opens for all three recoveries. |
| 1284 | * Check if we need to update the current stateid. |
| 1285 | */ |
| 1286 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1287 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1288 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1289 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1290 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1291 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1292 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | /* |
| 1297 | * OPEN_RECLAIM: |
| 1298 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1300 | 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] | 1301 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1302 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1303 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1304 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | int status; |
| 1306 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 1307 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1308 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1309 | if (IS_ERR(opendata)) |
| 1310 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1311 | rcu_read_lock(); |
| 1312 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1313 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1314 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1315 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1316 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1317 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1318 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | return status; |
| 1320 | } |
| 1321 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1322 | 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] | 1323 | { |
| 1324 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1325 | struct nfs4_exception exception = { }; |
| 1326 | int err; |
| 1327 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1328 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1329 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1330 | break; |
| 1331 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | } while (exception.retry); |
| 1333 | return err; |
| 1334 | } |
| 1335 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1336 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1337 | { |
| 1338 | struct nfs_open_context *ctx; |
| 1339 | int ret; |
| 1340 | |
| 1341 | ctx = nfs4_state_find_open_context(state); |
| 1342 | if (IS_ERR(ctx)) |
| 1343 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1344 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1345 | put_nfs_open_context(ctx); |
| 1346 | return ret; |
| 1347 | } |
| 1348 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1349 | 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] | 1350 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1351 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1352 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 1354 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1355 | NFS4_OPEN_CLAIM_DELEGATE_CUR); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1356 | if (IS_ERR(opendata)) |
| 1357 | return PTR_ERR(opendata); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1358 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1359 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1360 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1361 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1364 | 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] | 1365 | { |
| 1366 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1367 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | int err; |
| 1369 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1370 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | switch (err) { |
| 1372 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1373 | case -ENOENT: |
| 1374 | case -ESTALE: |
| 1375 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1376 | case -NFS4ERR_BADSESSION: |
| 1377 | case -NFS4ERR_BADSLOT: |
| 1378 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1379 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1380 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1381 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1382 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1383 | err = -EAGAIN; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1384 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | case -NFS4ERR_STALE_CLIENTID: |
| 1386 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1387 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | case -NFS4ERR_EXPIRED: |
| 1389 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1390 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1391 | err = -EAGAIN; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1392 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1393 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1394 | case -NFS4ERR_ADMIN_REVOKED: |
| 1395 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1396 | nfs_inode_find_state_and_recover(state->inode, |
| 1397 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1398 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1399 | case -ENOMEM: |
| 1400 | err = 0; |
| 1401 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1403 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | err = nfs4_handle_exception(server, err, &exception); |
| 1405 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1406 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | return err; |
| 1408 | } |
| 1409 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1410 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1411 | { |
| 1412 | struct nfs4_opendata *data = calldata; |
| 1413 | |
| 1414 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1415 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1416 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1417 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1418 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1419 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1420 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | static void nfs4_open_confirm_release(void *calldata) |
| 1424 | { |
| 1425 | struct nfs4_opendata *data = calldata; |
| 1426 | struct nfs4_state *state = NULL; |
| 1427 | |
| 1428 | /* If this request hasn't been cancelled, do nothing */ |
| 1429 | if (data->cancelled == 0) |
| 1430 | goto out_free; |
| 1431 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1432 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1433 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1434 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1435 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1436 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1437 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1438 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1442 | .rpc_call_done = nfs4_open_confirm_done, |
| 1443 | .rpc_release = nfs4_open_confirm_release, |
| 1444 | }; |
| 1445 | |
| 1446 | /* |
| 1447 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1448 | */ |
| 1449 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1450 | { |
| 1451 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1452 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1453 | struct rpc_message msg = { |
| 1454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1455 | .rpc_argp = &data->c_arg, |
| 1456 | .rpc_resp = &data->c_res, |
| 1457 | .rpc_cred = data->owner->so_cred, |
| 1458 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1459 | struct rpc_task_setup task_setup_data = { |
| 1460 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1461 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1462 | .callback_ops = &nfs4_open_confirm_ops, |
| 1463 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1464 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1465 | .flags = RPC_TASK_ASYNC, |
| 1466 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | int status; |
| 1468 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1469 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1470 | data->rpc_done = 0; |
| 1471 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1472 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1473 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1474 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1475 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1476 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1477 | if (status != 0) { |
| 1478 | data->cancelled = 1; |
| 1479 | smp_wmb(); |
| 1480 | } else |
| 1481 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1482 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | return status; |
| 1484 | } |
| 1485 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1486 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1488 | struct nfs4_opendata *data = calldata; |
| 1489 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1490 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1491 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1492 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1493 | /* |
| 1494 | * Check if we still need to send an OPEN call, or if we can use |
| 1495 | * a delegation instead. |
| 1496 | */ |
| 1497 | if (data->state != NULL) { |
| 1498 | struct nfs_delegation *delegation; |
| 1499 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1500 | 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] | 1501 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1502 | rcu_read_lock(); |
| 1503 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1504 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1505 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1506 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1507 | rcu_read_unlock(); |
| 1508 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1509 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1510 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1511 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1512 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1513 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1514 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1515 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1516 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1517 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1518 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1519 | &data->o_res.seq_res, |
| 1520 | task) != 0) |
| 1521 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1522 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1523 | unlock_no_action: |
| 1524 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1525 | out_no_action: |
| 1526 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1527 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1528 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1529 | } |
| 1530 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1531 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1532 | { |
| 1533 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1535 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1536 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1537 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1538 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1539 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1540 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1541 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1542 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1543 | case S_IFREG: |
| 1544 | break; |
| 1545 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1546 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1547 | break; |
| 1548 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1549 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1550 | break; |
| 1551 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1552 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1553 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1554 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1555 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1556 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1557 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1558 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1559 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1560 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1561 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1562 | static void nfs4_open_release(void *calldata) |
| 1563 | { |
| 1564 | struct nfs4_opendata *data = calldata; |
| 1565 | struct nfs4_state *state = NULL; |
| 1566 | |
| 1567 | /* If this request hasn't been cancelled, do nothing */ |
| 1568 | if (data->cancelled == 0) |
| 1569 | goto out_free; |
| 1570 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1571 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1572 | goto out_free; |
| 1573 | /* In case we need an open_confirm, no cleanup! */ |
| 1574 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1575 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1576 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1577 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1578 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1579 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1580 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1584 | .rpc_call_prepare = nfs4_open_prepare, |
| 1585 | .rpc_call_done = nfs4_open_done, |
| 1586 | .rpc_release = nfs4_open_release, |
| 1587 | }; |
| 1588 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1589 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1590 | { |
| 1591 | struct inode *dir = data->dir->d_inode; |
| 1592 | struct nfs_server *server = NFS_SERVER(dir); |
| 1593 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1594 | struct nfs_openres *o_res = &data->o_res; |
| 1595 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1596 | struct rpc_message msg = { |
| 1597 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1598 | .rpc_argp = o_arg, |
| 1599 | .rpc_resp = o_res, |
| 1600 | .rpc_cred = data->owner->so_cred, |
| 1601 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1602 | struct rpc_task_setup task_setup_data = { |
| 1603 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1604 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1605 | .callback_ops = &nfs4_open_ops, |
| 1606 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1607 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1608 | .flags = RPC_TASK_ASYNC, |
| 1609 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1610 | int status; |
| 1611 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1612 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1613 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1614 | data->rpc_done = 0; |
| 1615 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1616 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1617 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1618 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1619 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1620 | if (IS_ERR(task)) |
| 1621 | return PTR_ERR(task); |
| 1622 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1623 | if (status != 0) { |
| 1624 | data->cancelled = 1; |
| 1625 | smp_wmb(); |
| 1626 | } else |
| 1627 | status = data->rpc_status; |
| 1628 | rpc_put_task(task); |
| 1629 | |
| 1630 | return status; |
| 1631 | } |
| 1632 | |
| 1633 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1634 | { |
| 1635 | struct inode *dir = data->dir->d_inode; |
| 1636 | struct nfs_openres *o_res = &data->o_res; |
| 1637 | int status; |
| 1638 | |
| 1639 | status = nfs4_run_open_task(data, 1); |
| 1640 | if (status != 0 || !data->rpc_done) |
| 1641 | return status; |
| 1642 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1643 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1644 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1645 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1646 | status = _nfs4_proc_open_confirm(data); |
| 1647 | if (status != 0) |
| 1648 | return status; |
| 1649 | } |
| 1650 | |
| 1651 | return status; |
| 1652 | } |
| 1653 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1654 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1655 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1656 | struct nfs4_state *state, fmode_t fmode, |
| 1657 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1658 | { |
| 1659 | struct nfs_access_entry cache; |
| 1660 | u32 mask; |
| 1661 | |
| 1662 | /* access call failed or for some reason the server doesn't |
| 1663 | * support any access modes -- defer access call until later */ |
| 1664 | if (opendata->o_res.access_supported == 0) |
| 1665 | return 0; |
| 1666 | |
| 1667 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1668 | /* 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] | 1669 | * write mode bits, but POSIX allows the creating process to write. |
| 1670 | * use openflags to check for exec, because fmode won't |
| 1671 | * always have FMODE_EXEC set when file open for exec. */ |
| 1672 | if (openflags & __FMODE_EXEC) { |
| 1673 | /* ONLY check for exec rights */ |
| 1674 | mask = MAY_EXEC; |
| 1675 | } else if (fmode & FMODE_READ) |
| 1676 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1677 | |
| 1678 | cache.cred = cred; |
| 1679 | cache.jiffies = jiffies; |
| 1680 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1681 | nfs_access_add_cache(state->inode, &cache); |
| 1682 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1683 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1684 | return 0; |
| 1685 | |
| 1686 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1687 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1688 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1689 | } |
| 1690 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1691 | /* |
| 1692 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1693 | */ |
| 1694 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1695 | { |
| 1696 | struct inode *dir = data->dir->d_inode; |
| 1697 | struct nfs_server *server = NFS_SERVER(dir); |
| 1698 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1699 | struct nfs_openres *o_res = &data->o_res; |
| 1700 | int status; |
| 1701 | |
| 1702 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1703 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1704 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1705 | if (status != 0) { |
| 1706 | if (status == -NFS4ERR_BADNAME && |
| 1707 | !(o_arg->open_flags & O_CREAT)) |
| 1708 | return -ENOENT; |
| 1709 | return status; |
| 1710 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1711 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1712 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1713 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1714 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1715 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1716 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1717 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1719 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1721 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | } |
| 1723 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1724 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1725 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1728 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1729 | { |
| 1730 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1731 | } |
| 1732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | /* |
| 1734 | * OPEN_EXPIRED: |
| 1735 | * reclaim state on the server after a network partition. |
| 1736 | * Assumes caller holds the appropriate lock |
| 1737 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1738 | 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] | 1739 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1740 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1741 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 1743 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1744 | NFS4_OPEN_CLAIM_NULL); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1745 | if (IS_ERR(opendata)) |
| 1746 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1747 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1748 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1749 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1750 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1751 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1754 | 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] | 1755 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1756 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1757 | struct nfs4_exception exception = { }; |
| 1758 | int err; |
| 1759 | |
| 1760 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1761 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1762 | switch (err) { |
| 1763 | default: |
| 1764 | goto out; |
| 1765 | case -NFS4ERR_GRACE: |
| 1766 | case -NFS4ERR_DELAY: |
| 1767 | nfs4_handle_exception(server, err, &exception); |
| 1768 | err = 0; |
| 1769 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1770 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1771 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1772 | return err; |
| 1773 | } |
| 1774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1776 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1778 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | ctx = nfs4_state_find_open_context(state); |
| 1781 | if (IS_ERR(ctx)) |
| 1782 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1783 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1784 | put_nfs_open_context(ctx); |
| 1785 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1788 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1789 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1790 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1791 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1792 | nfs4_stateid *stateid = &state->stateid; |
| 1793 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1794 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1795 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1796 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1797 | return; |
| 1798 | |
| 1799 | status = nfs41_test_stateid(server, stateid); |
| 1800 | if (status != NFS_OK) { |
| 1801 | /* Free the stateid unless the server explicitly |
| 1802 | * informs us the stateid is unrecognized. */ |
| 1803 | if (status != -NFS4ERR_BAD_STATEID) |
| 1804 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1805 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1806 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1807 | write_seqlock(&state->seqlock); |
| 1808 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1809 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1810 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | /** |
| 1815 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1816 | * |
| 1817 | * @state: NFSv4 state for an inode |
| 1818 | * |
| 1819 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1820 | * Otherwise a negative NFS4ERR value is returned. |
| 1821 | */ |
| 1822 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1823 | { |
| 1824 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1825 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1826 | int status; |
| 1827 | |
| 1828 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1829 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1830 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1831 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1832 | return -NFS4ERR_BAD_STATEID; |
| 1833 | |
| 1834 | status = nfs41_test_stateid(server, stateid); |
| 1835 | if (status != NFS_OK) { |
| 1836 | /* Free the stateid unless the server explicitly |
| 1837 | * informs us the stateid is unrecognized. */ |
| 1838 | if (status != -NFS4ERR_BAD_STATEID) |
| 1839 | nfs41_free_stateid(server, stateid); |
| 1840 | |
| 1841 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1842 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1843 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1844 | } |
| 1845 | return status; |
| 1846 | } |
| 1847 | |
| 1848 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1849 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1850 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1851 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1852 | nfs41_clear_delegation_stateid(state); |
| 1853 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1854 | if (status != NFS_OK) |
| 1855 | status = nfs4_open_expired(sp, state); |
| 1856 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1857 | } |
| 1858 | #endif |
| 1859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1861 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1862 | * fields corresponding to attributes that were used to store the verifier. |
| 1863 | * Make sure we clobber those fields in the later setattr call |
| 1864 | */ |
| 1865 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1866 | { |
| 1867 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1868 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1869 | sattr->ia_valid |= ATTR_ATIME; |
| 1870 | |
| 1871 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1872 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1873 | sattr->ia_valid |= ATTR_MTIME; |
| 1874 | } |
| 1875 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1876 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1877 | fmode_t fmode, |
| 1878 | int flags, |
| 1879 | struct nfs4_state **res) |
| 1880 | { |
| 1881 | struct nfs4_state_owner *sp = opendata->owner; |
| 1882 | struct nfs_server *server = sp->so_server; |
| 1883 | struct nfs4_state *state; |
| 1884 | unsigned int seq; |
| 1885 | int ret; |
| 1886 | |
| 1887 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1888 | |
| 1889 | ret = _nfs4_proc_open(opendata); |
| 1890 | if (ret != 0) |
| 1891 | goto out; |
| 1892 | |
| 1893 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1894 | ret = PTR_ERR(state); |
| 1895 | if (IS_ERR(state)) |
| 1896 | goto out; |
| 1897 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1898 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1899 | |
| 1900 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 1901 | if (ret != 0) |
| 1902 | goto out; |
| 1903 | |
| 1904 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 1905 | nfs4_schedule_stateid_recovery(server, state); |
| 1906 | nfs4_wait_clnt_recover(server->nfs_client); |
| 1907 | } |
| 1908 | *res = state; |
| 1909 | out: |
| 1910 | return ret; |
| 1911 | } |
| 1912 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1913 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1914 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1916 | static int _nfs4_do_open(struct inode *dir, |
| 1917 | struct dentry *dentry, |
| 1918 | fmode_t fmode, |
| 1919 | int flags, |
| 1920 | struct iattr *sattr, |
| 1921 | struct rpc_cred *cred, |
| 1922 | struct nfs4_state **res, |
| 1923 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | { |
| 1925 | struct nfs4_state_owner *sp; |
| 1926 | struct nfs4_state *state = NULL; |
| 1927 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1928 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1929 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
| 1931 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1933 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1934 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1936 | goto out_err; |
| 1937 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1938 | status = nfs4_recover_expired_lease(server); |
| 1939 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1940 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1941 | if (dentry->d_inode != NULL) |
| 1942 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1943 | status = -ENOMEM; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame^] | 1944 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
| 1945 | NFS4_OPEN_CLAIM_NULL, |
| 1946 | GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1947 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1948 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1950 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1951 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1952 | if (!opendata->f_attr.mdsthreshold) |
| 1953 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1954 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1955 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1956 | if (dentry->d_inode != NULL) |
| 1957 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1958 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1959 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1960 | if (status != 0) |
| 1961 | goto err_opendata_put; |
| 1962 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1963 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1964 | nfs4_exclusive_attrset(opendata, sattr); |
| 1965 | |
| 1966 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1967 | status = nfs4_do_setattr(state->inode, cred, |
| 1968 | opendata->o_res.f_attr, sattr, |
| 1969 | state); |
| 1970 | if (status == 0) |
| 1971 | nfs_setattr_update_inode(state->inode, sattr); |
| 1972 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1973 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1974 | |
| 1975 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1976 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1977 | else |
| 1978 | kfree(opendata->f_attr.mdsthreshold); |
| 1979 | opendata->f_attr.mdsthreshold = NULL; |
| 1980 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1981 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | *res = state; |
| 1984 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1985 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1986 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1987 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1988 | err_put_state_owner: |
| 1989 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | *res = NULL; |
| 1992 | return status; |
| 1993 | } |
| 1994 | |
| 1995 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1996 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1997 | struct dentry *dentry, |
| 1998 | fmode_t fmode, |
| 1999 | int flags, |
| 2000 | struct iattr *sattr, |
| 2001 | struct rpc_cred *cred, |
| 2002 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | { |
| 2004 | struct nfs4_exception exception = { }; |
| 2005 | struct nfs4_state *res; |
| 2006 | int status; |
| 2007 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2008 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2010 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2011 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | if (status == 0) |
| 2013 | break; |
| 2014 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2015 | * book-keeping w.r.t. state-changing operations |
| 2016 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2017 | * It is actually a sign of a bug on the client or on the server. |
| 2018 | * |
| 2019 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2020 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | * have unhashed the old state_owner for us, and that we can |
| 2022 | * therefore safely retry using a new one. We should still warn |
| 2023 | * the user though... |
| 2024 | */ |
| 2025 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2026 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2027 | " returned a bad sequence-id error!\n", |
| 2028 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | exception.retry = 1; |
| 2030 | continue; |
| 2031 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2032 | /* |
| 2033 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2034 | * state before it received the OPEN_CONFIRM. |
| 2035 | * Recover by retrying the request as per the discussion |
| 2036 | * on Page 181 of RFC3530. |
| 2037 | */ |
| 2038 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2039 | exception.retry = 1; |
| 2040 | continue; |
| 2041 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2042 | if (status == -EAGAIN) { |
| 2043 | /* We must have found a delegation */ |
| 2044 | exception.retry = 1; |
| 2045 | continue; |
| 2046 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2048 | status, &exception)); |
| 2049 | } while (exception.retry); |
| 2050 | return res; |
| 2051 | } |
| 2052 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2053 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2054 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2055 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2057 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2059 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | .iap = sattr, |
| 2061 | .server = server, |
| 2062 | .bitmask = server->attr_bitmask, |
| 2063 | }; |
| 2064 | struct nfs_setattrres res = { |
| 2065 | .fattr = fattr, |
| 2066 | .server = server, |
| 2067 | }; |
| 2068 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2069 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2070 | .rpc_argp = &arg, |
| 2071 | .rpc_resp = &res, |
| 2072 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2074 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2075 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2077 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2079 | if (state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2080 | struct nfs_lockowner lockowner = { |
| 2081 | .l_owner = current->files, |
| 2082 | .l_pid = current->tgid, |
| 2083 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2084 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2085 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2086 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2087 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2088 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2089 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2090 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2092 | 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] | 2093 | if (status == 0 && state != NULL) |
| 2094 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2095 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2098 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2099 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2100 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2102 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2103 | struct nfs4_exception exception = { |
| 2104 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2105 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2106 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | int err; |
| 2108 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2109 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2110 | switch (err) { |
| 2111 | case -NFS4ERR_OPENMODE: |
| 2112 | if (state && !(state->state & FMODE_WRITE)) { |
| 2113 | err = -EBADF; |
| 2114 | if (sattr->ia_valid & ATTR_OPEN) |
| 2115 | err = -EACCES; |
| 2116 | goto out; |
| 2117 | } |
| 2118 | } |
| 2119 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2121 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | return err; |
| 2123 | } |
| 2124 | |
| 2125 | struct nfs4_closedata { |
| 2126 | struct inode *inode; |
| 2127 | struct nfs4_state *state; |
| 2128 | struct nfs_closeargs arg; |
| 2129 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2130 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2131 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2132 | bool roc; |
| 2133 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | }; |
| 2135 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2136 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2137 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2138 | struct nfs4_closedata *calldata = data; |
| 2139 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2140 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2141 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2142 | if (calldata->roc) |
| 2143 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2144 | nfs4_put_open_state(calldata->state); |
| 2145 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2146 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2147 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2148 | kfree(calldata); |
| 2149 | } |
| 2150 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2151 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2152 | fmode_t fmode) |
| 2153 | { |
| 2154 | spin_lock(&state->owner->so_lock); |
| 2155 | if (!(fmode & FMODE_READ)) |
| 2156 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2157 | if (!(fmode & FMODE_WRITE)) |
| 2158 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2159 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2160 | spin_unlock(&state->owner->so_lock); |
| 2161 | } |
| 2162 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2163 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2165 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2168 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2169 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2170 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2171 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | /* hmm. we are done with the inode, and in the process of freeing |
| 2173 | * the state_owner. we keep this around to process errors |
| 2174 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | switch (task->tk_status) { |
| 2176 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2177 | if (calldata->roc) |
| 2178 | pnfs_roc_set_barrier(state->inode, |
| 2179 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2180 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2181 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2182 | nfs4_close_clear_stateid_flags(state, |
| 2183 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | break; |
| 2185 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2186 | case -NFS4ERR_OLD_STATEID: |
| 2187 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2189 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2190 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2192 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2193 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2195 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2196 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2197 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2200 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2202 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2203 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2204 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2205 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2206 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2207 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2208 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2209 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2210 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2211 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2212 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2213 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2214 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2215 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2216 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2217 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2218 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2219 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2220 | } |
| 2221 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2222 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2223 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2224 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2225 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2226 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2227 | if (!nfs4_valid_open_stateid(state)) |
| 2228 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2229 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2230 | |
| 2231 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2232 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2233 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2234 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2235 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2236 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2237 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2238 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2239 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2240 | goto out_wait; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2241 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2242 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2243 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2244 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2245 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2246 | &calldata->arg.seq_args, |
| 2247 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2248 | task) != 0) |
| 2249 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2250 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2251 | return; |
| 2252 | out_no_action: |
| 2253 | task->tk_action = NULL; |
| 2254 | out_wait: |
| 2255 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2258 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2259 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2260 | .rpc_call_done = nfs4_close_done, |
| 2261 | .rpc_release = nfs4_free_closedata, |
| 2262 | }; |
| 2263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | /* |
| 2265 | * It is possible for data to be read/written from a mem-mapped file |
| 2266 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2267 | * This means that we can't safely call nfsv4 close on a file until |
| 2268 | * the inode is cleared. This in turn means that we are not good |
| 2269 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2270 | * share state even when we are done with one of the three share |
| 2271 | * stateid's in the inode. |
| 2272 | * |
| 2273 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2274 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2275 | 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] | 2276 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2277 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2279 | struct nfs4_state_owner *sp = state->owner; |
| 2280 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2281 | struct rpc_message msg = { |
| 2282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2283 | .rpc_cred = state->owner->so_cred, |
| 2284 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2285 | struct rpc_task_setup task_setup_data = { |
| 2286 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2287 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2288 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2289 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2290 | .flags = RPC_TASK_ASYNC, |
| 2291 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2292 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2294 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2296 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2297 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2298 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2300 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2301 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2303 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2304 | if (calldata->arg.seqid == NULL) |
| 2305 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2306 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2307 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2308 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2309 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2310 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2311 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2312 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2313 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2314 | msg.rpc_argp = &calldata->arg; |
| 2315 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2316 | task_setup_data.callback_data = calldata; |
| 2317 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2318 | if (IS_ERR(task)) |
| 2319 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2320 | status = 0; |
| 2321 | if (wait) |
| 2322 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2323 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2324 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2325 | out_free_calldata: |
| 2326 | kfree(calldata); |
| 2327 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2328 | nfs4_put_open_state(state); |
| 2329 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2330 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2333 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2334 | 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] | 2335 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | struct nfs4_state *state; |
| 2337 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2338 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2339 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2340 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2341 | if (IS_ERR(state)) |
| 2342 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2343 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2344 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2347 | 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] | 2348 | { |
| 2349 | if (ctx->state == NULL) |
| 2350 | return; |
| 2351 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2352 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2353 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2354 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | |
| 2357 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2358 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2359 | struct nfs4_server_caps_arg args = { |
| 2360 | .fhandle = fhandle, |
| 2361 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | struct nfs4_server_caps_res res = {}; |
| 2363 | struct rpc_message msg = { |
| 2364 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2365 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | .rpc_resp = &res, |
| 2367 | }; |
| 2368 | int status; |
| 2369 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2370 | 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] | 2371 | if (status == 0) { |
| 2372 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2373 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2374 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2375 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2376 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2377 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2379 | server->caps |= NFS_CAP_ACLS; |
| 2380 | if (res.has_links != 0) |
| 2381 | server->caps |= NFS_CAP_HARDLINKS; |
| 2382 | if (res.has_symlinks != 0) |
| 2383 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2384 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2385 | server->caps |= NFS_CAP_FILEID; |
| 2386 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2387 | server->caps |= NFS_CAP_MODE; |
| 2388 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2389 | server->caps |= NFS_CAP_NLINK; |
| 2390 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2391 | server->caps |= NFS_CAP_OWNER; |
| 2392 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2393 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2394 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2395 | server->caps |= NFS_CAP_ATIME; |
| 2396 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2397 | server->caps |= NFS_CAP_CTIME; |
| 2398 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2399 | server->caps |= NFS_CAP_MTIME; |
| 2400 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2401 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2402 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2403 | 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] | 2404 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2405 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | return status; |
| 2409 | } |
| 2410 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2411 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | { |
| 2413 | struct nfs4_exception exception = { }; |
| 2414 | int err; |
| 2415 | do { |
| 2416 | err = nfs4_handle_exception(server, |
| 2417 | _nfs4_server_capabilities(server, fhandle), |
| 2418 | &exception); |
| 2419 | } while (exception.retry); |
| 2420 | return err; |
| 2421 | } |
| 2422 | |
| 2423 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2424 | struct nfs_fsinfo *info) |
| 2425 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | struct nfs4_lookup_root_arg args = { |
| 2427 | .bitmask = nfs4_fattr_bitmap, |
| 2428 | }; |
| 2429 | struct nfs4_lookup_res res = { |
| 2430 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2431 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | .fh = fhandle, |
| 2433 | }; |
| 2434 | struct rpc_message msg = { |
| 2435 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2436 | .rpc_argp = &args, |
| 2437 | .rpc_resp = &res, |
| 2438 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2439 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2440 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2441 | 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] | 2442 | } |
| 2443 | |
| 2444 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2445 | struct nfs_fsinfo *info) |
| 2446 | { |
| 2447 | struct nfs4_exception exception = { }; |
| 2448 | int err; |
| 2449 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2450 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2451 | switch (err) { |
| 2452 | case 0: |
| 2453 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2454 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2455 | default: |
| 2456 | err = nfs4_handle_exception(server, err, &exception); |
| 2457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2459 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | return err; |
| 2461 | } |
| 2462 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2463 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2464 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2465 | { |
| 2466 | struct rpc_auth *auth; |
| 2467 | int ret; |
| 2468 | |
| 2469 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2470 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2471 | ret = -EIO; |
| 2472 | goto out; |
| 2473 | } |
| 2474 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2475 | out: |
| 2476 | return ret; |
| 2477 | } |
| 2478 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2479 | 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] | 2480 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2482 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2483 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2485 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2486 | if (len < 0) |
| 2487 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2488 | |
| 2489 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2490 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2491 | * thus has already been tried. */ |
| 2492 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2493 | continue; |
| 2494 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2495 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2496 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2497 | continue; |
| 2498 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2499 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2500 | /* |
| 2501 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2502 | * to access the mount. It could also mean that we tried to mount |
| 2503 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2504 | * existing mount programs don't handle -EACCES very well so it should |
| 2505 | * be mapped to -EPERM instead. |
| 2506 | */ |
| 2507 | if (status == -EACCES) |
| 2508 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2509 | return status; |
| 2510 | } |
| 2511 | |
| 2512 | /* |
| 2513 | * get the file handle for the "/" directory on the server |
| 2514 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2515 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2516 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2517 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2518 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2519 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2520 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2521 | /* |
| 2522 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2523 | * by nfs4_map_errors() as this function exits. |
| 2524 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2525 | 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] | 2526 | if (status == 0) |
| 2527 | status = nfs4_server_capabilities(server, fhandle); |
| 2528 | if (status == 0) |
| 2529 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2530 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2533 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2534 | struct nfs_fsinfo *info) |
| 2535 | { |
| 2536 | int error; |
| 2537 | struct nfs_fattr *fattr = info->fattr; |
| 2538 | |
| 2539 | error = nfs4_server_capabilities(server, mntfh); |
| 2540 | if (error < 0) { |
| 2541 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2542 | return error; |
| 2543 | } |
| 2544 | |
| 2545 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2546 | if (error < 0) { |
| 2547 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2548 | return error; |
| 2549 | } |
| 2550 | |
| 2551 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2552 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2553 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2554 | |
| 2555 | return error; |
| 2556 | } |
| 2557 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2558 | /* |
| 2559 | * Get locations and (maybe) other attributes of a referral. |
| 2560 | * Note that we'll actually follow the referral later when |
| 2561 | * we detect fsid mismatch in inode revalidation |
| 2562 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2563 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2564 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2565 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2566 | { |
| 2567 | int status = -ENOMEM; |
| 2568 | struct page *page = NULL; |
| 2569 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2570 | |
| 2571 | page = alloc_page(GFP_KERNEL); |
| 2572 | if (page == NULL) |
| 2573 | goto out; |
| 2574 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2575 | if (locations == NULL) |
| 2576 | goto out; |
| 2577 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2578 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2579 | if (status != 0) |
| 2580 | goto out; |
| 2581 | /* Make sure server returned a different fsid for the referral */ |
| 2582 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2583 | dprintk("%s: server did not return a different fsid for" |
| 2584 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2585 | status = -EIO; |
| 2586 | goto out; |
| 2587 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2588 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2589 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2590 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2591 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2592 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2593 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2594 | out: |
| 2595 | if (page) |
| 2596 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2597 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2598 | return status; |
| 2599 | } |
| 2600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2602 | { |
| 2603 | struct nfs4_getattr_arg args = { |
| 2604 | .fh = fhandle, |
| 2605 | .bitmask = server->attr_bitmask, |
| 2606 | }; |
| 2607 | struct nfs4_getattr_res res = { |
| 2608 | .fattr = fattr, |
| 2609 | .server = server, |
| 2610 | }; |
| 2611 | struct rpc_message msg = { |
| 2612 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2613 | .rpc_argp = &args, |
| 2614 | .rpc_resp = &res, |
| 2615 | }; |
| 2616 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2617 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2618 | 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] | 2619 | } |
| 2620 | |
| 2621 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2622 | { |
| 2623 | struct nfs4_exception exception = { }; |
| 2624 | int err; |
| 2625 | do { |
| 2626 | err = nfs4_handle_exception(server, |
| 2627 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2628 | &exception); |
| 2629 | } while (exception.retry); |
| 2630 | return err; |
| 2631 | } |
| 2632 | |
| 2633 | /* |
| 2634 | * The file is not closed if it is opened due to the a request to change |
| 2635 | * the size of the file. The open call will not be needed once the |
| 2636 | * VFS layer lookup-intents are implemented. |
| 2637 | * |
| 2638 | * Close is called when the inode is destroyed. |
| 2639 | * If we haven't opened the file for O_WRONLY, we |
| 2640 | * need to in the size_change case to obtain a stateid. |
| 2641 | * |
| 2642 | * Got race? |
| 2643 | * Because OPEN is always done by name in nfsv4, it is |
| 2644 | * possible that we opened a different file by the same |
| 2645 | * name. We can recognize this race condition, but we |
| 2646 | * can't do anything about it besides returning an error. |
| 2647 | * |
| 2648 | * This will be fixed with VFS changes (lookup-intent). |
| 2649 | */ |
| 2650 | static int |
| 2651 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2652 | struct iattr *sattr) |
| 2653 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2654 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2655 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2656 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | int status; |
| 2658 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2659 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2660 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2661 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2662 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2664 | /* Deal with open(O_TRUNC) */ |
| 2665 | if (sattr->ia_valid & ATTR_OPEN) |
| 2666 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2667 | |
| 2668 | /* Optimization: if the end result is no change, don't RPC */ |
| 2669 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2670 | return 0; |
| 2671 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2672 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2673 | if (sattr->ia_valid & ATTR_FILE) { |
| 2674 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2675 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2676 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2677 | if (ctx) { |
| 2678 | cred = ctx->cred; |
| 2679 | state = ctx->state; |
| 2680 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2684 | if (status == 0) |
| 2685 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | return status; |
| 2687 | } |
| 2688 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2689 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2690 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2691 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2692 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2693 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2694 | int status; |
| 2695 | struct nfs4_lookup_arg args = { |
| 2696 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2697 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2698 | .name = name, |
| 2699 | }; |
| 2700 | struct nfs4_lookup_res res = { |
| 2701 | .server = server, |
| 2702 | .fattr = fattr, |
| 2703 | .fh = fhandle, |
| 2704 | }; |
| 2705 | struct rpc_message msg = { |
| 2706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2707 | .rpc_argp = &args, |
| 2708 | .rpc_resp = &res, |
| 2709 | }; |
| 2710 | |
| 2711 | nfs_fattr_init(fattr); |
| 2712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2714 | 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] | 2715 | dprintk("NFS reply lookup: %d\n", status); |
| 2716 | return status; |
| 2717 | } |
| 2718 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2719 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2720 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2721 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2722 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2723 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2724 | fattr->nlink = 2; |
| 2725 | } |
| 2726 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2727 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2728 | struct qstr *name, struct nfs_fh *fhandle, |
| 2729 | struct nfs_fattr *fattr) |
| 2730 | { |
| 2731 | struct nfs4_exception exception = { }; |
| 2732 | struct rpc_clnt *client = *clnt; |
| 2733 | int err; |
| 2734 | do { |
| 2735 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2736 | switch (err) { |
| 2737 | case -NFS4ERR_BADNAME: |
| 2738 | err = -ENOENT; |
| 2739 | goto out; |
| 2740 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2741 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2742 | goto out; |
| 2743 | case -NFS4ERR_WRONGSEC: |
| 2744 | err = -EPERM; |
| 2745 | if (client != *clnt) |
| 2746 | goto out; |
| 2747 | |
| 2748 | client = nfs4_create_sec_client(client, dir, name); |
| 2749 | if (IS_ERR(client)) |
| 2750 | return PTR_ERR(client); |
| 2751 | |
| 2752 | exception.retry = 1; |
| 2753 | break; |
| 2754 | default: |
| 2755 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2756 | } |
| 2757 | } while (exception.retry); |
| 2758 | |
| 2759 | out: |
| 2760 | if (err == 0) |
| 2761 | *clnt = client; |
| 2762 | else if (client != *clnt) |
| 2763 | rpc_shutdown_client(client); |
| 2764 | |
| 2765 | return err; |
| 2766 | } |
| 2767 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2768 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2769 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2771 | int status; |
| 2772 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2773 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2774 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2775 | if (client != NFS_CLIENT(dir)) { |
| 2776 | rpc_shutdown_client(client); |
| 2777 | nfs_fixup_secinfo_attributes(fattr); |
| 2778 | } |
| 2779 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2782 | struct rpc_clnt * |
| 2783 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2784 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2785 | { |
| 2786 | int status; |
| 2787 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2788 | |
| 2789 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2790 | if (status < 0) { |
| 2791 | rpc_shutdown_client(client); |
| 2792 | return ERR_PTR(status); |
| 2793 | } |
| 2794 | return client; |
| 2795 | } |
| 2796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2798 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2799 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | struct nfs4_accessargs args = { |
| 2801 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2802 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2804 | struct nfs4_accessres res = { |
| 2805 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2806 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | struct rpc_message msg = { |
| 2808 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2809 | .rpc_argp = &args, |
| 2810 | .rpc_resp = &res, |
| 2811 | .rpc_cred = entry->cred, |
| 2812 | }; |
| 2813 | int mode = entry->mask; |
| 2814 | int status; |
| 2815 | |
| 2816 | /* |
| 2817 | * Determine which access bits we want to ask for... |
| 2818 | */ |
| 2819 | if (mode & MAY_READ) |
| 2820 | args.access |= NFS4_ACCESS_READ; |
| 2821 | if (S_ISDIR(inode->i_mode)) { |
| 2822 | if (mode & MAY_WRITE) |
| 2823 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2824 | if (mode & MAY_EXEC) |
| 2825 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2826 | } else { |
| 2827 | if (mode & MAY_WRITE) |
| 2828 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2829 | if (mode & MAY_EXEC) |
| 2830 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2831 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2832 | |
| 2833 | res.fattr = nfs_alloc_fattr(); |
| 2834 | if (res.fattr == NULL) |
| 2835 | return -ENOMEM; |
| 2836 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2837 | 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] | 2838 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2839 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2840 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2842 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | return status; |
| 2844 | } |
| 2845 | |
| 2846 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2847 | { |
| 2848 | struct nfs4_exception exception = { }; |
| 2849 | int err; |
| 2850 | do { |
| 2851 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2852 | _nfs4_proc_access(inode, entry), |
| 2853 | &exception); |
| 2854 | } while (exception.retry); |
| 2855 | return err; |
| 2856 | } |
| 2857 | |
| 2858 | /* |
| 2859 | * TODO: For the time being, we don't try to get any attributes |
| 2860 | * along with any of the zero-copy operations READ, READDIR, |
| 2861 | * READLINK, WRITE. |
| 2862 | * |
| 2863 | * In the case of the first three, we want to put the GETATTR |
| 2864 | * after the read-type operation -- this is because it is hard |
| 2865 | * to predict the length of a GETATTR response in v4, and thus |
| 2866 | * align the READ data correctly. This means that the GETATTR |
| 2867 | * may end up partially falling into the page cache, and we should |
| 2868 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2869 | * To do this efficiently, we need to know the total length |
| 2870 | * of data received, which doesn't seem to be available outside |
| 2871 | * of the RPC layer. |
| 2872 | * |
| 2873 | * In the case of WRITE, we also want to put the GETATTR after |
| 2874 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2875 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | * |
| 2877 | * Both of these changes to the XDR layer would in fact be quite |
| 2878 | * minor, but I decided to leave them for a subsequent patch. |
| 2879 | */ |
| 2880 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2881 | unsigned int pgbase, unsigned int pglen) |
| 2882 | { |
| 2883 | struct nfs4_readlink args = { |
| 2884 | .fh = NFS_FH(inode), |
| 2885 | .pgbase = pgbase, |
| 2886 | .pglen = pglen, |
| 2887 | .pages = &page, |
| 2888 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2889 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | struct rpc_message msg = { |
| 2891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2892 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2893 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | }; |
| 2895 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2896 | 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] | 2897 | } |
| 2898 | |
| 2899 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2900 | unsigned int pgbase, unsigned int pglen) |
| 2901 | { |
| 2902 | struct nfs4_exception exception = { }; |
| 2903 | int err; |
| 2904 | do { |
| 2905 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2906 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2907 | &exception); |
| 2908 | } while (exception.retry); |
| 2909 | return err; |
| 2910 | } |
| 2911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2913 | * 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] | 2914 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | static int |
| 2916 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2917 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2919 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | int status = 0; |
| 2922 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2923 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2924 | if (IS_ERR(ctx)) |
| 2925 | return PTR_ERR(ctx); |
| 2926 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2927 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2928 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2929 | flags, sattr, ctx->cred, |
| 2930 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2931 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | if (IS_ERR(state)) { |
| 2933 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2934 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2936 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2937 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2938 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2940 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | return status; |
| 2942 | } |
| 2943 | |
| 2944 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2945 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2946 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2947 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2949 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2951 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2952 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2953 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2956 | .rpc_argp = &args, |
| 2957 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2959 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2960 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2961 | 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] | 2962 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2963 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | return status; |
| 2965 | } |
| 2966 | |
| 2967 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2968 | { |
| 2969 | struct nfs4_exception exception = { }; |
| 2970 | int err; |
| 2971 | do { |
| 2972 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2973 | _nfs4_proc_remove(dir, name), |
| 2974 | &exception); |
| 2975 | } while (exception.retry); |
| 2976 | return err; |
| 2977 | } |
| 2978 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2979 | 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] | 2980 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2981 | struct nfs_server *server = NFS_SERVER(dir); |
| 2982 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2983 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2985 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2987 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2990 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2991 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2992 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2993 | &data->args.seq_args, |
| 2994 | &data->res.seq_res, |
| 2995 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2998 | 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] | 2999 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3000 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3001 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3002 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3003 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3004 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3005 | return 0; |
| 3006 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3007 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3010 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3011 | { |
| 3012 | struct nfs_server *server = NFS_SERVER(dir); |
| 3013 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3014 | struct nfs_renameres *res = msg->rpc_resp; |
| 3015 | |
| 3016 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3017 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3018 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3019 | } |
| 3020 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3021 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3022 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3023 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3024 | &data->args.seq_args, |
| 3025 | &data->res.seq_res, |
| 3026 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3030 | struct inode *new_dir) |
| 3031 | { |
| 3032 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3033 | |
| 3034 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3035 | return 0; |
| 3036 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3037 | return 0; |
| 3038 | |
| 3039 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3040 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3041 | return 1; |
| 3042 | } |
| 3043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3045 | struct inode *new_dir, struct qstr *new_name) |
| 3046 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3047 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3048 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | .old_dir = NFS_FH(old_dir), |
| 3050 | .new_dir = NFS_FH(new_dir), |
| 3051 | .old_name = old_name, |
| 3052 | .new_name = new_name, |
| 3053 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3054 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3055 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3056 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | struct rpc_message msg = { |
| 3058 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3059 | .rpc_argp = &arg, |
| 3060 | .rpc_resp = &res, |
| 3061 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3062 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3064 | 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] | 3065 | if (!status) { |
| 3066 | update_changeattr(old_dir, &res.old_cinfo); |
| 3067 | update_changeattr(new_dir, &res.new_cinfo); |
| 3068 | } |
| 3069 | return status; |
| 3070 | } |
| 3071 | |
| 3072 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3073 | struct inode *new_dir, struct qstr *new_name) |
| 3074 | { |
| 3075 | struct nfs4_exception exception = { }; |
| 3076 | int err; |
| 3077 | do { |
| 3078 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3079 | _nfs4_proc_rename(old_dir, old_name, |
| 3080 | new_dir, new_name), |
| 3081 | &exception); |
| 3082 | } while (exception.retry); |
| 3083 | return err; |
| 3084 | } |
| 3085 | |
| 3086 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3087 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3088 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | struct nfs4_link_arg arg = { |
| 3090 | .fh = NFS_FH(inode), |
| 3091 | .dir_fh = NFS_FH(dir), |
| 3092 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3093 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3095 | struct nfs4_link_res res = { |
| 3096 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3097 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | struct rpc_message msg = { |
| 3099 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3100 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3101 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3103 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3105 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3106 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3107 | goto out; |
| 3108 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3109 | 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] | 3110 | if (!status) { |
| 3111 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3112 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3113 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3114 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3115 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | return status; |
| 3117 | } |
| 3118 | |
| 3119 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3120 | { |
| 3121 | struct nfs4_exception exception = { }; |
| 3122 | int err; |
| 3123 | do { |
| 3124 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3125 | _nfs4_proc_link(inode, dir, name), |
| 3126 | &exception); |
| 3127 | } while (exception.retry); |
| 3128 | return err; |
| 3129 | } |
| 3130 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3131 | struct nfs4_createdata { |
| 3132 | struct rpc_message msg; |
| 3133 | struct nfs4_create_arg arg; |
| 3134 | struct nfs4_create_res res; |
| 3135 | struct nfs_fh fh; |
| 3136 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3137 | }; |
| 3138 | |
| 3139 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3140 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3141 | { |
| 3142 | struct nfs4_createdata *data; |
| 3143 | |
| 3144 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3145 | if (data != NULL) { |
| 3146 | struct nfs_server *server = NFS_SERVER(dir); |
| 3147 | |
| 3148 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3149 | data->msg.rpc_argp = &data->arg; |
| 3150 | data->msg.rpc_resp = &data->res; |
| 3151 | data->arg.dir_fh = NFS_FH(dir); |
| 3152 | data->arg.server = server; |
| 3153 | data->arg.name = name; |
| 3154 | data->arg.attrs = sattr; |
| 3155 | data->arg.ftype = ftype; |
| 3156 | data->arg.bitmask = server->attr_bitmask; |
| 3157 | data->res.server = server; |
| 3158 | data->res.fh = &data->fh; |
| 3159 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3160 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3161 | } |
| 3162 | return data; |
| 3163 | } |
| 3164 | |
| 3165 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3166 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3167 | 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] | 3168 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3169 | if (status == 0) { |
| 3170 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3171 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3172 | } |
| 3173 | return status; |
| 3174 | } |
| 3175 | |
| 3176 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3177 | { |
| 3178 | kfree(data); |
| 3179 | } |
| 3180 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3181 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3182 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3184 | struct nfs4_createdata *data; |
| 3185 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3187 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3188 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3189 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3190 | status = -ENOMEM; |
| 3191 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3192 | if (data == NULL) |
| 3193 | goto out; |
| 3194 | |
| 3195 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3196 | data->arg.u.symlink.pages = &page; |
| 3197 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 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 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3206 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3207 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | { |
| 3209 | struct nfs4_exception exception = { }; |
| 3210 | int err; |
| 3211 | do { |
| 3212 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3213 | _nfs4_proc_symlink(dir, dentry, page, |
| 3214 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | &exception); |
| 3216 | } while (exception.retry); |
| 3217 | return err; |
| 3218 | } |
| 3219 | |
| 3220 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3221 | struct iattr *sattr) |
| 3222 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3223 | struct nfs4_createdata *data; |
| 3224 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3226 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3227 | if (data == NULL) |
| 3228 | goto out; |
| 3229 | |
| 3230 | status = nfs4_do_create(dir, dentry, data); |
| 3231 | |
| 3232 | nfs4_free_createdata(data); |
| 3233 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | return status; |
| 3235 | } |
| 3236 | |
| 3237 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3238 | struct iattr *sattr) |
| 3239 | { |
| 3240 | struct nfs4_exception exception = { }; |
| 3241 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3242 | |
| 3243 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | do { |
| 3245 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3246 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3247 | &exception); |
| 3248 | } while (exception.retry); |
| 3249 | return err; |
| 3250 | } |
| 3251 | |
| 3252 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3253 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | { |
| 3255 | struct inode *dir = dentry->d_inode; |
| 3256 | struct nfs4_readdir_arg args = { |
| 3257 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3258 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | .pgbase = 0, |
| 3260 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3261 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3262 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | }; |
| 3264 | struct nfs4_readdir_res res; |
| 3265 | struct rpc_message msg = { |
| 3266 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3267 | .rpc_argp = &args, |
| 3268 | .rpc_resp = &res, |
| 3269 | .rpc_cred = cred, |
| 3270 | }; |
| 3271 | int status; |
| 3272 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3273 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3274 | dentry->d_parent->d_name.name, |
| 3275 | dentry->d_name.name, |
| 3276 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3277 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3279 | 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] | 3280 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3281 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3282 | status += args.pgbase; |
| 3283 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3284 | |
| 3285 | nfs_invalidate_atime(dir); |
| 3286 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3287 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | return status; |
| 3289 | } |
| 3290 | |
| 3291 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3292 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | { |
| 3294 | struct nfs4_exception exception = { }; |
| 3295 | int err; |
| 3296 | do { |
| 3297 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3298 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3299 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | &exception); |
| 3301 | } while (exception.retry); |
| 3302 | return err; |
| 3303 | } |
| 3304 | |
| 3305 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3306 | struct iattr *sattr, dev_t rdev) |
| 3307 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3308 | struct nfs4_createdata *data; |
| 3309 | int mode = sattr->ia_mode; |
| 3310 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3312 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3313 | if (data == NULL) |
| 3314 | goto out; |
| 3315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3317 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3319 | data->arg.ftype = NF4BLK; |
| 3320 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3321 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | } |
| 3323 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3324 | data->arg.ftype = NF4CHR; |
| 3325 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3326 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3327 | } else if (!S_ISSOCK(mode)) { |
| 3328 | status = -EINVAL; |
| 3329 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3332 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3333 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3334 | nfs4_free_createdata(data); |
| 3335 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | return status; |
| 3337 | } |
| 3338 | |
| 3339 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3340 | struct iattr *sattr, dev_t rdev) |
| 3341 | { |
| 3342 | struct nfs4_exception exception = { }; |
| 3343 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3344 | |
| 3345 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | do { |
| 3347 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3348 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3349 | &exception); |
| 3350 | } while (exception.retry); |
| 3351 | return err; |
| 3352 | } |
| 3353 | |
| 3354 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3355 | struct nfs_fsstat *fsstat) |
| 3356 | { |
| 3357 | struct nfs4_statfs_arg args = { |
| 3358 | .fh = fhandle, |
| 3359 | .bitmask = server->attr_bitmask, |
| 3360 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3361 | struct nfs4_statfs_res res = { |
| 3362 | .fsstat = fsstat, |
| 3363 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | struct rpc_message msg = { |
| 3365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3366 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3367 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | }; |
| 3369 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3370 | nfs_fattr_init(fsstat->fattr); |
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_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3375 | { |
| 3376 | struct nfs4_exception exception = { }; |
| 3377 | int err; |
| 3378 | do { |
| 3379 | err = nfs4_handle_exception(server, |
| 3380 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3381 | &exception); |
| 3382 | } while (exception.retry); |
| 3383 | return err; |
| 3384 | } |
| 3385 | |
| 3386 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3387 | struct nfs_fsinfo *fsinfo) |
| 3388 | { |
| 3389 | struct nfs4_fsinfo_arg args = { |
| 3390 | .fh = fhandle, |
| 3391 | .bitmask = server->attr_bitmask, |
| 3392 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3393 | struct nfs4_fsinfo_res res = { |
| 3394 | .fsinfo = fsinfo, |
| 3395 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | struct rpc_message msg = { |
| 3397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3398 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3399 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | }; |
| 3401 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3402 | 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] | 3403 | } |
| 3404 | |
| 3405 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3406 | { |
| 3407 | struct nfs4_exception exception = { }; |
| 3408 | int err; |
| 3409 | |
| 3410 | do { |
| 3411 | err = nfs4_handle_exception(server, |
| 3412 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3413 | &exception); |
| 3414 | } while (exception.retry); |
| 3415 | return err; |
| 3416 | } |
| 3417 | |
| 3418 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3419 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3420 | int error; |
| 3421 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3422 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3423 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3424 | if (error == 0) { |
| 3425 | /* block layout checks this! */ |
| 3426 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3427 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3428 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3429 | |
| 3430 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3434 | struct nfs_pathconf *pathconf) |
| 3435 | { |
| 3436 | struct nfs4_pathconf_arg args = { |
| 3437 | .fh = fhandle, |
| 3438 | .bitmask = server->attr_bitmask, |
| 3439 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3440 | struct nfs4_pathconf_res res = { |
| 3441 | .pathconf = pathconf, |
| 3442 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | struct rpc_message msg = { |
| 3444 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3445 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3446 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | }; |
| 3448 | |
| 3449 | /* None of the pathconf attributes are mandatory to implement */ |
| 3450 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3451 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3452 | return 0; |
| 3453 | } |
| 3454 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3455 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3456 | 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] | 3457 | } |
| 3458 | |
| 3459 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3460 | struct nfs_pathconf *pathconf) |
| 3461 | { |
| 3462 | struct nfs4_exception exception = { }; |
| 3463 | int err; |
| 3464 | |
| 3465 | do { |
| 3466 | err = nfs4_handle_exception(server, |
| 3467 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3468 | &exception); |
| 3469 | } while (exception.retry); |
| 3470 | return err; |
| 3471 | } |
| 3472 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3473 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3474 | const struct nfs_open_context *ctx, |
| 3475 | const struct nfs_lock_context *l_ctx, |
| 3476 | fmode_t fmode) |
| 3477 | { |
| 3478 | const struct nfs_lockowner *lockowner = NULL; |
| 3479 | |
| 3480 | if (l_ctx != NULL) |
| 3481 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3482 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3483 | } |
| 3484 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3485 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3486 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3487 | const struct nfs_open_context *ctx, |
| 3488 | const struct nfs_lock_context *l_ctx, |
| 3489 | fmode_t fmode) |
| 3490 | { |
| 3491 | nfs4_stateid current_stateid; |
| 3492 | |
| 3493 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3494 | return false; |
| 3495 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3496 | } |
| 3497 | |
| 3498 | static bool nfs4_error_stateid_expired(int err) |
| 3499 | { |
| 3500 | switch (err) { |
| 3501 | case -NFS4ERR_DELEG_REVOKED: |
| 3502 | case -NFS4ERR_ADMIN_REVOKED: |
| 3503 | case -NFS4ERR_BAD_STATEID: |
| 3504 | case -NFS4ERR_STALE_STATEID: |
| 3505 | case -NFS4ERR_OLD_STATEID: |
| 3506 | case -NFS4ERR_OPENMODE: |
| 3507 | case -NFS4ERR_EXPIRED: |
| 3508 | return true; |
| 3509 | } |
| 3510 | return false; |
| 3511 | } |
| 3512 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3513 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3514 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3515 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3516 | } |
| 3517 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3518 | 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] | 3519 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3520 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3522 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3523 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3524 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3526 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3527 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3529 | renew_lease(server, data->timestamp); |
| 3530 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3533 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3534 | struct nfs_readargs *args) |
| 3535 | { |
| 3536 | |
| 3537 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3538 | nfs4_stateid_is_current(&args->stateid, |
| 3539 | args->context, |
| 3540 | args->lock_context, |
| 3541 | FMODE_READ)) |
| 3542 | return false; |
| 3543 | rpc_restart_call_prepare(task); |
| 3544 | return true; |
| 3545 | } |
| 3546 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3547 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3548 | { |
| 3549 | |
| 3550 | dprintk("--> %s\n", __func__); |
| 3551 | |
| 3552 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3553 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3554 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3555 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3556 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3557 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3560 | 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] | 3561 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3563 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3564 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3565 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | } |
| 3567 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3568 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3569 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3570 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3571 | &data->args.seq_args, |
| 3572 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3573 | task)) |
| 3574 | return; |
| 3575 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3576 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3579 | static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3581 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3583 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3584 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3585 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3587 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3589 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3590 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3591 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3594 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3595 | struct nfs_writeargs *args) |
| 3596 | { |
| 3597 | |
| 3598 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3599 | nfs4_stateid_is_current(&args->stateid, |
| 3600 | args->context, |
| 3601 | args->lock_context, |
| 3602 | FMODE_WRITE)) |
| 3603 | return false; |
| 3604 | rpc_restart_call_prepare(task); |
| 3605 | return true; |
| 3606 | } |
| 3607 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3608 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3609 | { |
| 3610 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3611 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3612 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3613 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3614 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3615 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3618 | static |
| 3619 | 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] | 3620 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3621 | const struct nfs_pgio_header *hdr = data->header; |
| 3622 | |
| 3623 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3624 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3625 | return false; |
| 3626 | /* Otherwise, request attributes if and only if we don't hold |
| 3627 | * a delegation |
| 3628 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3629 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3630 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3631 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3632 | 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] | 3633 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3634 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3635 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3636 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3637 | data->args.bitmask = NULL; |
| 3638 | data->res.fattr = NULL; |
| 3639 | } else |
| 3640 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3641 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3642 | if (!data->write_done_cb) |
| 3643 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3644 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | data->timestamp = jiffies; |
| 3646 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3647 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3648 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3651 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3652 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3653 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3654 | &data->args.seq_args, |
| 3655 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3656 | task)) |
| 3657 | return; |
| 3658 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3659 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3662 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3663 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3664 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3665 | &data->args.seq_args, |
| 3666 | &data->res.seq_res, |
| 3667 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3670 | 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] | 3671 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3673 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3674 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3675 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3676 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3678 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | } |
| 3680 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3681 | 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] | 3682 | { |
| 3683 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3684 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3685 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3686 | } |
| 3687 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3688 | 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] | 3689 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3690 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3691 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3692 | if (data->commit_done_cb == NULL) |
| 3693 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3694 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3695 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3696 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | } |
| 3698 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3699 | struct nfs4_renewdata { |
| 3700 | struct nfs_client *client; |
| 3701 | unsigned long timestamp; |
| 3702 | }; |
| 3703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | /* |
| 3705 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3706 | * standalone procedure for queueing an asynchronous RENEW. |
| 3707 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3708 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3709 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3710 | struct nfs4_renewdata *data = calldata; |
| 3711 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3712 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3713 | if (atomic_read(&clp->cl_count) > 1) |
| 3714 | nfs4_schedule_state_renewal(clp); |
| 3715 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3716 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3717 | } |
| 3718 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3719 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3721 | struct nfs4_renewdata *data = calldata; |
| 3722 | struct nfs_client *clp = data->client; |
| 3723 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | |
| 3725 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3726 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3727 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3728 | return; |
| 3729 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3730 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3731 | return; |
| 3732 | } |
| 3733 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3735 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | } |
| 3737 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3738 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3739 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3740 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3741 | }; |
| 3742 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3743 | 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] | 3744 | { |
| 3745 | struct rpc_message msg = { |
| 3746 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3747 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3748 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3750 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3752 | if (renew_flags == 0) |
| 3753 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3754 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3755 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3756 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3757 | if (data == NULL) |
| 3758 | return -ENOMEM; |
| 3759 | data->client = clp; |
| 3760 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3762 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3765 | 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] | 3766 | { |
| 3767 | struct rpc_message msg = { |
| 3768 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3769 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3770 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | }; |
| 3772 | unsigned long now = jiffies; |
| 3773 | int status; |
| 3774 | |
| 3775 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3776 | if (status < 0) |
| 3777 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3778 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | return 0; |
| 3780 | } |
| 3781 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3782 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3783 | { |
| 3784 | return (server->caps & NFS_CAP_ACLS) |
| 3785 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3786 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3787 | } |
| 3788 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3789 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3790 | * 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] | 3791 | * the stack. |
| 3792 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3793 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3794 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3795 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3796 | struct page **pages, unsigned int *pgbase) |
| 3797 | { |
| 3798 | struct page *newpage, **spages; |
| 3799 | int rc = 0; |
| 3800 | size_t len; |
| 3801 | spages = pages; |
| 3802 | |
| 3803 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3804 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3805 | newpage = alloc_page(GFP_KERNEL); |
| 3806 | |
| 3807 | if (newpage == NULL) |
| 3808 | goto unwind; |
| 3809 | memcpy(page_address(newpage), buf, len); |
| 3810 | buf += len; |
| 3811 | buflen -= len; |
| 3812 | *pages++ = newpage; |
| 3813 | rc++; |
| 3814 | } while (buflen != 0); |
| 3815 | |
| 3816 | return rc; |
| 3817 | |
| 3818 | unwind: |
| 3819 | for(; rc > 0; rc--) |
| 3820 | __free_page(spages[rc-1]); |
| 3821 | return -ENOMEM; |
| 3822 | } |
| 3823 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3824 | struct nfs4_cached_acl { |
| 3825 | int cached; |
| 3826 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3827 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3828 | }; |
| 3829 | |
| 3830 | 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] | 3831 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3832 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3833 | |
| 3834 | spin_lock(&inode->i_lock); |
| 3835 | kfree(nfsi->nfs4_acl); |
| 3836 | nfsi->nfs4_acl = acl; |
| 3837 | spin_unlock(&inode->i_lock); |
| 3838 | } |
| 3839 | |
| 3840 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3841 | { |
| 3842 | nfs4_set_cached_acl(inode, NULL); |
| 3843 | } |
| 3844 | |
| 3845 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3846 | { |
| 3847 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3848 | struct nfs4_cached_acl *acl; |
| 3849 | int ret = -ENOENT; |
| 3850 | |
| 3851 | spin_lock(&inode->i_lock); |
| 3852 | acl = nfsi->nfs4_acl; |
| 3853 | if (acl == NULL) |
| 3854 | goto out; |
| 3855 | if (buf == NULL) /* user is just asking for length */ |
| 3856 | goto out_len; |
| 3857 | if (acl->cached == 0) |
| 3858 | goto out; |
| 3859 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3860 | if (acl->len > buflen) |
| 3861 | goto out; |
| 3862 | memcpy(buf, acl->data, acl->len); |
| 3863 | out_len: |
| 3864 | ret = acl->len; |
| 3865 | out: |
| 3866 | spin_unlock(&inode->i_lock); |
| 3867 | return ret; |
| 3868 | } |
| 3869 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3870 | 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] | 3871 | { |
| 3872 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3873 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3874 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3875 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3876 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3877 | if (acl == NULL) |
| 3878 | goto out; |
| 3879 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3880 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3881 | } else { |
| 3882 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3883 | if (acl == NULL) |
| 3884 | goto out; |
| 3885 | acl->cached = 0; |
| 3886 | } |
| 3887 | acl->len = acl_len; |
| 3888 | out: |
| 3889 | nfs4_set_cached_acl(inode, acl); |
| 3890 | } |
| 3891 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3892 | /* |
| 3893 | * The getxattr API returns the required buffer length when called with a |
| 3894 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3895 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3896 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3897 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3898 | * the cache. If not so, we throw away the page, and cache the required |
| 3899 | * length. The next getxattr call will then produce another round trip to |
| 3900 | * the server, this time with the input buf of the required size. |
| 3901 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3902 | 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] | 3903 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3904 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3905 | struct nfs_getaclargs args = { |
| 3906 | .fh = NFS_FH(inode), |
| 3907 | .acl_pages = pages, |
| 3908 | .acl_len = buflen, |
| 3909 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3910 | struct nfs_getaclres res = { |
| 3911 | .acl_len = buflen, |
| 3912 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3913 | struct rpc_message msg = { |
| 3914 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3915 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3916 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3917 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3918 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3919 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3920 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3921 | /* As long as we're doing a round trip to the server anyway, |
| 3922 | * let's be prepared for a page of acl data. */ |
| 3923 | if (npages == 0) |
| 3924 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3925 | if (npages > ARRAY_SIZE(pages)) |
| 3926 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3927 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3928 | for (i = 0; i < npages; i++) { |
| 3929 | pages[i] = alloc_page(GFP_KERNEL); |
| 3930 | if (!pages[i]) |
| 3931 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3932 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3933 | |
| 3934 | /* for decoding across pages */ |
| 3935 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3936 | if (!res.acl_scratch) |
| 3937 | goto out_free; |
| 3938 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3939 | args.acl_len = npages * PAGE_SIZE; |
| 3940 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3941 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3942 | 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] | 3943 | __func__, buf, buflen, npages, args.acl_len); |
| 3944 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3945 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3946 | if (ret) |
| 3947 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3948 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3949 | /* Handle the case where the passed-in buffer is too short */ |
| 3950 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3951 | /* Did the user only issue a request for the acl length? */ |
| 3952 | if (buf == NULL) |
| 3953 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3954 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3955 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3956 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3957 | 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] | 3958 | if (buf) { |
| 3959 | if (res.acl_len > buflen) { |
| 3960 | ret = -ERANGE; |
| 3961 | goto out_free; |
| 3962 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3963 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 3964 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3965 | out_ok: |
| 3966 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3967 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3968 | for (i = 0; i < npages; i++) |
| 3969 | if (pages[i]) |
| 3970 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3971 | if (res.acl_scratch) |
| 3972 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3973 | return ret; |
| 3974 | } |
| 3975 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3976 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3977 | { |
| 3978 | struct nfs4_exception exception = { }; |
| 3979 | ssize_t ret; |
| 3980 | do { |
| 3981 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3982 | if (ret >= 0) |
| 3983 | break; |
| 3984 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3985 | } while (exception.retry); |
| 3986 | return ret; |
| 3987 | } |
| 3988 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3989 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3990 | { |
| 3991 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3992 | int ret; |
| 3993 | |
| 3994 | if (!nfs4_server_supports_acls(server)) |
| 3995 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3996 | ret = nfs_revalidate_inode(server, inode); |
| 3997 | if (ret < 0) |
| 3998 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3999 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4000 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4001 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4002 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4003 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4004 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4005 | return ret; |
| 4006 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4007 | } |
| 4008 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4009 | 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] | 4010 | { |
| 4011 | struct nfs_server *server = NFS_SERVER(inode); |
| 4012 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4013 | struct nfs_setaclargs arg = { |
| 4014 | .fh = NFS_FH(inode), |
| 4015 | .acl_pages = pages, |
| 4016 | .acl_len = buflen, |
| 4017 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4018 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4019 | struct rpc_message msg = { |
| 4020 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4021 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4022 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4023 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4024 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4025 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4026 | |
| 4027 | if (!nfs4_server_supports_acls(server)) |
| 4028 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4029 | if (npages > ARRAY_SIZE(pages)) |
| 4030 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4031 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4032 | if (i < 0) |
| 4033 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4034 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4035 | 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] | 4036 | |
| 4037 | /* |
| 4038 | * Free each page after tx, so the only ref left is |
| 4039 | * held by the network stack |
| 4040 | */ |
| 4041 | for (; i > 0; i--) |
| 4042 | put_page(pages[i-1]); |
| 4043 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4044 | /* |
| 4045 | * Acl update can result in inode attribute update. |
| 4046 | * so mark the attribute cache invalid. |
| 4047 | */ |
| 4048 | spin_lock(&inode->i_lock); |
| 4049 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4050 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4051 | nfs_access_zap_cache(inode); |
| 4052 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4053 | return ret; |
| 4054 | } |
| 4055 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4056 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4057 | { |
| 4058 | struct nfs4_exception exception = { }; |
| 4059 | int err; |
| 4060 | do { |
| 4061 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4062 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4063 | &exception); |
| 4064 | } while (exception.retry); |
| 4065 | return err; |
| 4066 | } |
| 4067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4069 | 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] | 4070 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4071 | struct nfs_client *clp = server->nfs_client; |
| 4072 | |
| 4073 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | return 0; |
| 4075 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4076 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4077 | case -NFS4ERR_ADMIN_REVOKED: |
| 4078 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4079 | if (state == NULL) |
| 4080 | break; |
| 4081 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4082 | case -NFS4ERR_OPENMODE: |
| 4083 | if (state == NULL) |
| 4084 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4085 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4086 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4087 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4088 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4089 | if (state != NULL) { |
| 4090 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4091 | goto stateid_invalid; |
| 4092 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4094 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4095 | nfs4_schedule_lease_recovery(clp); |
| 4096 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4097 | #if defined(CONFIG_NFS_V4_1) |
| 4098 | case -NFS4ERR_BADSESSION: |
| 4099 | case -NFS4ERR_BADSLOT: |
| 4100 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4101 | case -NFS4ERR_DEADSESSION: |
| 4102 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4103 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4104 | case -NFS4ERR_SEQ_MISORDERED: |
| 4105 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4106 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4107 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4108 | task->tk_status = 0; |
| 4109 | return -EAGAIN; |
| 4110 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4112 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4113 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4115 | task->tk_status = 0; |
| 4116 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4117 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | case -NFS4ERR_OLD_STATEID: |
| 4119 | task->tk_status = 0; |
| 4120 | return -EAGAIN; |
| 4121 | } |
| 4122 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4123 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4124 | stateid_invalid: |
| 4125 | task->tk_status = -EIO; |
| 4126 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4127 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4128 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4129 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4130 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4131 | task->tk_status = 0; |
| 4132 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4135 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4136 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4137 | { |
| 4138 | __be32 verf[2]; |
| 4139 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4140 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4141 | /* An impossible timestamp guarantees this value |
| 4142 | * will never match a generated boot time. */ |
| 4143 | verf[0] = 0; |
| 4144 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4145 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4146 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4147 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4148 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4149 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4150 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4151 | } |
| 4152 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4153 | static unsigned int |
| 4154 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4155 | char *buf, size_t len) |
| 4156 | { |
| 4157 | unsigned int result; |
| 4158 | |
| 4159 | rcu_read_lock(); |
| 4160 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4161 | clp->cl_ipaddr, |
| 4162 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4163 | RPC_DISPLAY_ADDR), |
| 4164 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4165 | RPC_DISPLAY_PROTO)); |
| 4166 | rcu_read_unlock(); |
| 4167 | return result; |
| 4168 | } |
| 4169 | |
| 4170 | static unsigned int |
| 4171 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4172 | char *buf, size_t len) |
| 4173 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4174 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4175 | |
| 4176 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4177 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4178 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4179 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4180 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4181 | } |
| 4182 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4183 | /** |
| 4184 | * nfs4_proc_setclientid - Negotiate client ID |
| 4185 | * @clp: state data structure |
| 4186 | * @program: RPC program for NFSv4 callback service |
| 4187 | * @port: IP port number for NFS4 callback service |
| 4188 | * @cred: RPC credential to use for this call |
| 4189 | * @res: where to place the result |
| 4190 | * |
| 4191 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4192 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4193 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4194 | unsigned short port, struct rpc_cred *cred, |
| 4195 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | { |
| 4197 | nfs4_verifier sc_verifier; |
| 4198 | struct nfs4_setclientid setclientid = { |
| 4199 | .sc_verifier = &sc_verifier, |
| 4200 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4201 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | }; |
| 4203 | struct rpc_message msg = { |
| 4204 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4205 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4206 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4207 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4209 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4211 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4212 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4213 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4214 | setclientid.sc_name_len = |
| 4215 | nfs4_init_uniform_client_string(clp, |
| 4216 | setclientid.sc_name, |
| 4217 | sizeof(setclientid.sc_name)); |
| 4218 | else |
| 4219 | setclientid.sc_name_len = |
| 4220 | nfs4_init_nonuniform_client_string(clp, |
| 4221 | setclientid.sc_name, |
| 4222 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4223 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4224 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4225 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4226 | sizeof(setclientid.sc_netid), |
| 4227 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4228 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4229 | rcu_read_unlock(); |
| 4230 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4231 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4233 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4234 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4235 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4236 | setclientid.sc_name_len, setclientid.sc_name); |
| 4237 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4238 | dprintk("NFS reply setclientid: %d\n", status); |
| 4239 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | } |
| 4241 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4242 | /** |
| 4243 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4244 | * @clp: state data structure |
| 4245 | * @res: result of a previous SETCLIENTID |
| 4246 | * @cred: RPC credential to use for this call |
| 4247 | * |
| 4248 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4249 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4250 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4251 | struct nfs4_setclientid_res *arg, |
| 4252 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | { |
| 4254 | struct nfs_fsinfo fsinfo; |
| 4255 | struct rpc_message msg = { |
| 4256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4257 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4259 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | }; |
| 4261 | unsigned long now; |
| 4262 | int status; |
| 4263 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4264 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4265 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4266 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4268 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | if (status == 0) { |
| 4270 | spin_lock(&clp->cl_lock); |
| 4271 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4272 | clp->cl_last_renewal = now; |
| 4273 | spin_unlock(&clp->cl_lock); |
| 4274 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4275 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | return status; |
| 4277 | } |
| 4278 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4279 | struct nfs4_delegreturndata { |
| 4280 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4281 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4282 | struct nfs_fh fh; |
| 4283 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4284 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4285 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4286 | int rpc_status; |
| 4287 | }; |
| 4288 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4289 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4290 | { |
| 4291 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4292 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4293 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4294 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4295 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4296 | switch (task->tk_status) { |
| 4297 | case -NFS4ERR_STALE_STATEID: |
| 4298 | case -NFS4ERR_EXPIRED: |
| 4299 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4300 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4301 | break; |
| 4302 | default: |
| 4303 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4304 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4305 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4306 | return; |
| 4307 | } |
| 4308 | } |
| 4309 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | static void nfs4_delegreturn_release(void *calldata) |
| 4313 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4314 | kfree(calldata); |
| 4315 | } |
| 4316 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4317 | #if defined(CONFIG_NFS_V4_1) |
| 4318 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4319 | { |
| 4320 | struct nfs4_delegreturndata *d_data; |
| 4321 | |
| 4322 | d_data = (struct nfs4_delegreturndata *)data; |
| 4323 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4324 | nfs4_setup_sequence(d_data->res.server, |
| 4325 | &d_data->args.seq_args, |
| 4326 | &d_data->res.seq_res, |
| 4327 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4328 | } |
| 4329 | #endif /* CONFIG_NFS_V4_1 */ |
| 4330 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4331 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4332 | #if defined(CONFIG_NFS_V4_1) |
| 4333 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4334 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4335 | .rpc_call_done = nfs4_delegreturn_done, |
| 4336 | .rpc_release = nfs4_delegreturn_release, |
| 4337 | }; |
| 4338 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4339 | 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] | 4340 | { |
| 4341 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4342 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4343 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4344 | struct rpc_message msg = { |
| 4345 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4346 | .rpc_cred = cred, |
| 4347 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4348 | struct rpc_task_setup task_setup_data = { |
| 4349 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4350 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4351 | .callback_ops = &nfs4_delegreturn_ops, |
| 4352 | .flags = RPC_TASK_ASYNC, |
| 4353 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4354 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4355 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4356 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4357 | if (data == NULL) |
| 4358 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4359 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4360 | data->args.fhandle = &data->fh; |
| 4361 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4362 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4363 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4364 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4365 | data->res.fattr = &data->fattr; |
| 4366 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4367 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4368 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4369 | data->rpc_status = 0; |
| 4370 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4371 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4372 | msg.rpc_argp = &data->args; |
| 4373 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4374 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4375 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4376 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4377 | if (!issync) |
| 4378 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4379 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4380 | if (status != 0) |
| 4381 | goto out; |
| 4382 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4383 | if (status == 0) |
| 4384 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4385 | else |
| 4386 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4387 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4388 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4389 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | } |
| 4391 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4392 | 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] | 4393 | { |
| 4394 | struct nfs_server *server = NFS_SERVER(inode); |
| 4395 | struct nfs4_exception exception = { }; |
| 4396 | int err; |
| 4397 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4398 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | switch (err) { |
| 4400 | case -NFS4ERR_STALE_STATEID: |
| 4401 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | case 0: |
| 4403 | return 0; |
| 4404 | } |
| 4405 | err = nfs4_handle_exception(server, err, &exception); |
| 4406 | } while (exception.retry); |
| 4407 | return err; |
| 4408 | } |
| 4409 | |
| 4410 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4411 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4412 | |
| 4413 | /* |
| 4414 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4415 | */ |
| 4416 | static unsigned long |
| 4417 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4418 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4419 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | timeout <<= 1; |
| 4421 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4422 | return NFS4_LOCK_MAXTIMEOUT; |
| 4423 | return timeout; |
| 4424 | } |
| 4425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4427 | { |
| 4428 | struct inode *inode = state->inode; |
| 4429 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4430 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4431 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4433 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4435 | struct nfs_lockt_res res = { |
| 4436 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | }; |
| 4438 | struct rpc_message msg = { |
| 4439 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4440 | .rpc_argp = &arg, |
| 4441 | .rpc_resp = &res, |
| 4442 | .rpc_cred = state->owner->so_cred, |
| 4443 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | struct nfs4_lock_state *lsp; |
| 4445 | int status; |
| 4446 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4447 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4448 | status = nfs4_set_lock_state(state, request); |
| 4449 | if (status != 0) |
| 4450 | goto out; |
| 4451 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4452 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4453 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4454 | 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] | 4455 | switch (status) { |
| 4456 | case 0: |
| 4457 | request->fl_type = F_UNLCK; |
| 4458 | break; |
| 4459 | case -NFS4ERR_DENIED: |
| 4460 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4462 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4463 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | return status; |
| 4465 | } |
| 4466 | |
| 4467 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4468 | { |
| 4469 | struct nfs4_exception exception = { }; |
| 4470 | int err; |
| 4471 | |
| 4472 | do { |
| 4473 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4474 | _nfs4_proc_getlk(state, cmd, request), |
| 4475 | &exception); |
| 4476 | } while (exception.retry); |
| 4477 | return err; |
| 4478 | } |
| 4479 | |
| 4480 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4481 | { |
| 4482 | int res = 0; |
| 4483 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4484 | case FL_POSIX: |
| 4485 | res = posix_lock_file_wait(file, fl); |
| 4486 | break; |
| 4487 | case FL_FLOCK: |
| 4488 | res = flock_lock_file_wait(file, fl); |
| 4489 | break; |
| 4490 | default: |
| 4491 | BUG(); |
| 4492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | return res; |
| 4494 | } |
| 4495 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4496 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4497 | struct nfs_locku_args arg; |
| 4498 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4499 | struct nfs4_lock_state *lsp; |
| 4500 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4501 | struct file_lock fl; |
| 4502 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4503 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4504 | }; |
| 4505 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4506 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4507 | struct nfs_open_context *ctx, |
| 4508 | struct nfs4_lock_state *lsp, |
| 4509 | struct nfs_seqid *seqid) |
| 4510 | { |
| 4511 | struct nfs4_unlockdata *p; |
| 4512 | struct inode *inode = lsp->ls_state->inode; |
| 4513 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4514 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4515 | if (p == NULL) |
| 4516 | return NULL; |
| 4517 | p->arg.fh = NFS_FH(inode); |
| 4518 | p->arg.fl = &p->fl; |
| 4519 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4520 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4521 | p->arg.stateid = &lsp->ls_stateid; |
| 4522 | p->lsp = lsp; |
| 4523 | atomic_inc(&lsp->ls_count); |
| 4524 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4525 | p->ctx = get_nfs_open_context(ctx); |
| 4526 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4527 | p->server = NFS_SERVER(inode); |
| 4528 | return p; |
| 4529 | } |
| 4530 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4531 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4532 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4533 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4534 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4535 | nfs4_put_lock_state(calldata->lsp); |
| 4536 | put_nfs_open_context(calldata->ctx); |
| 4537 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4540 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4541 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4542 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4543 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4544 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4545 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4546 | switch (task->tk_status) { |
| 4547 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4548 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4549 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4550 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4551 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4552 | case -NFS4ERR_BAD_STATEID: |
| 4553 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4554 | case -NFS4ERR_STALE_STATEID: |
| 4555 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4556 | break; |
| 4557 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4558 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4559 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4560 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4561 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4564 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4565 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4566 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4568 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4569 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4570 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4571 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4572 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4573 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4574 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4575 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4576 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4577 | &calldata->res.seq_res, |
| 4578 | task) != 0) |
| 4579 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4580 | return; |
| 4581 | out_no_action: |
| 4582 | task->tk_action = NULL; |
| 4583 | out_wait: |
| 4584 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4587 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4588 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4589 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4590 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4591 | }; |
| 4592 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4593 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4594 | struct nfs_open_context *ctx, |
| 4595 | struct nfs4_lock_state *lsp, |
| 4596 | struct nfs_seqid *seqid) |
| 4597 | { |
| 4598 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4599 | struct rpc_message msg = { |
| 4600 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4601 | .rpc_cred = ctx->cred, |
| 4602 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4603 | struct rpc_task_setup task_setup_data = { |
| 4604 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4605 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4606 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4607 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4608 | .flags = RPC_TASK_ASYNC, |
| 4609 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4610 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4611 | /* Ensure this is an unlock - when canceling a lock, the |
| 4612 | * canceled lock is passed in, and it won't be an unlock. |
| 4613 | */ |
| 4614 | fl->fl_type = F_UNLCK; |
| 4615 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4616 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4617 | if (data == NULL) { |
| 4618 | nfs_free_seqid(seqid); |
| 4619 | return ERR_PTR(-ENOMEM); |
| 4620 | } |
| 4621 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4622 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4623 | msg.rpc_argp = &data->arg; |
| 4624 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4625 | task_setup_data.callback_data = data; |
| 4626 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4627 | } |
| 4628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4630 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4631 | struct inode *inode = state->inode; |
| 4632 | struct nfs4_state_owner *sp = state->owner; |
| 4633 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4634 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4635 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4636 | struct rpc_task *task; |
| 4637 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4638 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4640 | status = nfs4_set_lock_state(state, request); |
| 4641 | /* Unlock _before_ we do the RPC call */ |
| 4642 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4643 | /* Exclude nfs_delegation_claim_locks() */ |
| 4644 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4645 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4646 | down_read(&nfsi->rwsem); |
| 4647 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4648 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4649 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4650 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4651 | } |
| 4652 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4653 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4654 | if (status != 0) |
| 4655 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4656 | /* Is this a delegated lock? */ |
| 4657 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4658 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4659 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4660 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4661 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4662 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4663 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4664 | 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] | 4665 | status = PTR_ERR(task); |
| 4666 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4667 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4668 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4669 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4670 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4671 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4672 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4675 | struct nfs4_lockdata { |
| 4676 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4677 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4678 | struct nfs4_lock_state *lsp; |
| 4679 | struct nfs_open_context *ctx; |
| 4680 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4681 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4682 | int rpc_status; |
| 4683 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4684 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4685 | }; |
| 4686 | |
| 4687 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4688 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4689 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4690 | { |
| 4691 | struct nfs4_lockdata *p; |
| 4692 | struct inode *inode = lsp->ls_state->inode; |
| 4693 | struct nfs_server *server = NFS_SERVER(inode); |
| 4694 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4695 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4696 | if (p == NULL) |
| 4697 | return NULL; |
| 4698 | |
| 4699 | p->arg.fh = NFS_FH(inode); |
| 4700 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4701 | 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] | 4702 | if (p->arg.open_seqid == NULL) |
| 4703 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4704 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4705 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4706 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4707 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4708 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4709 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4710 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4711 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4712 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4713 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4714 | atomic_inc(&lsp->ls_count); |
| 4715 | p->ctx = get_nfs_open_context(ctx); |
| 4716 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4717 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4718 | out_free_seqid: |
| 4719 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4720 | out_free: |
| 4721 | kfree(p); |
| 4722 | return NULL; |
| 4723 | } |
| 4724 | |
| 4725 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4726 | { |
| 4727 | struct nfs4_lockdata *data = calldata; |
| 4728 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4729 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4730 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4731 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4732 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4733 | /* Do we need to do an open_to_lock_owner? */ |
| 4734 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4735 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4736 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4737 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4738 | data->arg.open_stateid = &state->stateid; |
| 4739 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4740 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4741 | } else |
| 4742 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4743 | if (!nfs4_valid_open_stateid(state)) { |
| 4744 | data->rpc_status = -EBADF; |
| 4745 | task->tk_action = NULL; |
| 4746 | goto out_release_open_seqid; |
| 4747 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4748 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4749 | if (nfs4_setup_sequence(data->server, |
| 4750 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4751 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4752 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4753 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4754 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4755 | nfs_release_seqid(data->arg.open_seqid); |
| 4756 | out_release_lock_seqid: |
| 4757 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4758 | out_wait: |
| 4759 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4760 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4761 | } |
| 4762 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4763 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4764 | { |
| 4765 | struct nfs4_lockdata *data = calldata; |
| 4766 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4767 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4768 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4769 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4770 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4771 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4772 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4773 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4774 | if (data->rpc_status == 0) |
| 4775 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4776 | else |
| 4777 | goto out; |
| 4778 | } |
| 4779 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4780 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4781 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4782 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4783 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4784 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4785 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | static void nfs4_lock_release(void *calldata) |
| 4789 | { |
| 4790 | struct nfs4_lockdata *data = calldata; |
| 4791 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4792 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4793 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4794 | if (data->cancelled != 0) { |
| 4795 | struct rpc_task *task; |
| 4796 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4797 | data->arg.lock_seqid); |
| 4798 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4799 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4800 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4801 | } else |
| 4802 | nfs_free_seqid(data->arg.lock_seqid); |
| 4803 | nfs4_put_lock_state(data->lsp); |
| 4804 | put_nfs_open_context(data->ctx); |
| 4805 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4806 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4810 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4811 | .rpc_call_done = nfs4_lock_done, |
| 4812 | .rpc_release = nfs4_lock_release, |
| 4813 | }; |
| 4814 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4815 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4816 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4817 | switch (error) { |
| 4818 | case -NFS4ERR_ADMIN_REVOKED: |
| 4819 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4820 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4821 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4822 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4823 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4824 | break; |
| 4825 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4826 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4827 | case -NFS4ERR_EXPIRED: |
| 4828 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4829 | }; |
| 4830 | } |
| 4831 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4832 | 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] | 4833 | { |
| 4834 | struct nfs4_lockdata *data; |
| 4835 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4836 | struct rpc_message msg = { |
| 4837 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4838 | .rpc_cred = state->owner->so_cred, |
| 4839 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4840 | struct rpc_task_setup task_setup_data = { |
| 4841 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4842 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4843 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4844 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4845 | .flags = RPC_TASK_ASYNC, |
| 4846 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4847 | int ret; |
| 4848 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4849 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4850 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4851 | fl->fl_u.nfs4_fl.owner, |
| 4852 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4853 | if (data == NULL) |
| 4854 | return -ENOMEM; |
| 4855 | if (IS_SETLKW(cmd)) |
| 4856 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4857 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4858 | msg.rpc_argp = &data->arg; |
| 4859 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4860 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4861 | if (recovery_type > NFS_LOCK_NEW) { |
| 4862 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4863 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4864 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4865 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4866 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4867 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4868 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4869 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4870 | if (ret == 0) { |
| 4871 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4872 | if (ret) |
| 4873 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4874 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4875 | } else |
| 4876 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4877 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4878 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4879 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4883 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4884 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4885 | struct nfs4_exception exception = { |
| 4886 | .inode = state->inode, |
| 4887 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4888 | int err; |
| 4889 | |
| 4890 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4891 | /* Cache the lock if possible... */ |
| 4892 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4893 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4894 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4895 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4896 | break; |
| 4897 | nfs4_handle_exception(server, err, &exception); |
| 4898 | } while (exception.retry); |
| 4899 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4903 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4904 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4905 | struct nfs4_exception exception = { |
| 4906 | .inode = state->inode, |
| 4907 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4908 | int err; |
| 4909 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4910 | err = nfs4_set_lock_state(state, request); |
| 4911 | if (err != 0) |
| 4912 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4913 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4914 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4915 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4916 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4917 | switch (err) { |
| 4918 | default: |
| 4919 | goto out; |
| 4920 | case -NFS4ERR_GRACE: |
| 4921 | case -NFS4ERR_DELAY: |
| 4922 | nfs4_handle_exception(server, err, &exception); |
| 4923 | err = 0; |
| 4924 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4925 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4926 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4927 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | } |
| 4929 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4930 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4931 | /** |
| 4932 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4933 | * |
| 4934 | * @state: NFSv4 state for an inode |
| 4935 | * |
| 4936 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4937 | * Otherwise a negative NFS4ERR value is returned. |
| 4938 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4939 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4940 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4941 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4942 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4943 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4944 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4945 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4946 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4947 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4948 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4949 | /* Free the stateid unless the server |
| 4950 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4951 | if (status != -NFS4ERR_BAD_STATEID) |
| 4952 | nfs41_free_stateid(server, |
| 4953 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4954 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4955 | ret = status; |
| 4956 | } |
| 4957 | } |
| 4958 | }; |
| 4959 | |
| 4960 | return ret; |
| 4961 | } |
| 4962 | |
| 4963 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4964 | { |
| 4965 | int status = NFS_OK; |
| 4966 | |
| 4967 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4968 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4969 | if (status != NFS_OK) |
| 4970 | status = nfs4_lock_expired(state, request); |
| 4971 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4972 | } |
| 4973 | #endif |
| 4974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4976 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4977 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4978 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4979 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4980 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4981 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4983 | if ((fl_flags & FL_POSIX) && |
| 4984 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4985 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4986 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4987 | status = nfs4_set_lock_state(state, request); |
| 4988 | if (status != 0) |
| 4989 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4990 | request->fl_flags |= FL_ACCESS; |
| 4991 | status = do_vfs_lock(request->fl_file, request); |
| 4992 | if (status < 0) |
| 4993 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4994 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4995 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4996 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4997 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4998 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4999 | status = do_vfs_lock(request->fl_file, request); |
| 5000 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5001 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5002 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5003 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5004 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5005 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5006 | goto out; |
| 5007 | down_read(&nfsi->rwsem); |
| 5008 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5009 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5010 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5011 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5012 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5013 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5014 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5015 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5016 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5017 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5018 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5019 | out: |
| 5020 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | return status; |
| 5022 | } |
| 5023 | |
| 5024 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5025 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5026 | struct nfs4_exception exception = { |
| 5027 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5028 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5029 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | int err; |
| 5031 | |
| 5032 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5033 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5034 | if (err == -NFS4ERR_DENIED) |
| 5035 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5037 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | } while (exception.retry); |
| 5039 | return err; |
| 5040 | } |
| 5041 | |
| 5042 | static int |
| 5043 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5044 | { |
| 5045 | struct nfs_open_context *ctx; |
| 5046 | struct nfs4_state *state; |
| 5047 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5048 | int status; |
| 5049 | |
| 5050 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5051 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | state = ctx->state; |
| 5053 | |
| 5054 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5055 | return -EINVAL; |
| 5056 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5057 | if (IS_GETLK(cmd)) { |
| 5058 | if (state != NULL) |
| 5059 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5060 | return 0; |
| 5061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | |
| 5063 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5064 | return -EINVAL; |
| 5065 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5066 | if (request->fl_type == F_UNLCK) { |
| 5067 | if (state != NULL) |
| 5068 | return nfs4_proc_unlck(state, cmd, request); |
| 5069 | return 0; |
| 5070 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5072 | if (state == NULL) |
| 5073 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5074 | /* |
| 5075 | * Don't rely on the VFS having checked the file open mode, |
| 5076 | * since it won't do this for flock() locks. |
| 5077 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5078 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5079 | case F_RDLCK: |
| 5080 | if (!(filp->f_mode & FMODE_READ)) |
| 5081 | return -EBADF; |
| 5082 | break; |
| 5083 | case F_WRLCK: |
| 5084 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5085 | return -EBADF; |
| 5086 | } |
| 5087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | do { |
| 5089 | status = nfs4_proc_setlk(state, cmd, request); |
| 5090 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5091 | break; |
| 5092 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5093 | status = -ERESTARTSYS; |
| 5094 | if (signalled()) |
| 5095 | break; |
| 5096 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | return status; |
| 5098 | } |
| 5099 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5100 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5101 | { |
| 5102 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5103 | struct nfs4_exception exception = { }; |
| 5104 | int err; |
| 5105 | |
| 5106 | err = nfs4_set_lock_state(state, fl); |
| 5107 | if (err != 0) |
| 5108 | goto out; |
| 5109 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5110 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5111 | switch (err) { |
| 5112 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5113 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5114 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5115 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5116 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5117 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5118 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5119 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5120 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 5121 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5122 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5123 | err = -EAGAIN; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5124 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5125 | case -NFS4ERR_BADSESSION: |
| 5126 | case -NFS4ERR_BADSLOT: |
| 5127 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5128 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5129 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5130 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5131 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5132 | err = -EAGAIN; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5133 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5134 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5135 | case -NFS4ERR_ADMIN_REVOKED: |
| 5136 | case -NFS4ERR_BAD_STATEID: |
| 5137 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5138 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5139 | err = 0; |
| 5140 | goto out; |
| 5141 | case -ENOMEM: |
| 5142 | case -NFS4ERR_DENIED: |
| 5143 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5144 | err = 0; |
| 5145 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5146 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5147 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5148 | err = nfs4_handle_exception(server, err, &exception); |
| 5149 | } while (exception.retry); |
| 5150 | out: |
| 5151 | return err; |
| 5152 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5153 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5154 | struct nfs_release_lockowner_data { |
| 5155 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5156 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5157 | struct nfs_release_lockowner_args args; |
| 5158 | }; |
| 5159 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5160 | static void nfs4_release_lockowner_release(void *calldata) |
| 5161 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5162 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5163 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5164 | kfree(calldata); |
| 5165 | } |
| 5166 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5167 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5168 | .rpc_release = nfs4_release_lockowner_release, |
| 5169 | }; |
| 5170 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5171 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5172 | { |
| 5173 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5174 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5175 | struct rpc_message msg = { |
| 5176 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5177 | }; |
| 5178 | |
| 5179 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5180 | return -EINVAL; |
| 5181 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5182 | if (!data) |
| 5183 | return -ENOMEM; |
| 5184 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5185 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5186 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5187 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5188 | data->args.lock_owner.s_dev = server->s_dev; |
| 5189 | msg.rpc_argp = &data->args; |
| 5190 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5191 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5192 | } |
| 5193 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5194 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5195 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5196 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5197 | const void *buf, size_t buflen, |
| 5198 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5199 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5200 | if (strcmp(key, "") != 0) |
| 5201 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5202 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5203 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5204 | } |
| 5205 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5206 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5207 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5208 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5209 | if (strcmp(key, "") != 0) |
| 5210 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5211 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5212 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5215 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5216 | size_t list_len, const char *name, |
| 5217 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5218 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5219 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5220 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5221 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5222 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5223 | |
| 5224 | if (list && len <= list_len) |
| 5225 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5226 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5229 | /* |
| 5230 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5231 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5232 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5233 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5234 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5235 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5236 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5237 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5238 | return; |
| 5239 | |
| 5240 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5241 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5242 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5243 | fattr->nlink = 2; |
| 5244 | } |
| 5245 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5246 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5247 | const struct qstr *name, |
| 5248 | struct nfs4_fs_locations *fs_locations, |
| 5249 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5250 | { |
| 5251 | struct nfs_server *server = NFS_SERVER(dir); |
| 5252 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5253 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5254 | }; |
| 5255 | struct nfs4_fs_locations_arg args = { |
| 5256 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5257 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5258 | .page = page, |
| 5259 | .bitmask = bitmask, |
| 5260 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5261 | struct nfs4_fs_locations_res res = { |
| 5262 | .fs_locations = fs_locations, |
| 5263 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5264 | struct rpc_message msg = { |
| 5265 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5266 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5267 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5268 | }; |
| 5269 | int status; |
| 5270 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5271 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5272 | |
| 5273 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5274 | * is not supported */ |
| 5275 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5276 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5277 | else |
| 5278 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5279 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5280 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5281 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5282 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5283 | 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] | 5284 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5285 | return status; |
| 5286 | } |
| 5287 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5288 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5289 | const struct qstr *name, |
| 5290 | struct nfs4_fs_locations *fs_locations, |
| 5291 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5292 | { |
| 5293 | struct nfs4_exception exception = { }; |
| 5294 | int err; |
| 5295 | do { |
| 5296 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5297 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5298 | &exception); |
| 5299 | } while (exception.retry); |
| 5300 | return err; |
| 5301 | } |
| 5302 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5303 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5304 | { |
| 5305 | int status; |
| 5306 | struct nfs4_secinfo_arg args = { |
| 5307 | .dir_fh = NFS_FH(dir), |
| 5308 | .name = name, |
| 5309 | }; |
| 5310 | struct nfs4_secinfo_res res = { |
| 5311 | .flavors = flavors, |
| 5312 | }; |
| 5313 | struct rpc_message msg = { |
| 5314 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5315 | .rpc_argp = &args, |
| 5316 | .rpc_resp = &res, |
| 5317 | }; |
| 5318 | |
| 5319 | dprintk("NFS call secinfo %s\n", name->name); |
| 5320 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5321 | dprintk("NFS reply secinfo: %d\n", status); |
| 5322 | return status; |
| 5323 | } |
| 5324 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5325 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5326 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5327 | { |
| 5328 | struct nfs4_exception exception = { }; |
| 5329 | int err; |
| 5330 | do { |
| 5331 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5332 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5333 | &exception); |
| 5334 | } while (exception.retry); |
| 5335 | return err; |
| 5336 | } |
| 5337 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5338 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5339 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5340 | * Check the exchange flags returned by the server for invalid flags, having |
| 5341 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5342 | * DS flags set. |
| 5343 | */ |
| 5344 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5345 | { |
| 5346 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5347 | goto out_inval; |
| 5348 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5349 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5350 | goto out_inval; |
| 5351 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5352 | goto out_inval; |
| 5353 | return NFS_OK; |
| 5354 | out_inval: |
| 5355 | return -NFS4ERR_INVAL; |
| 5356 | } |
| 5357 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5358 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5359 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5360 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5361 | { |
| 5362 | if (a->server_scope_sz == b->server_scope_sz && |
| 5363 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5364 | return true; |
| 5365 | |
| 5366 | return false; |
| 5367 | } |
| 5368 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5369 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5370 | * nfs4_proc_bind_conn_to_session() |
| 5371 | * |
| 5372 | * The 4.1 client currently uses the same TCP connection for the |
| 5373 | * fore and backchannel. |
| 5374 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5375 | 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] | 5376 | { |
| 5377 | int status; |
| 5378 | struct nfs41_bind_conn_to_session_res res; |
| 5379 | struct rpc_message msg = { |
| 5380 | .rpc_proc = |
| 5381 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5382 | .rpc_argp = clp, |
| 5383 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5384 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5385 | }; |
| 5386 | |
| 5387 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5388 | |
| 5389 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5390 | if (unlikely(res.session == NULL)) { |
| 5391 | status = -ENOMEM; |
| 5392 | goto out; |
| 5393 | } |
| 5394 | |
| 5395 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5396 | if (status == 0) { |
| 5397 | if (memcmp(res.session->sess_id.data, |
| 5398 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5399 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5400 | status = -EIO; |
| 5401 | goto out_session; |
| 5402 | } |
| 5403 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5404 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5405 | __func__); |
| 5406 | status = -EIO; |
| 5407 | goto out_session; |
| 5408 | } |
| 5409 | if (res.use_conn_in_rdma_mode) { |
| 5410 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5411 | __func__); |
| 5412 | status = -EIO; |
| 5413 | goto out_session; |
| 5414 | } |
| 5415 | } |
| 5416 | out_session: |
| 5417 | kfree(res.session); |
| 5418 | out: |
| 5419 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5420 | return status; |
| 5421 | } |
| 5422 | |
| 5423 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5424 | * nfs4_proc_exchange_id() |
| 5425 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5426 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5427 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5428 | * Since the clientid has expired, all compounds using sessions |
| 5429 | * associated with the stale clientid will be returning |
| 5430 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5431 | * be in some phase of session reset. |
| 5432 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5433 | 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] | 5434 | { |
| 5435 | nfs4_verifier verifier; |
| 5436 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5437 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5438 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5439 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5440 | }; |
| 5441 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5442 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5443 | }; |
| 5444 | int status; |
| 5445 | struct rpc_message msg = { |
| 5446 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5447 | .rpc_argp = &args, |
| 5448 | .rpc_resp = &res, |
| 5449 | .rpc_cred = cred, |
| 5450 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5451 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5452 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5453 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5454 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5455 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5456 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5457 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5458 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5459 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5460 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5461 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5462 | status = -ENOMEM; |
| 5463 | goto out; |
| 5464 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5465 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5466 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5467 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5468 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5469 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5470 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5471 | } |
| 5472 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5473 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5474 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5475 | status = -ENOMEM; |
| 5476 | goto out_server_scope; |
| 5477 | } |
| 5478 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5479 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5480 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5481 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5482 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5483 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5484 | clp->cl_clientid = res.clientid; |
| 5485 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5486 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5487 | clp->cl_seqid = res.seqid; |
| 5488 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5489 | kfree(clp->cl_serverowner); |
| 5490 | clp->cl_serverowner = res.server_owner; |
| 5491 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5492 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5493 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5494 | kfree(clp->cl_implid); |
| 5495 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5496 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5497 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5498 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5499 | res.server_scope)) { |
| 5500 | dprintk("%s: server_scope mismatch detected\n", |
| 5501 | __func__); |
| 5502 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5503 | kfree(clp->cl_serverscope); |
| 5504 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5505 | } |
| 5506 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5507 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5508 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5509 | goto out; |
| 5510 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5511 | } else |
| 5512 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5513 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5514 | out_server_owner: |
| 5515 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5516 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5517 | kfree(res.server_scope); |
| 5518 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5519 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5520 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5521 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5522 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5523 | clp->cl_implid->date.seconds, |
| 5524 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5525 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5526 | return status; |
| 5527 | } |
| 5528 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5529 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5530 | struct rpc_cred *cred) |
| 5531 | { |
| 5532 | struct rpc_message msg = { |
| 5533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5534 | .rpc_argp = clp, |
| 5535 | .rpc_cred = cred, |
| 5536 | }; |
| 5537 | int status; |
| 5538 | |
| 5539 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5540 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5541 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5542 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5543 | return status; |
| 5544 | } |
| 5545 | |
| 5546 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5547 | struct rpc_cred *cred) |
| 5548 | { |
| 5549 | unsigned int loop; |
| 5550 | int ret; |
| 5551 | |
| 5552 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5553 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5554 | switch (ret) { |
| 5555 | case -NFS4ERR_DELAY: |
| 5556 | case -NFS4ERR_CLIENTID_BUSY: |
| 5557 | ssleep(1); |
| 5558 | break; |
| 5559 | default: |
| 5560 | return ret; |
| 5561 | } |
| 5562 | } |
| 5563 | return 0; |
| 5564 | } |
| 5565 | |
| 5566 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5567 | { |
| 5568 | struct rpc_cred *cred; |
| 5569 | int ret = 0; |
| 5570 | |
| 5571 | if (clp->cl_mvops->minor_version < 1) |
| 5572 | goto out; |
| 5573 | if (clp->cl_exchange_flags == 0) |
| 5574 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5575 | if (clp->cl_preserve_clid) |
| 5576 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5577 | cred = nfs4_get_exchange_id_cred(clp); |
| 5578 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5579 | if (cred) |
| 5580 | put_rpccred(cred); |
| 5581 | switch (ret) { |
| 5582 | case 0: |
| 5583 | case -NFS4ERR_STALE_CLIENTID: |
| 5584 | clp->cl_exchange_flags = 0; |
| 5585 | } |
| 5586 | out: |
| 5587 | return ret; |
| 5588 | } |
| 5589 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5590 | struct nfs4_get_lease_time_data { |
| 5591 | struct nfs4_get_lease_time_args *args; |
| 5592 | struct nfs4_get_lease_time_res *res; |
| 5593 | struct nfs_client *clp; |
| 5594 | }; |
| 5595 | |
| 5596 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5597 | void *calldata) |
| 5598 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5599 | struct nfs4_get_lease_time_data *data = |
| 5600 | (struct nfs4_get_lease_time_data *)calldata; |
| 5601 | |
| 5602 | dprintk("--> %s\n", __func__); |
| 5603 | /* just setup sequence, do not trigger session recovery |
| 5604 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5605 | nfs41_setup_sequence(data->clp->cl_session, |
| 5606 | &data->args->la_seq_args, |
| 5607 | &data->res->lr_seq_res, |
| 5608 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5609 | dprintk("<-- %s\n", __func__); |
| 5610 | } |
| 5611 | |
| 5612 | /* |
| 5613 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5614 | * from sequence operation or clientid errors. |
| 5615 | */ |
| 5616 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5617 | { |
| 5618 | struct nfs4_get_lease_time_data *data = |
| 5619 | (struct nfs4_get_lease_time_data *)calldata; |
| 5620 | |
| 5621 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5622 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5623 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5624 | switch (task->tk_status) { |
| 5625 | case -NFS4ERR_DELAY: |
| 5626 | case -NFS4ERR_GRACE: |
| 5627 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5628 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5629 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5630 | /* fall through */ |
| 5631 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5632 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5633 | return; |
| 5634 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5635 | dprintk("<-- %s\n", __func__); |
| 5636 | } |
| 5637 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5638 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5639 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5640 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5641 | }; |
| 5642 | |
| 5643 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5644 | { |
| 5645 | struct rpc_task *task; |
| 5646 | struct nfs4_get_lease_time_args args; |
| 5647 | struct nfs4_get_lease_time_res res = { |
| 5648 | .lr_fsinfo = fsinfo, |
| 5649 | }; |
| 5650 | struct nfs4_get_lease_time_data data = { |
| 5651 | .args = &args, |
| 5652 | .res = &res, |
| 5653 | .clp = clp, |
| 5654 | }; |
| 5655 | struct rpc_message msg = { |
| 5656 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5657 | .rpc_argp = &args, |
| 5658 | .rpc_resp = &res, |
| 5659 | }; |
| 5660 | struct rpc_task_setup task_setup = { |
| 5661 | .rpc_client = clp->cl_rpcclient, |
| 5662 | .rpc_message = &msg, |
| 5663 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5664 | .callback_data = &data, |
| 5665 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5666 | }; |
| 5667 | int status; |
| 5668 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5669 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5670 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5671 | dprintk("--> %s\n", __func__); |
| 5672 | task = rpc_run_task(&task_setup); |
| 5673 | |
| 5674 | if (IS_ERR(task)) |
| 5675 | status = PTR_ERR(task); |
| 5676 | else { |
| 5677 | status = task->tk_status; |
| 5678 | rpc_put_task(task); |
| 5679 | } |
| 5680 | dprintk("<-- %s return %d\n", __func__, status); |
| 5681 | |
| 5682 | return status; |
| 5683 | } |
| 5684 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5685 | /* |
| 5686 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5687 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5688 | * use them. |
| 5689 | * |
| 5690 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5691 | * always set csa_cachethis to FALSE because the current implementation |
| 5692 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5693 | */ |
| 5694 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5695 | { |
| 5696 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5697 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5698 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5699 | |
| 5700 | if (mxrqst_sz == 0) |
| 5701 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5702 | if (mxresp_sz == 0) |
| 5703 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5704 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5705 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5706 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5707 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5708 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5709 | |
| 5710 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5711 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5712 | __func__, |
| 5713 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5714 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5715 | |
| 5716 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5717 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5718 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5719 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5720 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5721 | args->bc_attrs.max_reqs = 1; |
| 5722 | |
| 5723 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5724 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5725 | __func__, |
| 5726 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5727 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5728 | args->bc_attrs.max_reqs); |
| 5729 | } |
| 5730 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5731 | 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] | 5732 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5733 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5734 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5735 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5736 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5737 | return -EINVAL; |
| 5738 | /* |
| 5739 | * Our requested max_ops is the minimum we need; we're not |
| 5740 | * prepared to break up compounds into smaller pieces than that. |
| 5741 | * So, no point even trying to continue if the server won't |
| 5742 | * cooperate: |
| 5743 | */ |
| 5744 | if (rcvd->max_ops < sent->max_ops) |
| 5745 | return -EINVAL; |
| 5746 | if (rcvd->max_reqs == 0) |
| 5747 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5748 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5749 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5750 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5751 | } |
| 5752 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5753 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5754 | { |
| 5755 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5756 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5757 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5758 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5759 | return -EINVAL; |
| 5760 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5761 | return -EINVAL; |
| 5762 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5763 | return -EINVAL; |
| 5764 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5765 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5766 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5767 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5768 | return -EINVAL; |
| 5769 | return 0; |
| 5770 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5771 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5772 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5773 | struct nfs4_session *session) |
| 5774 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5775 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5776 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5777 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5778 | if (ret) |
| 5779 | return ret; |
| 5780 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5781 | } |
| 5782 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5783 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5784 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5785 | { |
| 5786 | struct nfs4_session *session = clp->cl_session; |
| 5787 | struct nfs41_create_session_args args = { |
| 5788 | .client = clp, |
| 5789 | .cb_program = NFS4_CALLBACK, |
| 5790 | }; |
| 5791 | struct nfs41_create_session_res res = { |
| 5792 | .client = clp, |
| 5793 | }; |
| 5794 | struct rpc_message msg = { |
| 5795 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5796 | .rpc_argp = &args, |
| 5797 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5798 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5799 | }; |
| 5800 | int status; |
| 5801 | |
| 5802 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5803 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5804 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5805 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5806 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5807 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5808 | /* Verify the session's negotiated channel_attrs values */ |
| 5809 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5810 | /* Increment the clientid slot sequence id */ |
| 5811 | clp->cl_seqid++; |
| 5812 | } |
| 5813 | |
| 5814 | return status; |
| 5815 | } |
| 5816 | |
| 5817 | /* |
| 5818 | * Issues a CREATE_SESSION operation to the server. |
| 5819 | * It is the responsibility of the caller to verify the session is |
| 5820 | * expired before calling this routine. |
| 5821 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5822 | 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] | 5823 | { |
| 5824 | int status; |
| 5825 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5826 | struct nfs4_session *session = clp->cl_session; |
| 5827 | |
| 5828 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5829 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5830 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5831 | if (status) |
| 5832 | goto out; |
| 5833 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5834 | /* Init or reset the session slot tables */ |
| 5835 | status = nfs4_setup_session_slot_tables(session); |
| 5836 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5837 | if (status) |
| 5838 | goto out; |
| 5839 | |
| 5840 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5841 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5842 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5843 | out: |
| 5844 | dprintk("<-- %s\n", __func__); |
| 5845 | return status; |
| 5846 | } |
| 5847 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5848 | /* |
| 5849 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5850 | * The caller must serialize access to this routine. |
| 5851 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5852 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5853 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5854 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5855 | struct rpc_message msg = { |
| 5856 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5857 | .rpc_argp = session, |
| 5858 | .rpc_cred = cred, |
| 5859 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5860 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5861 | |
| 5862 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5863 | |
| 5864 | /* session is still being setup */ |
| 5865 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5866 | return status; |
| 5867 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5868 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5869 | |
| 5870 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5871 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5872 | "Session has been destroyed regardless...\n", status); |
| 5873 | |
| 5874 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5875 | return status; |
| 5876 | } |
| 5877 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5878 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5879 | * Renew the cl_session lease. |
| 5880 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5881 | struct nfs4_sequence_data { |
| 5882 | struct nfs_client *clp; |
| 5883 | struct nfs4_sequence_args args; |
| 5884 | struct nfs4_sequence_res res; |
| 5885 | }; |
| 5886 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5887 | static void nfs41_sequence_release(void *data) |
| 5888 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5889 | struct nfs4_sequence_data *calldata = data; |
| 5890 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5891 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5892 | if (atomic_read(&clp->cl_count) > 1) |
| 5893 | nfs4_schedule_state_renewal(clp); |
| 5894 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5895 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5896 | } |
| 5897 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5898 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5899 | { |
| 5900 | switch(task->tk_status) { |
| 5901 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5902 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5903 | return -EAGAIN; |
| 5904 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5905 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5906 | } |
| 5907 | return 0; |
| 5908 | } |
| 5909 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5910 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5911 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5912 | struct nfs4_sequence_data *calldata = data; |
| 5913 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5914 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5915 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5916 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5917 | |
| 5918 | if (task->tk_status < 0) { |
| 5919 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5920 | if (atomic_read(&clp->cl_count) == 1) |
| 5921 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5922 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5923 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5924 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5925 | return; |
| 5926 | } |
| 5927 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5928 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5929 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5930 | dprintk("<-- %s\n", __func__); |
| 5931 | } |
| 5932 | |
| 5933 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5934 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5935 | struct nfs4_sequence_data *calldata = data; |
| 5936 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5937 | struct nfs4_sequence_args *args; |
| 5938 | struct nfs4_sequence_res *res; |
| 5939 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5940 | args = task->tk_msg.rpc_argp; |
| 5941 | res = task->tk_msg.rpc_resp; |
| 5942 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5943 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5944 | } |
| 5945 | |
| 5946 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5947 | .rpc_call_done = nfs41_sequence_call_done, |
| 5948 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5949 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5950 | }; |
| 5951 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5952 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5953 | struct rpc_cred *cred, |
| 5954 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5955 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5956 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5957 | struct rpc_message msg = { |
| 5958 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5959 | .rpc_cred = cred, |
| 5960 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5961 | struct rpc_task_setup task_setup_data = { |
| 5962 | .rpc_client = clp->cl_rpcclient, |
| 5963 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5964 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5965 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5966 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5967 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5968 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5969 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5970 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5971 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5972 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5973 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5974 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5975 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5976 | if (is_privileged) |
| 5977 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5978 | msg.rpc_argp = &calldata->args; |
| 5979 | msg.rpc_resp = &calldata->res; |
| 5980 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5981 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5982 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5983 | return rpc_run_task(&task_setup_data); |
| 5984 | } |
| 5985 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5986 | 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] | 5987 | { |
| 5988 | struct rpc_task *task; |
| 5989 | int ret = 0; |
| 5990 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5991 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5992 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5993 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5994 | if (IS_ERR(task)) |
| 5995 | ret = PTR_ERR(task); |
| 5996 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5997 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5998 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5999 | return ret; |
| 6000 | } |
| 6001 | |
| 6002 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6003 | { |
| 6004 | struct rpc_task *task; |
| 6005 | int ret; |
| 6006 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6007 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6008 | if (IS_ERR(task)) { |
| 6009 | ret = PTR_ERR(task); |
| 6010 | goto out; |
| 6011 | } |
| 6012 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6013 | if (!ret) { |
| 6014 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6015 | |
| 6016 | if (task->tk_status == 0) |
| 6017 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6018 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6019 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6020 | rpc_put_task(task); |
| 6021 | out: |
| 6022 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6023 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6024 | } |
| 6025 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6026 | struct nfs4_reclaim_complete_data { |
| 6027 | struct nfs_client *clp; |
| 6028 | struct nfs41_reclaim_complete_args arg; |
| 6029 | struct nfs41_reclaim_complete_res res; |
| 6030 | }; |
| 6031 | |
| 6032 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6033 | { |
| 6034 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6035 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6036 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6037 | &calldata->arg.seq_args, |
| 6038 | &calldata->res.seq_res, |
| 6039 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6040 | } |
| 6041 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6042 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6043 | { |
| 6044 | switch(task->tk_status) { |
| 6045 | case 0: |
| 6046 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6047 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6048 | break; |
| 6049 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6050 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6051 | /* fall through */ |
| 6052 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6053 | return -EAGAIN; |
| 6054 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6055 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6056 | } |
| 6057 | return 0; |
| 6058 | } |
| 6059 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6060 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6061 | { |
| 6062 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6063 | struct nfs_client *clp = calldata->clp; |
| 6064 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6065 | |
| 6066 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6067 | if (!nfs41_sequence_done(task, res)) |
| 6068 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6069 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6070 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6071 | rpc_restart_call_prepare(task); |
| 6072 | return; |
| 6073 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6074 | dprintk("<-- %s\n", __func__); |
| 6075 | } |
| 6076 | |
| 6077 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6078 | { |
| 6079 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6080 | |
| 6081 | kfree(calldata); |
| 6082 | } |
| 6083 | |
| 6084 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6085 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6086 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6087 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6088 | }; |
| 6089 | |
| 6090 | /* |
| 6091 | * Issue a global reclaim complete. |
| 6092 | */ |
| 6093 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6094 | { |
| 6095 | struct nfs4_reclaim_complete_data *calldata; |
| 6096 | struct rpc_task *task; |
| 6097 | struct rpc_message msg = { |
| 6098 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6099 | }; |
| 6100 | struct rpc_task_setup task_setup_data = { |
| 6101 | .rpc_client = clp->cl_rpcclient, |
| 6102 | .rpc_message = &msg, |
| 6103 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6104 | .flags = RPC_TASK_ASYNC, |
| 6105 | }; |
| 6106 | int status = -ENOMEM; |
| 6107 | |
| 6108 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6109 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6110 | if (calldata == NULL) |
| 6111 | goto out; |
| 6112 | calldata->clp = clp; |
| 6113 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6114 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6115 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6116 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6117 | msg.rpc_argp = &calldata->arg; |
| 6118 | msg.rpc_resp = &calldata->res; |
| 6119 | task_setup_data.callback_data = calldata; |
| 6120 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6121 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6122 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6123 | goto out; |
| 6124 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6125 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6126 | if (status == 0) |
| 6127 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6128 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6129 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6130 | out: |
| 6131 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6132 | return status; |
| 6133 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6134 | |
| 6135 | static void |
| 6136 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6137 | { |
| 6138 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6139 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6140 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6141 | |
| 6142 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6143 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6144 | * right now covering the LAYOUTGET we are about to send. |
| 6145 | * However, that is not so catastrophic, and there seems |
| 6146 | * to be no way to prevent it completely. |
| 6147 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6148 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6149 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6150 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6151 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6152 | NFS_I(lgp->args.inode)->layout, |
| 6153 | lgp->args.ctx->state)) { |
| 6154 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6155 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6159 | { |
| 6160 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6161 | struct inode *inode = lgp->args.inode; |
| 6162 | struct nfs_server *server = NFS_SERVER(inode); |
| 6163 | struct pnfs_layout_hdr *lo; |
| 6164 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6165 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6166 | |
| 6167 | dprintk("--> %s\n", __func__); |
| 6168 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6169 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6170 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6171 | |
| 6172 | switch (task->tk_status) { |
| 6173 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6174 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6175 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6176 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6177 | timeo = rpc_get_timeout(task->tk_client); |
| 6178 | giveup = lgp->args.timestamp + timeo; |
| 6179 | if (time_after(giveup, jiffies)) |
| 6180 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6181 | break; |
| 6182 | case -NFS4ERR_EXPIRED: |
| 6183 | case -NFS4ERR_BAD_STATEID: |
| 6184 | spin_lock(&inode->i_lock); |
| 6185 | lo = NFS_I(inode)->layout; |
| 6186 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6187 | spin_unlock(&inode->i_lock); |
| 6188 | /* If the open stateid was bad, then recover it. */ |
| 6189 | state = lgp->args.ctx->state; |
| 6190 | } else { |
| 6191 | LIST_HEAD(head); |
| 6192 | |
| 6193 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6194 | spin_unlock(&inode->i_lock); |
| 6195 | /* Mark the bad layout state as invalid, then |
| 6196 | * retry using the open stateid. */ |
| 6197 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6198 | } |
| 6199 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6200 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6201 | rpc_restart_call_prepare(task); |
| 6202 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6203 | dprintk("<-- %s\n", __func__); |
| 6204 | } |
| 6205 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6206 | static size_t max_response_pages(struct nfs_server *server) |
| 6207 | { |
| 6208 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6209 | return nfs_page_array_len(0, max_resp_sz); |
| 6210 | } |
| 6211 | |
| 6212 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6213 | { |
| 6214 | int i; |
| 6215 | |
| 6216 | if (!pages) |
| 6217 | return; |
| 6218 | |
| 6219 | for (i = 0; i < size; i++) { |
| 6220 | if (!pages[i]) |
| 6221 | break; |
| 6222 | __free_page(pages[i]); |
| 6223 | } |
| 6224 | kfree(pages); |
| 6225 | } |
| 6226 | |
| 6227 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6228 | { |
| 6229 | struct page **pages; |
| 6230 | int i; |
| 6231 | |
| 6232 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6233 | if (!pages) { |
| 6234 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6235 | return NULL; |
| 6236 | } |
| 6237 | |
| 6238 | for (i = 0; i < size; i++) { |
| 6239 | pages[i] = alloc_page(gfp_flags); |
| 6240 | if (!pages[i]) { |
| 6241 | dprintk("%s: failed to allocate page\n", __func__); |
| 6242 | nfs4_free_pages(pages, size); |
| 6243 | return NULL; |
| 6244 | } |
| 6245 | } |
| 6246 | |
| 6247 | return pages; |
| 6248 | } |
| 6249 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6250 | static void nfs4_layoutget_release(void *calldata) |
| 6251 | { |
| 6252 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6253 | struct inode *inode = lgp->args.inode; |
| 6254 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6255 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6256 | |
| 6257 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6258 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6259 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6260 | put_nfs_open_context(lgp->args.ctx); |
| 6261 | kfree(calldata); |
| 6262 | dprintk("<-- %s\n", __func__); |
| 6263 | } |
| 6264 | |
| 6265 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6266 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6267 | .rpc_call_done = nfs4_layoutget_done, |
| 6268 | .rpc_release = nfs4_layoutget_release, |
| 6269 | }; |
| 6270 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6271 | struct pnfs_layout_segment * |
| 6272 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6273 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6274 | struct inode *inode = lgp->args.inode; |
| 6275 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6276 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6277 | struct rpc_task *task; |
| 6278 | struct rpc_message msg = { |
| 6279 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6280 | .rpc_argp = &lgp->args, |
| 6281 | .rpc_resp = &lgp->res, |
| 6282 | }; |
| 6283 | struct rpc_task_setup task_setup_data = { |
| 6284 | .rpc_client = server->client, |
| 6285 | .rpc_message = &msg, |
| 6286 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6287 | .callback_data = lgp, |
| 6288 | .flags = RPC_TASK_ASYNC, |
| 6289 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6290 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6291 | int status = 0; |
| 6292 | |
| 6293 | dprintk("--> %s\n", __func__); |
| 6294 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6295 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6296 | if (!lgp->args.layout.pages) { |
| 6297 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6298 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6299 | } |
| 6300 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6301 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6302 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6303 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6304 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6305 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6306 | |
| 6307 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6308 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6309 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6310 | task = rpc_run_task(&task_setup_data); |
| 6311 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6312 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6313 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6314 | if (status == 0) |
| 6315 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6316 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6317 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6318 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6319 | rpc_put_task(task); |
| 6320 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6321 | if (status) |
| 6322 | return ERR_PTR(status); |
| 6323 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6324 | } |
| 6325 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6326 | static void |
| 6327 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6328 | { |
| 6329 | struct nfs4_layoutreturn *lrp = calldata; |
| 6330 | |
| 6331 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6332 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6333 | &lrp->args.seq_args, |
| 6334 | &lrp->res.seq_res, |
| 6335 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6339 | { |
| 6340 | struct nfs4_layoutreturn *lrp = calldata; |
| 6341 | struct nfs_server *server; |
| 6342 | |
| 6343 | dprintk("--> %s\n", __func__); |
| 6344 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6345 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6346 | return; |
| 6347 | |
| 6348 | server = NFS_SERVER(lrp->args.inode); |
| 6349 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6350 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6351 | return; |
| 6352 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6353 | dprintk("<-- %s\n", __func__); |
| 6354 | } |
| 6355 | |
| 6356 | static void nfs4_layoutreturn_release(void *calldata) |
| 6357 | { |
| 6358 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6359 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6360 | |
| 6361 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6362 | spin_lock(&lo->plh_inode->i_lock); |
| 6363 | if (lrp->res.lrs_present) |
| 6364 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6365 | lo->plh_block_lgets--; |
| 6366 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6367 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6368 | kfree(calldata); |
| 6369 | dprintk("<-- %s\n", __func__); |
| 6370 | } |
| 6371 | |
| 6372 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6373 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6374 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6375 | .rpc_release = nfs4_layoutreturn_release, |
| 6376 | }; |
| 6377 | |
| 6378 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6379 | { |
| 6380 | struct rpc_task *task; |
| 6381 | struct rpc_message msg = { |
| 6382 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6383 | .rpc_argp = &lrp->args, |
| 6384 | .rpc_resp = &lrp->res, |
| 6385 | }; |
| 6386 | struct rpc_task_setup task_setup_data = { |
| 6387 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6388 | .rpc_message = &msg, |
| 6389 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6390 | .callback_data = lrp, |
| 6391 | }; |
| 6392 | int status; |
| 6393 | |
| 6394 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6395 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6396 | task = rpc_run_task(&task_setup_data); |
| 6397 | if (IS_ERR(task)) |
| 6398 | return PTR_ERR(task); |
| 6399 | status = task->tk_status; |
| 6400 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6401 | rpc_put_task(task); |
| 6402 | return status; |
| 6403 | } |
| 6404 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6405 | /* |
| 6406 | * Retrieve the list of Data Server devices from the MDS. |
| 6407 | */ |
| 6408 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6409 | const struct nfs_fh *fh, |
| 6410 | struct pnfs_devicelist *devlist) |
| 6411 | { |
| 6412 | struct nfs4_getdevicelist_args args = { |
| 6413 | .fh = fh, |
| 6414 | .layoutclass = server->pnfs_curr_ld->id, |
| 6415 | }; |
| 6416 | struct nfs4_getdevicelist_res res = { |
| 6417 | .devlist = devlist, |
| 6418 | }; |
| 6419 | struct rpc_message msg = { |
| 6420 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6421 | .rpc_argp = &args, |
| 6422 | .rpc_resp = &res, |
| 6423 | }; |
| 6424 | int status; |
| 6425 | |
| 6426 | dprintk("--> %s\n", __func__); |
| 6427 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6428 | &res.seq_res, 0); |
| 6429 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6430 | return status; |
| 6431 | } |
| 6432 | |
| 6433 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6434 | const struct nfs_fh *fh, |
| 6435 | struct pnfs_devicelist *devlist) |
| 6436 | { |
| 6437 | struct nfs4_exception exception = { }; |
| 6438 | int err; |
| 6439 | |
| 6440 | do { |
| 6441 | err = nfs4_handle_exception(server, |
| 6442 | _nfs4_getdevicelist(server, fh, devlist), |
| 6443 | &exception); |
| 6444 | } while (exception.retry); |
| 6445 | |
| 6446 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6447 | err, devlist->num_devs); |
| 6448 | |
| 6449 | return err; |
| 6450 | } |
| 6451 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6452 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6453 | static int |
| 6454 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6455 | { |
| 6456 | struct nfs4_getdeviceinfo_args args = { |
| 6457 | .pdev = pdev, |
| 6458 | }; |
| 6459 | struct nfs4_getdeviceinfo_res res = { |
| 6460 | .pdev = pdev, |
| 6461 | }; |
| 6462 | struct rpc_message msg = { |
| 6463 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6464 | .rpc_argp = &args, |
| 6465 | .rpc_resp = &res, |
| 6466 | }; |
| 6467 | int status; |
| 6468 | |
| 6469 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6470 | 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] | 6471 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6472 | |
| 6473 | return status; |
| 6474 | } |
| 6475 | |
| 6476 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6477 | { |
| 6478 | struct nfs4_exception exception = { }; |
| 6479 | int err; |
| 6480 | |
| 6481 | do { |
| 6482 | err = nfs4_handle_exception(server, |
| 6483 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6484 | &exception); |
| 6485 | } while (exception.retry); |
| 6486 | return err; |
| 6487 | } |
| 6488 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6489 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6490 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6491 | { |
| 6492 | struct nfs4_layoutcommit_data *data = calldata; |
| 6493 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6494 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6495 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6496 | nfs41_setup_sequence(session, |
| 6497 | &data->args.seq_args, |
| 6498 | &data->res.seq_res, |
| 6499 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | static void |
| 6503 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6504 | { |
| 6505 | struct nfs4_layoutcommit_data *data = calldata; |
| 6506 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6507 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6508 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6509 | return; |
| 6510 | |
| 6511 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6512 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6513 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6514 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6515 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6516 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6517 | break; |
| 6518 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6519 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6520 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6521 | break; |
| 6522 | default: |
| 6523 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6524 | rpc_restart_call_prepare(task); |
| 6525 | return; |
| 6526 | } |
| 6527 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6528 | } |
| 6529 | |
| 6530 | static void nfs4_layoutcommit_release(void *calldata) |
| 6531 | { |
| 6532 | struct nfs4_layoutcommit_data *data = calldata; |
| 6533 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6534 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6535 | put_rpccred(data->cred); |
| 6536 | kfree(data); |
| 6537 | } |
| 6538 | |
| 6539 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6540 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6541 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6542 | .rpc_release = nfs4_layoutcommit_release, |
| 6543 | }; |
| 6544 | |
| 6545 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6546 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6547 | { |
| 6548 | struct rpc_message msg = { |
| 6549 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6550 | .rpc_argp = &data->args, |
| 6551 | .rpc_resp = &data->res, |
| 6552 | .rpc_cred = data->cred, |
| 6553 | }; |
| 6554 | struct rpc_task_setup task_setup_data = { |
| 6555 | .task = &data->task, |
| 6556 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6557 | .rpc_message = &msg, |
| 6558 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6559 | .callback_data = data, |
| 6560 | .flags = RPC_TASK_ASYNC, |
| 6561 | }; |
| 6562 | struct rpc_task *task; |
| 6563 | int status = 0; |
| 6564 | |
| 6565 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6566 | "lbw: %llu inode %lu\n", |
| 6567 | data->task.tk_pid, sync, |
| 6568 | data->args.lastbytewritten, |
| 6569 | data->args.inode->i_ino); |
| 6570 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6571 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6572 | task = rpc_run_task(&task_setup_data); |
| 6573 | if (IS_ERR(task)) |
| 6574 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6575 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6576 | goto out; |
| 6577 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6578 | if (status != 0) |
| 6579 | goto out; |
| 6580 | status = task->tk_status; |
| 6581 | out: |
| 6582 | dprintk("%s: status %d\n", __func__, status); |
| 6583 | rpc_put_task(task); |
| 6584 | return status; |
| 6585 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6586 | |
| 6587 | static int |
| 6588 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6589 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6590 | { |
| 6591 | struct nfs41_secinfo_no_name_args args = { |
| 6592 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6593 | }; |
| 6594 | struct nfs4_secinfo_res res = { |
| 6595 | .flavors = flavors, |
| 6596 | }; |
| 6597 | struct rpc_message msg = { |
| 6598 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6599 | .rpc_argp = &args, |
| 6600 | .rpc_resp = &res, |
| 6601 | }; |
| 6602 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6603 | } |
| 6604 | |
| 6605 | static int |
| 6606 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6607 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6608 | { |
| 6609 | struct nfs4_exception exception = { }; |
| 6610 | int err; |
| 6611 | do { |
| 6612 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6613 | switch (err) { |
| 6614 | case 0: |
| 6615 | case -NFS4ERR_WRONGSEC: |
| 6616 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6617 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6618 | default: |
| 6619 | err = nfs4_handle_exception(server, err, &exception); |
| 6620 | } |
| 6621 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6622 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6623 | return err; |
| 6624 | } |
| 6625 | |
| 6626 | static int |
| 6627 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6628 | struct nfs_fsinfo *info) |
| 6629 | { |
| 6630 | int err; |
| 6631 | struct page *page; |
| 6632 | rpc_authflavor_t flavor; |
| 6633 | struct nfs4_secinfo_flavors *flavors; |
| 6634 | |
| 6635 | page = alloc_page(GFP_KERNEL); |
| 6636 | if (!page) { |
| 6637 | err = -ENOMEM; |
| 6638 | goto out; |
| 6639 | } |
| 6640 | |
| 6641 | flavors = page_address(page); |
| 6642 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6643 | |
| 6644 | /* |
| 6645 | * Fall back on "guess and check" method if |
| 6646 | * the server doesn't support SECINFO_NO_NAME |
| 6647 | */ |
| 6648 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6649 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6650 | goto out_freepage; |
| 6651 | } |
| 6652 | if (err) |
| 6653 | goto out_freepage; |
| 6654 | |
| 6655 | flavor = nfs_find_best_sec(flavors); |
| 6656 | if (err == 0) |
| 6657 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6658 | |
| 6659 | out_freepage: |
| 6660 | put_page(page); |
| 6661 | if (err == -EACCES) |
| 6662 | return -EPERM; |
| 6663 | out: |
| 6664 | return err; |
| 6665 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6666 | |
| 6667 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6668 | { |
| 6669 | int status; |
| 6670 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6671 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6672 | }; |
| 6673 | struct nfs41_test_stateid_res res; |
| 6674 | struct rpc_message msg = { |
| 6675 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6676 | .rpc_argp = &args, |
| 6677 | .rpc_resp = &res, |
| 6678 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6679 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6680 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6681 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6682 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6683 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6684 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6685 | if (status != NFS_OK) { |
| 6686 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6687 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6688 | } |
| 6689 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6690 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6691 | } |
| 6692 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6693 | /** |
| 6694 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6695 | * |
| 6696 | * @server: server / transport on which to perform the operation |
| 6697 | * @stateid: state ID to test |
| 6698 | * |
| 6699 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6700 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6701 | * failed or the state ID is not currently valid. |
| 6702 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6703 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6704 | { |
| 6705 | struct nfs4_exception exception = { }; |
| 6706 | int err; |
| 6707 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6708 | err = _nfs41_test_stateid(server, stateid); |
| 6709 | if (err != -NFS4ERR_DELAY) |
| 6710 | break; |
| 6711 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6712 | } while (exception.retry); |
| 6713 | return err; |
| 6714 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6715 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6716 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6717 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6718 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6719 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6720 | }; |
| 6721 | struct nfs41_free_stateid_res res; |
| 6722 | struct rpc_message msg = { |
| 6723 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6724 | .rpc_argp = &args, |
| 6725 | .rpc_resp = &res, |
| 6726 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6727 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6728 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6729 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6730 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6731 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6732 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6733 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6734 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6735 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6736 | } |
| 6737 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6738 | /** |
| 6739 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6740 | * |
| 6741 | * @server: server / transport on which to perform the operation |
| 6742 | * @stateid: state ID to release |
| 6743 | * |
| 6744 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6745 | * negative NFS4ERR value is returned. |
| 6746 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6747 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6748 | { |
| 6749 | struct nfs4_exception exception = { }; |
| 6750 | int err; |
| 6751 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6752 | err = _nfs4_free_stateid(server, stateid); |
| 6753 | if (err != -NFS4ERR_DELAY) |
| 6754 | break; |
| 6755 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6756 | } while (exception.retry); |
| 6757 | return err; |
| 6758 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6759 | |
| 6760 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6761 | const nfs4_stateid *s2) |
| 6762 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6763 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6764 | return false; |
| 6765 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6766 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6767 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6768 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6769 | return true; |
| 6770 | |
| 6771 | return false; |
| 6772 | } |
| 6773 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6774 | #endif /* CONFIG_NFS_V4_1 */ |
| 6775 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6776 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6777 | const nfs4_stateid *s2) |
| 6778 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6779 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6783 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6784 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6785 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6786 | .recover_open = nfs4_open_reclaim, |
| 6787 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6788 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6789 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6790 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6791 | }; |
| 6792 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6793 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6794 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6795 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6796 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6797 | .recover_open = nfs4_open_reclaim, |
| 6798 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6799 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6800 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6801 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6802 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6803 | }; |
| 6804 | #endif /* CONFIG_NFS_V4_1 */ |
| 6805 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6806 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6807 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6808 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6809 | .recover_open = nfs4_open_expired, |
| 6810 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6811 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6812 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6813 | }; |
| 6814 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6815 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6816 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6817 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6818 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6819 | .recover_open = nfs41_open_expired, |
| 6820 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6821 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6822 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6823 | }; |
| 6824 | #endif /* CONFIG_NFS_V4_1 */ |
| 6825 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6826 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6827 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6828 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6829 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6830 | }; |
| 6831 | |
| 6832 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6833 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6834 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6835 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6836 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6837 | }; |
| 6838 | #endif |
| 6839 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6840 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6841 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6842 | .init_caps = NFS_CAP_READDIRPLUS |
| 6843 | | NFS_CAP_ATOMIC_OPEN |
| 6844 | | NFS_CAP_CHANGE_ATTR |
| 6845 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6846 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6847 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6848 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6849 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6850 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6851 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6852 | }; |
| 6853 | |
| 6854 | #if defined(CONFIG_NFS_V4_1) |
| 6855 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6856 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6857 | .init_caps = NFS_CAP_READDIRPLUS |
| 6858 | | NFS_CAP_ATOMIC_OPEN |
| 6859 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 6860 | | NFS_CAP_POSIX_LOCK |
| 6861 | | NFS_CAP_STATEID_NFSV41, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6862 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6863 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6864 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6865 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6866 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6867 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6868 | }; |
| 6869 | #endif |
| 6870 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6871 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6872 | [0] = &nfs_v4_0_minor_ops, |
| 6873 | #if defined(CONFIG_NFS_V4_1) |
| 6874 | [1] = &nfs_v4_1_minor_ops, |
| 6875 | #endif |
| 6876 | }; |
| 6877 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6878 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6879 | .create = nfs_create, |
| 6880 | .lookup = nfs_lookup, |
| 6881 | .atomic_open = nfs_atomic_open, |
| 6882 | .link = nfs_link, |
| 6883 | .unlink = nfs_unlink, |
| 6884 | .symlink = nfs_symlink, |
| 6885 | .mkdir = nfs_mkdir, |
| 6886 | .rmdir = nfs_rmdir, |
| 6887 | .mknod = nfs_mknod, |
| 6888 | .rename = nfs_rename, |
| 6889 | .permission = nfs_permission, |
| 6890 | .getattr = nfs_getattr, |
| 6891 | .setattr = nfs_setattr, |
| 6892 | .getxattr = generic_getxattr, |
| 6893 | .setxattr = generic_setxattr, |
| 6894 | .listxattr = generic_listxattr, |
| 6895 | .removexattr = generic_removexattr, |
| 6896 | }; |
| 6897 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6898 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6899 | .permission = nfs_permission, |
| 6900 | .getattr = nfs_getattr, |
| 6901 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6902 | .getxattr = generic_getxattr, |
| 6903 | .setxattr = generic_setxattr, |
| 6904 | .listxattr = generic_listxattr, |
| 6905 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6906 | }; |
| 6907 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6908 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6909 | .version = 4, /* protocol version */ |
| 6910 | .dentry_ops = &nfs4_dentry_operations, |
| 6911 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6912 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6913 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6914 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6915 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6916 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6917 | .getattr = nfs4_proc_getattr, |
| 6918 | .setattr = nfs4_proc_setattr, |
| 6919 | .lookup = nfs4_proc_lookup, |
| 6920 | .access = nfs4_proc_access, |
| 6921 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6922 | .create = nfs4_proc_create, |
| 6923 | .remove = nfs4_proc_remove, |
| 6924 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6925 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6926 | .unlink_done = nfs4_proc_unlink_done, |
| 6927 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6928 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6929 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6930 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6931 | .link = nfs4_proc_link, |
| 6932 | .symlink = nfs4_proc_symlink, |
| 6933 | .mkdir = nfs4_proc_mkdir, |
| 6934 | .rmdir = nfs4_proc_remove, |
| 6935 | .readdir = nfs4_proc_readdir, |
| 6936 | .mknod = nfs4_proc_mknod, |
| 6937 | .statfs = nfs4_proc_statfs, |
| 6938 | .fsinfo = nfs4_proc_fsinfo, |
| 6939 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6940 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6941 | .decode_dirent = nfs4_decode_dirent, |
| 6942 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6943 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6944 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6945 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6946 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6947 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6948 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6949 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6950 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6951 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6952 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6953 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6954 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6955 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6956 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6957 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6958 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6959 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6960 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6961 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6962 | .create_server = nfs4_create_server, |
| 6963 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6964 | }; |
| 6965 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6966 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6967 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6968 | .list = nfs4_xattr_list_nfs4_acl, |
| 6969 | .get = nfs4_xattr_get_nfs4_acl, |
| 6970 | .set = nfs4_xattr_set_nfs4_acl, |
| 6971 | }; |
| 6972 | |
| 6973 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6974 | &nfs4_xattr_nfs4_acl_handler, |
| 6975 | NULL |
| 6976 | }; |
| 6977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6978 | /* |
| 6979 | * Local variables: |
| 6980 | * c-basic-offset: 8 |
| 6981 | * End: |
| 6982 | */ |