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 | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 110 | case -NFS4ERR_FILE_OPEN: |
| 111 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 112 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 114 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 115 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 117 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* |
| 121 | * This is our standard bitmap for GETATTR requests. |
| 122 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 123 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | FATTR4_WORD0_TYPE |
| 125 | | FATTR4_WORD0_CHANGE |
| 126 | | FATTR4_WORD0_SIZE |
| 127 | | FATTR4_WORD0_FSID |
| 128 | | FATTR4_WORD0_FILEID, |
| 129 | FATTR4_WORD1_MODE |
| 130 | | FATTR4_WORD1_NUMLINKS |
| 131 | | FATTR4_WORD1_OWNER |
| 132 | | FATTR4_WORD1_OWNER_GROUP |
| 133 | | FATTR4_WORD1_RAWDEV |
| 134 | | FATTR4_WORD1_SPACE_USED |
| 135 | | FATTR4_WORD1_TIME_ACCESS |
| 136 | | FATTR4_WORD1_TIME_METADATA |
| 137 | | FATTR4_WORD1_TIME_MODIFY |
| 138 | }; |
| 139 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 140 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 141 | FATTR4_WORD0_TYPE |
| 142 | | FATTR4_WORD0_CHANGE |
| 143 | | FATTR4_WORD0_SIZE |
| 144 | | FATTR4_WORD0_FSID |
| 145 | | FATTR4_WORD0_FILEID, |
| 146 | FATTR4_WORD1_MODE |
| 147 | | FATTR4_WORD1_NUMLINKS |
| 148 | | FATTR4_WORD1_OWNER |
| 149 | | FATTR4_WORD1_OWNER_GROUP |
| 150 | | FATTR4_WORD1_RAWDEV |
| 151 | | FATTR4_WORD1_SPACE_USED |
| 152 | | FATTR4_WORD1_TIME_ACCESS |
| 153 | | FATTR4_WORD1_TIME_METADATA |
| 154 | | FATTR4_WORD1_TIME_MODIFY, |
| 155 | FATTR4_WORD2_MDSTHRESHOLD |
| 156 | }; |
| 157 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 158 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 159 | FATTR4_WORD0_TYPE |
| 160 | | FATTR4_WORD0_CHANGE |
| 161 | | FATTR4_WORD0_FILEID, |
| 162 | }; |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | const u32 nfs4_statfs_bitmap[2] = { |
| 165 | FATTR4_WORD0_FILES_AVAIL |
| 166 | | FATTR4_WORD0_FILES_FREE |
| 167 | | FATTR4_WORD0_FILES_TOTAL, |
| 168 | FATTR4_WORD1_SPACE_AVAIL |
| 169 | | FATTR4_WORD1_SPACE_FREE |
| 170 | | FATTR4_WORD1_SPACE_TOTAL |
| 171 | }; |
| 172 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 173 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | FATTR4_WORD0_MAXLINK |
| 175 | | FATTR4_WORD0_MAXNAME, |
| 176 | 0 |
| 177 | }; |
| 178 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 179 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | | FATTR4_WORD0_MAXREAD |
| 181 | | FATTR4_WORD0_MAXWRITE |
| 182 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 183 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 184 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 185 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 188 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 189 | FATTR4_WORD0_TYPE |
| 190 | | FATTR4_WORD0_CHANGE |
| 191 | | FATTR4_WORD0_SIZE |
| 192 | | FATTR4_WORD0_FSID |
| 193 | | FATTR4_WORD0_FILEID |
| 194 | | FATTR4_WORD0_FS_LOCATIONS, |
| 195 | FATTR4_WORD1_MODE |
| 196 | | FATTR4_WORD1_NUMLINKS |
| 197 | | FATTR4_WORD1_OWNER |
| 198 | | FATTR4_WORD1_OWNER_GROUP |
| 199 | | FATTR4_WORD1_RAWDEV |
| 200 | | FATTR4_WORD1_SPACE_USED |
| 201 | | FATTR4_WORD1_TIME_ACCESS |
| 202 | | FATTR4_WORD1_TIME_METADATA |
| 203 | | FATTR4_WORD1_TIME_MODIFY |
| 204 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 205 | }; |
| 206 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 207 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | struct nfs4_readdir_arg *readdir) |
| 209 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 210 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 213 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | readdir->cookie = 0; |
| 219 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 220 | if (cookie == 2) |
| 221 | return; |
| 222 | |
| 223 | /* |
| 224 | * NFSv4 servers do not return entries for '.' and '..' |
| 225 | * Therefore, we fake these entries here. We let '.' |
| 226 | * have cookie 0 and '..' have cookie 1. Note that |
| 227 | * when talking to the server, we always send cookie 0 |
| 228 | * instead of 1 or 2. |
| 229 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 230 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | if (cookie == 0) { |
| 233 | *p++ = xdr_one; /* next */ |
| 234 | *p++ = xdr_zero; /* cookie, first word */ |
| 235 | *p++ = xdr_one; /* cookie, second word */ |
| 236 | *p++ = xdr_one; /* entry len */ |
| 237 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 238 | p++; |
| 239 | *p++ = xdr_one; /* bitmap length */ |
| 240 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 241 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 242 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | *p++ = xdr_one; /* next */ |
| 246 | *p++ = xdr_zero; /* cookie, first word */ |
| 247 | *p++ = xdr_two; /* cookie, second word */ |
| 248 | *p++ = xdr_two; /* entry len */ |
| 249 | memcpy(p, "..\0\0", 4); /* entry */ |
| 250 | p++; |
| 251 | *p++ = xdr_one; /* bitmap length */ |
| 252 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 253 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 254 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | readdir->pgbase = (char *)p - (char *)start; |
| 257 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 258 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 261 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 262 | { |
| 263 | int res = 0; |
| 264 | |
| 265 | might_sleep(); |
| 266 | |
| 267 | if (*timeout <= 0) |
| 268 | *timeout = NFS4_POLL_RETRY_MIN; |
| 269 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 270 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 271 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 272 | if (fatal_signal_pending(current)) |
| 273 | res = -ERESTARTSYS; |
| 274 | *timeout <<= 1; |
| 275 | return res; |
| 276 | } |
| 277 | |
| 278 | /* This is the error handling routine for processes that are allowed |
| 279 | * to sleep. |
| 280 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 281 | 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] | 282 | { |
| 283 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 284 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 285 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 286 | int ret = errorcode; |
| 287 | |
| 288 | exception->retry = 0; |
| 289 | switch(errorcode) { |
| 290 | case 0: |
| 291 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 292 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 293 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 294 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 295 | exception->retry = 1; |
| 296 | return 0; |
| 297 | } |
| 298 | if (state == NULL) |
| 299 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 300 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 301 | if (ret < 0) |
| 302 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 303 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 304 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 305 | case -NFS4ERR_ADMIN_REVOKED: |
| 306 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 307 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 308 | nfs_remove_bad_delegation(inode); |
| 309 | exception->retry = 1; |
| 310 | break; |
| 311 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 312 | if (state == NULL) |
| 313 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 314 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 315 | if (ret < 0) |
| 316 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 317 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 318 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 319 | if (state != NULL) { |
| 320 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 321 | if (ret < 0) |
| 322 | break; |
| 323 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 324 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 325 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 326 | nfs4_schedule_lease_recovery(clp); |
| 327 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 328 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 329 | case -NFS4ERR_BADSESSION: |
| 330 | case -NFS4ERR_BADSLOT: |
| 331 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 332 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 333 | case -NFS4ERR_DEADSESSION: |
| 334 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 335 | case -NFS4ERR_SEQ_MISORDERED: |
| 336 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 337 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 338 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 339 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 340 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 342 | if (exception->timeout > HZ) { |
| 343 | /* We have retried a decent amount, time to |
| 344 | * fail |
| 345 | */ |
| 346 | ret = -EBUSY; |
| 347 | break; |
| 348 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 349 | case -NFS4ERR_GRACE: |
| 350 | case -NFS4ERR_DELAY: |
| 351 | ret = nfs4_delay(server->client, &exception->timeout); |
| 352 | if (ret != 0) |
| 353 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 354 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | case -NFS4ERR_OLD_STATEID: |
| 356 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 357 | break; |
| 358 | case -NFS4ERR_BADOWNER: |
| 359 | /* The following works around a Linux server bug! */ |
| 360 | case -NFS4ERR_BADNAME: |
| 361 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 362 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 363 | exception->retry = 1; |
| 364 | printk(KERN_WARNING "NFS: v4 server %s " |
| 365 | "does not accept raw " |
| 366 | "uid/gids. " |
| 367 | "Reenabling the idmapper.\n", |
| 368 | server->nfs_client->cl_hostname); |
| 369 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 370 | } |
| 371 | /* We failed to handle the error */ |
| 372 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 373 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 374 | ret = nfs4_wait_clnt_recover(clp); |
| 375 | if (ret == 0) |
| 376 | exception->retry = 1; |
| 377 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 381 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | spin_lock(&clp->cl_lock); |
| 384 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 385 | clp->cl_last_renewal = timestamp; |
| 386 | spin_unlock(&clp->cl_lock); |
| 387 | } |
| 388 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 389 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 390 | { |
| 391 | do_renew_lease(server->nfs_client, timestamp); |
| 392 | } |
| 393 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 394 | #if defined(CONFIG_NFS_V4_1) |
| 395 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 396 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 397 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 398 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 399 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 400 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 401 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 402 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 403 | /* just wake up the next guy waiting since |
| 404 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 405 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 406 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 407 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 408 | tbl = res->sr_slot->table; |
| 409 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 410 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 411 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 412 | /* Be nice to the server: try to ensure that the last transmitted |
| 413 | * value for highest_user_slotid <= target_highest_slotid |
| 414 | */ |
| 415 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 416 | send_new_highest_used_slotid = true; |
| 417 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 418 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 419 | send_new_highest_used_slotid = false; |
| 420 | goto out_unlock; |
| 421 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 422 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 423 | |
| 424 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 425 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 426 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 427 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 428 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 429 | if (send_new_highest_used_slotid) |
| 430 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 433 | 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] | 434 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 435 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 436 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 437 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 438 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 439 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 440 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 441 | /* don't increment the sequence number if the task wasn't sent */ |
| 442 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 443 | goto out; |
| 444 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 445 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 446 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 447 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 448 | if (slot->interrupted) { |
| 449 | slot->interrupted = 0; |
| 450 | interrupted = true; |
| 451 | } |
| 452 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 453 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 454 | switch (res->sr_status) { |
| 455 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 456 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 457 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 458 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 459 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 460 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 461 | if (res->sr_status_flags != 0) |
| 462 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 463 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 464 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 465 | case 1: |
| 466 | /* |
| 467 | * sr_status remains 1 if an RPC level error occurred. |
| 468 | * The server may or may not have processed the sequence |
| 469 | * operation.. |
| 470 | * Mark the slot as having hosted an interrupted RPC call. |
| 471 | */ |
| 472 | slot->interrupted = 1; |
| 473 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 474 | case -NFS4ERR_DELAY: |
| 475 | /* The server detected a resend of the RPC call and |
| 476 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 477 | * of RFC5661. |
| 478 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 479 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 480 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 481 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 482 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 483 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 484 | case -NFS4ERR_BADSLOT: |
| 485 | /* |
| 486 | * The slot id we used was probably retired. Try again |
| 487 | * using a different slot id. |
| 488 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 489 | goto retry_nowait; |
| 490 | case -NFS4ERR_SEQ_MISORDERED: |
| 491 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 492 | * Was the last operation on this sequence interrupted? |
| 493 | * If so, retry after bumping the sequence number. |
| 494 | */ |
| 495 | if (interrupted) { |
| 496 | ++slot->seq_nr; |
| 497 | goto retry_nowait; |
| 498 | } |
| 499 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 500 | * Could this slot have been previously retired? |
| 501 | * If so, then the server may be expecting seq_nr = 1! |
| 502 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 503 | if (slot->seq_nr != 1) { |
| 504 | slot->seq_nr = 1; |
| 505 | goto retry_nowait; |
| 506 | } |
| 507 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 508 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 509 | ++slot->seq_nr; |
| 510 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 511 | default: |
| 512 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 513 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 514 | } |
| 515 | out: |
| 516 | /* The session may be reset by one of the error handlers. */ |
| 517 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 518 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 519 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 520 | retry_nowait: |
| 521 | if (rpc_restart_call_prepare(task)) { |
| 522 | task->tk_status = 0; |
| 523 | ret = 0; |
| 524 | } |
| 525 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 526 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 527 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 528 | goto out; |
| 529 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 530 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 531 | } |
| 532 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 533 | static int nfs4_sequence_done(struct rpc_task *task, |
| 534 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 535 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 536 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 537 | return 1; |
| 538 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 541 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 542 | struct nfs4_sequence_res *res, int cache_reply) |
| 543 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 544 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 545 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 546 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 547 | if (cache_reply) |
| 548 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 549 | res->sr_slot = NULL; |
| 550 | } |
| 551 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 552 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 553 | { |
| 554 | args->sa_privileged = 1; |
| 555 | } |
| 556 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 557 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 558 | struct nfs4_sequence_args *args, |
| 559 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 560 | struct rpc_task *task) |
| 561 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 562 | struct nfs4_slot *slot; |
| 563 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 564 | |
| 565 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 566 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 567 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 568 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 569 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 570 | tbl = &session->fc_slot_table; |
| 571 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 572 | task->tk_timeout = 0; |
| 573 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 574 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 575 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 576 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 577 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 578 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 579 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 580 | } |
| 581 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 582 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 583 | if (IS_ERR(slot)) { |
| 584 | /* If out of memory, try again in 1/4 second */ |
| 585 | if (slot == ERR_PTR(-ENOMEM)) |
| 586 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 587 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 588 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 589 | } |
| 590 | spin_unlock(&tbl->slot_tbl_lock); |
| 591 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 592 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 593 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 594 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 595 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 596 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 597 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 598 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 599 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 600 | /* |
| 601 | * sr_status is only set in decode_sequence, and so will remain |
| 602 | * set to 1 if an rpc level failure occurs. |
| 603 | */ |
| 604 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 605 | out_success: |
| 606 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 607 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 608 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 609 | /* Privileged tasks are queued with top priority */ |
| 610 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 611 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 612 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 613 | else |
| 614 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 615 | spin_unlock(&tbl->slot_tbl_lock); |
| 616 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 618 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 620 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 621 | struct nfs4_sequence_args *args, |
| 622 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | struct rpc_task *task) |
| 624 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 625 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 626 | int ret = 0; |
| 627 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 628 | if (session == NULL) { |
| 629 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 631 | } |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 632 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 633 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 634 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 635 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 636 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 637 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 638 | out: |
| 639 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 644 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 645 | struct nfs4_sequence_args *seq_args; |
| 646 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 647 | }; |
| 648 | |
| 649 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 650 | { |
| 651 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 652 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 654 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 655 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 656 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 657 | } |
| 658 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 659 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 660 | { |
| 661 | struct nfs41_call_sync_data *data = calldata; |
| 662 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 663 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 664 | } |
| 665 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 666 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 668 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | }; |
| 670 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 671 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 672 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 673 | struct rpc_message *msg, |
| 674 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 675 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 676 | { |
| 677 | int ret; |
| 678 | struct rpc_task *task; |
| 679 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 680 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 681 | .seq_args = args, |
| 682 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 683 | }; |
| 684 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 685 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | .rpc_message = msg, |
| 687 | .callback_ops = &nfs41_call_sync_ops, |
| 688 | .callback_data = &data |
| 689 | }; |
| 690 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 691 | task = rpc_run_task(&task_setup); |
| 692 | if (IS_ERR(task)) |
| 693 | ret = PTR_ERR(task); |
| 694 | else { |
| 695 | ret = task->tk_status; |
| 696 | rpc_put_task(task); |
| 697 | } |
| 698 | return ret; |
| 699 | } |
| 700 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 701 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 702 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 703 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 704 | struct nfs4_sequence_res *res, int cache_reply) |
| 705 | { |
| 706 | } |
| 707 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 708 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 709 | { |
| 710 | } |
| 711 | |
| 712 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 713 | static int nfs4_sequence_done(struct rpc_task *task, |
| 714 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 715 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 716 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 717 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 718 | #endif /* CONFIG_NFS_V4_1 */ |
| 719 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 720 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 721 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 722 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 723 | struct rpc_message *msg, |
| 724 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 725 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 726 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 727 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 730 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 731 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 732 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 733 | struct rpc_message *msg, |
| 734 | struct nfs4_sequence_args *args, |
| 735 | struct nfs4_sequence_res *res, |
| 736 | int cache_reply) |
| 737 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 738 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 739 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 740 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 741 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 742 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 743 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 745 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 747 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 748 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 749 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 750 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 751 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 752 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 753 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 756 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 757 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct nfs_openargs o_arg; |
| 759 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 760 | struct nfs_open_confirmargs c_arg; |
| 761 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 762 | struct nfs4_string owner_name; |
| 763 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 764 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 766 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 768 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 770 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 771 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 772 | int rpc_status; |
| 773 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 774 | }; |
| 775 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 776 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 777 | int err, struct nfs4_exception *exception) |
| 778 | { |
| 779 | if (err != -EINVAL) |
| 780 | return false; |
| 781 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 782 | return false; |
| 783 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 784 | exception->retry = 1; |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | static enum open_claim_type4 |
| 789 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 790 | enum open_claim_type4 claim) |
| 791 | { |
| 792 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 793 | return claim; |
| 794 | switch (claim) { |
| 795 | default: |
| 796 | return claim; |
| 797 | case NFS4_OPEN_CLAIM_FH: |
| 798 | return NFS4_OPEN_CLAIM_NULL; |
| 799 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 800 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 801 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 802 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 803 | } |
| 804 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 805 | |
| 806 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 807 | { |
| 808 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 809 | p->o_res.seqid = p->o_arg.seqid; |
| 810 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 811 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 812 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 813 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 814 | 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] | 815 | } |
| 816 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 817 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 818 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 819 | const struct iattr *attrs, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 820 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 821 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 823 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | struct inode *dir = parent->d_inode; |
| 825 | struct nfs_server *server = NFS_SERVER(dir); |
| 826 | struct nfs4_opendata *p; |
| 827 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 828 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | if (p == NULL) |
| 830 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 831 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | if (p->o_arg.seqid == NULL) |
| 833 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 834 | nfs_sb_active(dentry->d_sb); |
| 835 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 836 | p->dir = parent; |
| 837 | p->owner = sp; |
| 838 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 839 | p->o_arg.open_flags = flags; |
| 840 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 841 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 842 | * will return permission denied for all bits until close */ |
| 843 | if (!(flags & O_EXCL)) { |
| 844 | /* ask server to check for all possible rights as results |
| 845 | * are cached */ |
| 846 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 847 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 848 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 849 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 850 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 851 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 852 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 853 | p->o_arg.server = server; |
| 854 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 855 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 856 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 857 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 858 | case NFS4_OPEN_CLAIM_NULL: |
| 859 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 860 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 861 | p->o_arg.fh = NFS_FH(dir); |
| 862 | break; |
| 863 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 864 | case NFS4_OPEN_CLAIM_FH: |
| 865 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 866 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 867 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 868 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 869 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 870 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 871 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 872 | p->o_arg.u.attrs = &p->attrs; |
| 873 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 874 | |
| 875 | verf[0] = jiffies; |
| 876 | verf[1] = current->pid; |
| 877 | memcpy(p->o_arg.u.verifier.data, verf, |
| 878 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 879 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 880 | p->c_arg.fh = &p->o_res.fh; |
| 881 | p->c_arg.stateid = &p->o_res.stateid; |
| 882 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 883 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 884 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 885 | return p; |
| 886 | err_free: |
| 887 | kfree(p); |
| 888 | err: |
| 889 | dput(parent); |
| 890 | return NULL; |
| 891 | } |
| 892 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 893 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 894 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 895 | struct nfs4_opendata *p = container_of(kref, |
| 896 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 897 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 898 | |
| 899 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 900 | if (p->state != NULL) |
| 901 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 902 | nfs4_put_state_owner(p->owner); |
| 903 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 904 | dput(p->dentry); |
| 905 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 906 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 907 | kfree(p); |
| 908 | } |
| 909 | |
| 910 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 911 | { |
| 912 | if (p != NULL) |
| 913 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 916 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 917 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 918 | int ret; |
| 919 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 920 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 921 | return ret; |
| 922 | } |
| 923 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | 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] | 925 | { |
| 926 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 928 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 929 | goto out; |
| 930 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 931 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 932 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 933 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 934 | break; |
| 935 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 936 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 937 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 938 | break; |
| 939 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 940 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 941 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 942 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 943 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 944 | return ret; |
| 945 | } |
| 946 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 948 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 949 | if (delegation == NULL) |
| 950 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 952 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 953 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 954 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 955 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 956 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 957 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 958 | return 1; |
| 959 | } |
| 960 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 962 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 964 | case FMODE_WRITE: |
| 965 | state->n_wronly++; |
| 966 | break; |
| 967 | case FMODE_READ: |
| 968 | state->n_rdonly++; |
| 969 | break; |
| 970 | case FMODE_READ|FMODE_WRITE: |
| 971 | state->n_rdwr++; |
| 972 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 974 | } |
| 975 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 976 | 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] | 977 | { |
| 978 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 979 | nfs4_stateid_copy(&state->stateid, stateid); |
| 980 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 981 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 982 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 983 | case FMODE_READ: |
| 984 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 985 | break; |
| 986 | case FMODE_WRITE: |
| 987 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 988 | break; |
| 989 | case FMODE_READ|FMODE_WRITE: |
| 990 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 991 | } |
| 992 | } |
| 993 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 994 | 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] | 995 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 996 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 997 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 998 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 999 | } |
| 1000 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | 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] | 1002 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1003 | /* |
| 1004 | * Protect the call to nfs4_state_set_mode_locked and |
| 1005 | * serialise the stateid update |
| 1006 | */ |
| 1007 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1008 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1009 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1010 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1011 | } |
| 1012 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1014 | write_sequnlock(&state->seqlock); |
| 1015 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1016 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1017 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | 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] | 1021 | { |
| 1022 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1023 | struct nfs_delegation *deleg_cur; |
| 1024 | int ret = 0; |
| 1025 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1026 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1027 | |
| 1028 | rcu_read_lock(); |
| 1029 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1030 | if (deleg_cur == NULL) |
| 1031 | goto no_delegation; |
| 1032 | |
| 1033 | spin_lock(&deleg_cur->lock); |
| 1034 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1035 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1036 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1037 | goto no_delegation_unlock; |
| 1038 | |
| 1039 | if (delegation == NULL) |
| 1040 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1041 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1042 | goto no_delegation_unlock; |
| 1043 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1044 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1046 | ret = 1; |
| 1047 | no_delegation_unlock: |
| 1048 | spin_unlock(&deleg_cur->lock); |
| 1049 | no_delegation: |
| 1050 | rcu_read_unlock(); |
| 1051 | |
| 1052 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | ret = 1; |
| 1055 | } |
| 1056 | |
| 1057 | return ret; |
| 1058 | } |
| 1059 | |
| 1060 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1061 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1062 | { |
| 1063 | struct nfs_delegation *delegation; |
| 1064 | |
| 1065 | rcu_read_lock(); |
| 1066 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1067 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1068 | rcu_read_unlock(); |
| 1069 | return; |
| 1070 | } |
| 1071 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1072 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1075 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | { |
| 1077 | struct nfs4_state *state = opendata->state; |
| 1078 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1079 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1080 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1081 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1082 | nfs4_stateid stateid; |
| 1083 | int ret = -EAGAIN; |
| 1084 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1085 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1086 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1087 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1088 | if (can_open_cached(state, fmode, open_mode)) { |
| 1089 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1090 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1091 | goto out_return_state; |
| 1092 | } |
| 1093 | spin_unlock(&state->owner->so_lock); |
| 1094 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1095 | rcu_read_lock(); |
| 1096 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1097 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1098 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1099 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1100 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1101 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1102 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1103 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1104 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1105 | if (ret != 0) |
| 1106 | goto out; |
| 1107 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1108 | |
| 1109 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1110 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1111 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1112 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1113 | out: |
| 1114 | return ERR_PTR(ret); |
| 1115 | out_return_state: |
| 1116 | atomic_inc(&state->count); |
| 1117 | return state; |
| 1118 | } |
| 1119 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1120 | static void |
| 1121 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1122 | { |
| 1123 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1124 | struct nfs_delegation *delegation; |
| 1125 | int delegation_flags = 0; |
| 1126 | |
| 1127 | rcu_read_lock(); |
| 1128 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1129 | if (delegation) |
| 1130 | delegation_flags = delegation->flags; |
| 1131 | rcu_read_unlock(); |
| 1132 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1133 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1134 | "returning a delegation for " |
| 1135 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1136 | clp->cl_hostname); |
| 1137 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1138 | nfs_inode_set_delegation(state->inode, |
| 1139 | data->owner->so_cred, |
| 1140 | &data->o_res); |
| 1141 | else |
| 1142 | nfs_inode_reclaim_delegation(state->inode, |
| 1143 | data->owner->so_cred, |
| 1144 | &data->o_res); |
| 1145 | } |
| 1146 | |
| 1147 | /* |
| 1148 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1149 | * and update the nfs4_state. |
| 1150 | */ |
| 1151 | static struct nfs4_state * |
| 1152 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1153 | { |
| 1154 | struct inode *inode = data->state->inode; |
| 1155 | struct nfs4_state *state = data->state; |
| 1156 | int ret; |
| 1157 | |
| 1158 | if (!data->rpc_done) { |
| 1159 | ret = data->rpc_status; |
| 1160 | goto err; |
| 1161 | } |
| 1162 | |
| 1163 | ret = -ESTALE; |
| 1164 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1165 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1166 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1167 | goto err; |
| 1168 | |
| 1169 | ret = -ENOMEM; |
| 1170 | state = nfs4_get_open_state(inode, data->owner); |
| 1171 | if (state == NULL) |
| 1172 | goto err; |
| 1173 | |
| 1174 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1175 | if (ret) |
| 1176 | goto err; |
| 1177 | |
| 1178 | if (data->o_res.delegation_type != 0) |
| 1179 | nfs4_opendata_check_deleg(data, state); |
| 1180 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1181 | data->o_arg.fmode); |
| 1182 | |
| 1183 | return state; |
| 1184 | err: |
| 1185 | return ERR_PTR(ret); |
| 1186 | |
| 1187 | } |
| 1188 | |
| 1189 | static struct nfs4_state * |
| 1190 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1191 | { |
| 1192 | struct inode *inode; |
| 1193 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1194 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1195 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1196 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1197 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1198 | goto out; |
| 1199 | } |
| 1200 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1201 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1202 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1203 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1204 | 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] | 1205 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1206 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1207 | goto err; |
| 1208 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1209 | state = nfs4_get_open_state(inode, data->owner); |
| 1210 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1211 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1212 | if (data->o_res.delegation_type != 0) |
| 1213 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1214 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1215 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1216 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1217 | out: |
Trond Myklebust | 7aa262b | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1218 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1219 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1220 | err_put_inode: |
| 1221 | iput(inode); |
| 1222 | err: |
| 1223 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1224 | } |
| 1225 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1226 | static struct nfs4_state * |
| 1227 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1228 | { |
| 1229 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1230 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1231 | return _nfs4_opendata_to_nfs4_state(data); |
| 1232 | } |
| 1233 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1234 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1235 | { |
| 1236 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1237 | struct nfs_open_context *ctx; |
| 1238 | |
| 1239 | spin_lock(&state->inode->i_lock); |
| 1240 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1241 | if (ctx->state != state) |
| 1242 | continue; |
| 1243 | get_nfs_open_context(ctx); |
| 1244 | spin_unlock(&state->inode->i_lock); |
| 1245 | return ctx; |
| 1246 | } |
| 1247 | spin_unlock(&state->inode->i_lock); |
| 1248 | return ERR_PTR(-ENOENT); |
| 1249 | } |
| 1250 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1251 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1252 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1253 | { |
| 1254 | struct nfs4_opendata *opendata; |
| 1255 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1256 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
| 1257 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1258 | if (opendata == NULL) |
| 1259 | return ERR_PTR(-ENOMEM); |
| 1260 | opendata->state = state; |
| 1261 | atomic_inc(&state->count); |
| 1262 | return opendata; |
| 1263 | } |
| 1264 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1265 | 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] | 1266 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1267 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1268 | int ret; |
| 1269 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1270 | opendata->o_arg.open_flags = 0; |
| 1271 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1272 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1273 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1274 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1275 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1276 | if (ret != 0) |
| 1277 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1278 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1279 | if (IS_ERR(newstate)) |
| 1280 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1281 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1282 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1283 | return 0; |
| 1284 | } |
| 1285 | |
| 1286 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1287 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1288 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1289 | int ret; |
| 1290 | |
| 1291 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1292 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1293 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1294 | smp_rmb(); |
| 1295 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1296 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1297 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1298 | if (ret != 0) |
| 1299 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1300 | if (newstate != state) |
| 1301 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1302 | } |
| 1303 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1304 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1305 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1306 | if (ret != 0) |
| 1307 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1308 | if (newstate != state) |
| 1309 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1310 | } |
| 1311 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1312 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1313 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1314 | if (ret != 0) |
| 1315 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1316 | if (newstate != state) |
| 1317 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1318 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1319 | /* |
| 1320 | * We may have performed cached opens for all three recoveries. |
| 1321 | * Check if we need to update the current stateid. |
| 1322 | */ |
| 1323 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1324 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1325 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1326 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1327 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1328 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1329 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1330 | return 0; |
| 1331 | } |
| 1332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | /* |
| 1334 | * OPEN_RECLAIM: |
| 1335 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1337 | 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] | 1338 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1339 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1340 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1341 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | int status; |
| 1343 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1344 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1345 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1346 | if (IS_ERR(opendata)) |
| 1347 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1348 | rcu_read_lock(); |
| 1349 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1350 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1351 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1352 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1353 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1354 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1355 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | return status; |
| 1357 | } |
| 1358 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1359 | 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] | 1360 | { |
| 1361 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1362 | struct nfs4_exception exception = { }; |
| 1363 | int err; |
| 1364 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1365 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1366 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1367 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1368 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1369 | break; |
| 1370 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | } while (exception.retry); |
| 1372 | return err; |
| 1373 | } |
| 1374 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1375 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1376 | { |
| 1377 | struct nfs_open_context *ctx; |
| 1378 | int ret; |
| 1379 | |
| 1380 | ctx = nfs4_state_find_open_context(state); |
| 1381 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1382 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1383 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1384 | put_nfs_open_context(ctx); |
| 1385 | return ret; |
| 1386 | } |
| 1387 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1388 | static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1390 | switch (err) { |
| 1391 | default: |
| 1392 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1393 | "%d.\n", __func__, err); |
| 1394 | case 0: |
| 1395 | case -ENOENT: |
| 1396 | case -ESTALE: |
| 1397 | break; |
| 1398 | case -NFS4ERR_BADSESSION: |
| 1399 | case -NFS4ERR_BADSLOT: |
| 1400 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1401 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1402 | case -NFS4ERR_DEADSESSION: |
| 1403 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1404 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1405 | return -EAGAIN; |
| 1406 | case -NFS4ERR_STALE_CLIENTID: |
| 1407 | case -NFS4ERR_STALE_STATEID: |
| 1408 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1409 | case -NFS4ERR_EXPIRED: |
| 1410 | /* Don't recall a delegation if it was lost */ |
| 1411 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1412 | return -EAGAIN; |
| 1413 | case -NFS4ERR_DELEG_REVOKED: |
| 1414 | case -NFS4ERR_ADMIN_REVOKED: |
| 1415 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1416 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1417 | nfs_inode_find_state_and_recover(state->inode, |
| 1418 | stateid); |
| 1419 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1420 | return 0; |
| 1421 | case -NFS4ERR_DELAY: |
| 1422 | case -NFS4ERR_GRACE: |
| 1423 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1424 | ssleep(1); |
| 1425 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1426 | case -ENOMEM: |
| 1427 | case -NFS4ERR_DENIED: |
| 1428 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1429 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1430 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | return err; |
| 1432 | } |
| 1433 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1434 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1435 | { |
| 1436 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1437 | struct nfs4_opendata *opendata; |
| 1438 | int err; |
| 1439 | |
| 1440 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1441 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1442 | if (IS_ERR(opendata)) |
| 1443 | return PTR_ERR(opendata); |
| 1444 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1445 | err = nfs4_open_recover(opendata, state); |
| 1446 | nfs4_opendata_put(opendata); |
| 1447 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1448 | } |
| 1449 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1450 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1451 | { |
| 1452 | struct nfs4_opendata *data = calldata; |
| 1453 | |
| 1454 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1455 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1456 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1457 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1458 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1459 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1460 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | static void nfs4_open_confirm_release(void *calldata) |
| 1464 | { |
| 1465 | struct nfs4_opendata *data = calldata; |
| 1466 | struct nfs4_state *state = NULL; |
| 1467 | |
| 1468 | /* If this request hasn't been cancelled, do nothing */ |
| 1469 | if (data->cancelled == 0) |
| 1470 | goto out_free; |
| 1471 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1472 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1473 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1474 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1475 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1476 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1477 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1478 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1482 | .rpc_call_done = nfs4_open_confirm_done, |
| 1483 | .rpc_release = nfs4_open_confirm_release, |
| 1484 | }; |
| 1485 | |
| 1486 | /* |
| 1487 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1488 | */ |
| 1489 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1490 | { |
| 1491 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1492 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1493 | struct rpc_message msg = { |
| 1494 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1495 | .rpc_argp = &data->c_arg, |
| 1496 | .rpc_resp = &data->c_res, |
| 1497 | .rpc_cred = data->owner->so_cred, |
| 1498 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1499 | struct rpc_task_setup task_setup_data = { |
| 1500 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1501 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1502 | .callback_ops = &nfs4_open_confirm_ops, |
| 1503 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1504 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1505 | .flags = RPC_TASK_ASYNC, |
| 1506 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | int status; |
| 1508 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1509 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1510 | data->rpc_done = 0; |
| 1511 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1512 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1513 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1514 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1515 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1516 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1517 | if (status != 0) { |
| 1518 | data->cancelled = 1; |
| 1519 | smp_wmb(); |
| 1520 | } else |
| 1521 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1522 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | return status; |
| 1524 | } |
| 1525 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1526 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1528 | struct nfs4_opendata *data = calldata; |
| 1529 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1530 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1531 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1532 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1533 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1534 | /* |
| 1535 | * Check if we still need to send an OPEN call, or if we can use |
| 1536 | * a delegation instead. |
| 1537 | */ |
| 1538 | if (data->state != NULL) { |
| 1539 | struct nfs_delegation *delegation; |
| 1540 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | 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] | 1542 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1543 | rcu_read_lock(); |
| 1544 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1545 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1546 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1547 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | rcu_read_unlock(); |
| 1549 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1550 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1551 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame^] | 1552 | switch (data->o_arg.claim) { |
| 1553 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1554 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1555 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1556 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame^] | 1557 | case NFS4_OPEN_CLAIM_FH: |
| 1558 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1559 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1560 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1561 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1562 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1563 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1564 | &data->o_res.seq_res, |
| 1565 | task) != 0) |
| 1566 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1567 | |
| 1568 | /* Set the create mode (note dependency on the session type) */ |
| 1569 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1570 | if (data->o_arg.open_flags & O_EXCL) { |
| 1571 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1572 | if (nfs4_has_persistent_session(clp)) |
| 1573 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1574 | else if (clp->cl_mvops->minor_version > 0) |
| 1575 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1576 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1577 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1578 | unlock_no_action: |
| 1579 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1580 | out_no_action: |
| 1581 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1582 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1583 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1586 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1587 | { |
| 1588 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1590 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1591 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1592 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1593 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1594 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1595 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1596 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1597 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1598 | case S_IFREG: |
| 1599 | break; |
| 1600 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1601 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1602 | break; |
| 1603 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1604 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1605 | break; |
| 1606 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1607 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1608 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1609 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1610 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1611 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1612 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1613 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1614 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1615 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1616 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1617 | static void nfs4_open_release(void *calldata) |
| 1618 | { |
| 1619 | struct nfs4_opendata *data = calldata; |
| 1620 | struct nfs4_state *state = NULL; |
| 1621 | |
| 1622 | /* If this request hasn't been cancelled, do nothing */ |
| 1623 | if (data->cancelled == 0) |
| 1624 | goto out_free; |
| 1625 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1626 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1627 | goto out_free; |
| 1628 | /* In case we need an open_confirm, no cleanup! */ |
| 1629 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1630 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1631 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1632 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1633 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1634 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1635 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1639 | .rpc_call_prepare = nfs4_open_prepare, |
| 1640 | .rpc_call_done = nfs4_open_done, |
| 1641 | .rpc_release = nfs4_open_release, |
| 1642 | }; |
| 1643 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1644 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1645 | { |
| 1646 | struct inode *dir = data->dir->d_inode; |
| 1647 | struct nfs_server *server = NFS_SERVER(dir); |
| 1648 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1649 | struct nfs_openres *o_res = &data->o_res; |
| 1650 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1651 | struct rpc_message msg = { |
| 1652 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1653 | .rpc_argp = o_arg, |
| 1654 | .rpc_resp = o_res, |
| 1655 | .rpc_cred = data->owner->so_cred, |
| 1656 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1657 | struct rpc_task_setup task_setup_data = { |
| 1658 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1659 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1660 | .callback_ops = &nfs4_open_ops, |
| 1661 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1662 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1663 | .flags = RPC_TASK_ASYNC, |
| 1664 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1665 | int status; |
| 1666 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1667 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1668 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1669 | data->rpc_done = 0; |
| 1670 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1671 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1672 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1673 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1674 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1675 | if (IS_ERR(task)) |
| 1676 | return PTR_ERR(task); |
| 1677 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1678 | if (status != 0) { |
| 1679 | data->cancelled = 1; |
| 1680 | smp_wmb(); |
| 1681 | } else |
| 1682 | status = data->rpc_status; |
| 1683 | rpc_put_task(task); |
| 1684 | |
| 1685 | return status; |
| 1686 | } |
| 1687 | |
| 1688 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1689 | { |
| 1690 | struct inode *dir = data->dir->d_inode; |
| 1691 | struct nfs_openres *o_res = &data->o_res; |
| 1692 | int status; |
| 1693 | |
| 1694 | status = nfs4_run_open_task(data, 1); |
| 1695 | if (status != 0 || !data->rpc_done) |
| 1696 | return status; |
| 1697 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1698 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1699 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1700 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1701 | status = _nfs4_proc_open_confirm(data); |
| 1702 | if (status != 0) |
| 1703 | return status; |
| 1704 | } |
| 1705 | |
| 1706 | return status; |
| 1707 | } |
| 1708 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1709 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1710 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1711 | struct nfs4_state *state, fmode_t fmode, |
| 1712 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1713 | { |
| 1714 | struct nfs_access_entry cache; |
| 1715 | u32 mask; |
| 1716 | |
| 1717 | /* access call failed or for some reason the server doesn't |
| 1718 | * support any access modes -- defer access call until later */ |
| 1719 | if (opendata->o_res.access_supported == 0) |
| 1720 | return 0; |
| 1721 | |
| 1722 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1723 | /* 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] | 1724 | * write mode bits, but POSIX allows the creating process to write. |
| 1725 | * use openflags to check for exec, because fmode won't |
| 1726 | * always have FMODE_EXEC set when file open for exec. */ |
| 1727 | if (openflags & __FMODE_EXEC) { |
| 1728 | /* ONLY check for exec rights */ |
| 1729 | mask = MAY_EXEC; |
| 1730 | } else if (fmode & FMODE_READ) |
| 1731 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1732 | |
| 1733 | cache.cred = cred; |
| 1734 | cache.jiffies = jiffies; |
| 1735 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1736 | nfs_access_add_cache(state->inode, &cache); |
| 1737 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1738 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1739 | return 0; |
| 1740 | |
| 1741 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1742 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1743 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1746 | /* |
| 1747 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1748 | */ |
| 1749 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1750 | { |
| 1751 | struct inode *dir = data->dir->d_inode; |
| 1752 | struct nfs_server *server = NFS_SERVER(dir); |
| 1753 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1754 | struct nfs_openres *o_res = &data->o_res; |
| 1755 | int status; |
| 1756 | |
| 1757 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1758 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1759 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1760 | if (status != 0) { |
| 1761 | if (status == -NFS4ERR_BADNAME && |
| 1762 | !(o_arg->open_flags & O_CREAT)) |
| 1763 | return -ENOENT; |
| 1764 | return status; |
| 1765 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1766 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1767 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1768 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1769 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1770 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1771 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1772 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1774 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1776 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | } |
| 1778 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1779 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1780 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1783 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1784 | { |
| 1785 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1786 | } |
| 1787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | /* |
| 1789 | * OPEN_EXPIRED: |
| 1790 | * reclaim state on the server after a network partition. |
| 1791 | * Assumes caller holds the appropriate lock |
| 1792 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1793 | 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] | 1794 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1795 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1796 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1798 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1799 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1800 | if (IS_ERR(opendata)) |
| 1801 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1802 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1803 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1804 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1805 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1806 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1809 | 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] | 1810 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1811 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1812 | struct nfs4_exception exception = { }; |
| 1813 | int err; |
| 1814 | |
| 1815 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1816 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1817 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1818 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1819 | switch (err) { |
| 1820 | default: |
| 1821 | goto out; |
| 1822 | case -NFS4ERR_GRACE: |
| 1823 | case -NFS4ERR_DELAY: |
| 1824 | nfs4_handle_exception(server, err, &exception); |
| 1825 | err = 0; |
| 1826 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1827 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1828 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1829 | return err; |
| 1830 | } |
| 1831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1833 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1835 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1837 | ctx = nfs4_state_find_open_context(state); |
| 1838 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1839 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1840 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1841 | put_nfs_open_context(ctx); |
| 1842 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1845 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1846 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1847 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1848 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1849 | nfs4_stateid *stateid = &state->stateid; |
| 1850 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1851 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1852 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1853 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1854 | return; |
| 1855 | |
| 1856 | status = nfs41_test_stateid(server, stateid); |
| 1857 | if (status != NFS_OK) { |
| 1858 | /* Free the stateid unless the server explicitly |
| 1859 | * informs us the stateid is unrecognized. */ |
| 1860 | if (status != -NFS4ERR_BAD_STATEID) |
| 1861 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1862 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1863 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1864 | write_seqlock(&state->seqlock); |
| 1865 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1866 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1867 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1873 | * |
| 1874 | * @state: NFSv4 state for an inode |
| 1875 | * |
| 1876 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1877 | * Otherwise a negative NFS4ERR value is returned. |
| 1878 | */ |
| 1879 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1880 | { |
| 1881 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1882 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1883 | int status; |
| 1884 | |
| 1885 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1886 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1887 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1888 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1889 | return -NFS4ERR_BAD_STATEID; |
| 1890 | |
| 1891 | status = nfs41_test_stateid(server, stateid); |
| 1892 | if (status != NFS_OK) { |
| 1893 | /* Free the stateid unless the server explicitly |
| 1894 | * informs us the stateid is unrecognized. */ |
| 1895 | if (status != -NFS4ERR_BAD_STATEID) |
| 1896 | nfs41_free_stateid(server, stateid); |
| 1897 | |
| 1898 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1899 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1900 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1901 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1902 | } |
| 1903 | return status; |
| 1904 | } |
| 1905 | |
| 1906 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1907 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1908 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1909 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1910 | nfs41_clear_delegation_stateid(state); |
| 1911 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1912 | if (status != NFS_OK) |
| 1913 | status = nfs4_open_expired(sp, state); |
| 1914 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1915 | } |
| 1916 | #endif |
| 1917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1919 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1920 | * fields corresponding to attributes that were used to store the verifier. |
| 1921 | * Make sure we clobber those fields in the later setattr call |
| 1922 | */ |
| 1923 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1924 | { |
| 1925 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1926 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1927 | sattr->ia_valid |= ATTR_ATIME; |
| 1928 | |
| 1929 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1930 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1931 | sattr->ia_valid |= ATTR_MTIME; |
| 1932 | } |
| 1933 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1934 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1935 | fmode_t fmode, |
| 1936 | int flags, |
| 1937 | struct nfs4_state **res) |
| 1938 | { |
| 1939 | struct nfs4_state_owner *sp = opendata->owner; |
| 1940 | struct nfs_server *server = sp->so_server; |
| 1941 | struct nfs4_state *state; |
| 1942 | unsigned int seq; |
| 1943 | int ret; |
| 1944 | |
| 1945 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1946 | |
| 1947 | ret = _nfs4_proc_open(opendata); |
| 1948 | if (ret != 0) |
| 1949 | goto out; |
| 1950 | |
| 1951 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1952 | ret = PTR_ERR(state); |
| 1953 | if (IS_ERR(state)) |
| 1954 | goto out; |
| 1955 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1956 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1957 | |
| 1958 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 1959 | if (ret != 0) |
| 1960 | goto out; |
| 1961 | |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1962 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1963 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1964 | *res = state; |
| 1965 | out: |
| 1966 | return ret; |
| 1967 | } |
| 1968 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1969 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1970 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1972 | static int _nfs4_do_open(struct inode *dir, |
| 1973 | struct dentry *dentry, |
| 1974 | fmode_t fmode, |
| 1975 | int flags, |
| 1976 | struct iattr *sattr, |
| 1977 | struct rpc_cred *cred, |
| 1978 | struct nfs4_state **res, |
| 1979 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | { |
| 1981 | struct nfs4_state_owner *sp; |
| 1982 | struct nfs4_state *state = NULL; |
| 1983 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1984 | struct nfs4_opendata *opendata; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1985 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1986 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | |
| 1988 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1990 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1991 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1993 | goto out_err; |
| 1994 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1995 | status = nfs4_recover_expired_lease(server); |
| 1996 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1997 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1998 | if (dentry->d_inode != NULL) |
| 1999 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2000 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2001 | if (dentry->d_inode) |
| 2002 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2003 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2004 | claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2005 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2006 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2008 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2009 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2010 | if (!opendata->f_attr.mdsthreshold) |
| 2011 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2012 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2013 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2014 | if (dentry->d_inode != NULL) |
| 2015 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2016 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2017 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2018 | if (status != 0) |
| 2019 | goto err_opendata_put; |
| 2020 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2021 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2022 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2023 | nfs4_exclusive_attrset(opendata, sattr); |
| 2024 | |
| 2025 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2026 | status = nfs4_do_setattr(state->inode, cred, |
| 2027 | opendata->o_res.f_attr, sattr, |
| 2028 | state); |
| 2029 | if (status == 0) |
| 2030 | nfs_setattr_update_inode(state->inode, sattr); |
| 2031 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2032 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2033 | |
| 2034 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2035 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2036 | else |
| 2037 | kfree(opendata->f_attr.mdsthreshold); |
| 2038 | opendata->f_attr.mdsthreshold = NULL; |
| 2039 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2040 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | *res = state; |
| 2043 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2044 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2045 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2046 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2047 | err_put_state_owner: |
| 2048 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | *res = NULL; |
| 2051 | return status; |
| 2052 | } |
| 2053 | |
| 2054 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2055 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2056 | struct dentry *dentry, |
| 2057 | fmode_t fmode, |
| 2058 | int flags, |
| 2059 | struct iattr *sattr, |
| 2060 | struct rpc_cred *cred, |
| 2061 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2063 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | struct nfs4_exception exception = { }; |
| 2065 | struct nfs4_state *res; |
| 2066 | int status; |
| 2067 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2068 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2070 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2071 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | if (status == 0) |
| 2073 | break; |
| 2074 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2075 | * book-keeping w.r.t. state-changing operations |
| 2076 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2077 | * It is actually a sign of a bug on the client or on the server. |
| 2078 | * |
| 2079 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2080 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | * have unhashed the old state_owner for us, and that we can |
| 2082 | * therefore safely retry using a new one. We should still warn |
| 2083 | * the user though... |
| 2084 | */ |
| 2085 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2086 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2087 | " returned a bad sequence-id error!\n", |
| 2088 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | exception.retry = 1; |
| 2090 | continue; |
| 2091 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2092 | /* |
| 2093 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2094 | * state before it received the OPEN_CONFIRM. |
| 2095 | * Recover by retrying the request as per the discussion |
| 2096 | * on Page 181 of RFC3530. |
| 2097 | */ |
| 2098 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2099 | exception.retry = 1; |
| 2100 | continue; |
| 2101 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2102 | if (status == -EAGAIN) { |
| 2103 | /* We must have found a delegation */ |
| 2104 | exception.retry = 1; |
| 2105 | continue; |
| 2106 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2107 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2108 | continue; |
| 2109 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | status, &exception)); |
| 2111 | } while (exception.retry); |
| 2112 | return res; |
| 2113 | } |
| 2114 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2115 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2116 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2117 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2119 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2121 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | .iap = sattr, |
| 2123 | .server = server, |
| 2124 | .bitmask = server->attr_bitmask, |
| 2125 | }; |
| 2126 | struct nfs_setattrres res = { |
| 2127 | .fattr = fattr, |
| 2128 | .server = server, |
| 2129 | }; |
| 2130 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2131 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2132 | .rpc_argp = &arg, |
| 2133 | .rpc_resp = &res, |
| 2134 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2136 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2137 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2139 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2141 | if (state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2142 | struct nfs_lockowner lockowner = { |
| 2143 | .l_owner = current->files, |
| 2144 | .l_pid = current->tgid, |
| 2145 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2146 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2147 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2148 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2149 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2150 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2151 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2152 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2154 | 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] | 2155 | if (status == 0 && state != NULL) |
| 2156 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2157 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2160 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2161 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2162 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2164 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2165 | struct nfs4_exception exception = { |
| 2166 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2167 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2168 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | int err; |
| 2170 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2171 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2172 | switch (err) { |
| 2173 | case -NFS4ERR_OPENMODE: |
| 2174 | if (state && !(state->state & FMODE_WRITE)) { |
| 2175 | err = -EBADF; |
| 2176 | if (sattr->ia_valid & ATTR_OPEN) |
| 2177 | err = -EACCES; |
| 2178 | goto out; |
| 2179 | } |
| 2180 | } |
| 2181 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2183 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | return err; |
| 2185 | } |
| 2186 | |
| 2187 | struct nfs4_closedata { |
| 2188 | struct inode *inode; |
| 2189 | struct nfs4_state *state; |
| 2190 | struct nfs_closeargs arg; |
| 2191 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2192 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2193 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2194 | bool roc; |
| 2195 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | }; |
| 2197 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2198 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2199 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2200 | struct nfs4_closedata *calldata = data; |
| 2201 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2202 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2203 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2204 | if (calldata->roc) |
| 2205 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2206 | nfs4_put_open_state(calldata->state); |
| 2207 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2208 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2209 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2210 | kfree(calldata); |
| 2211 | } |
| 2212 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2213 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2214 | fmode_t fmode) |
| 2215 | { |
| 2216 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2217 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2218 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2219 | case FMODE_WRITE: |
| 2220 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2221 | break; |
| 2222 | case FMODE_READ: |
| 2223 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2224 | break; |
| 2225 | case 0: |
| 2226 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2227 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2228 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2229 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2230 | spin_unlock(&state->owner->so_lock); |
| 2231 | } |
| 2232 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2233 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2235 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2238 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2239 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2240 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2241 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | /* hmm. we are done with the inode, and in the process of freeing |
| 2243 | * the state_owner. we keep this around to process errors |
| 2244 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | switch (task->tk_status) { |
| 2246 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2247 | if (calldata->roc) |
| 2248 | pnfs_roc_set_barrier(state->inode, |
| 2249 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2250 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2251 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2252 | nfs4_close_clear_stateid_flags(state, |
| 2253 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | break; |
| 2255 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2256 | case -NFS4ERR_OLD_STATEID: |
| 2257 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2259 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2260 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2262 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2263 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2265 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2266 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2267 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2270 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2272 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2273 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2274 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2275 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2276 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2277 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2278 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2279 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2280 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2281 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2282 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2283 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2284 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2285 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2286 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2287 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2288 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2289 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2290 | } |
| 2291 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2292 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2293 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2294 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2295 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2296 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2297 | if (!nfs4_valid_open_stateid(state)) |
| 2298 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2299 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2300 | |
| 2301 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2302 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2303 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2304 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2305 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2306 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2307 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2308 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2309 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2310 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2311 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2312 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2313 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2314 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2315 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2316 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2317 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2318 | &calldata->arg.seq_args, |
| 2319 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2320 | task) != 0) |
| 2321 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2322 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2323 | return; |
| 2324 | out_no_action: |
| 2325 | task->tk_action = NULL; |
| 2326 | out_wait: |
| 2327 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2330 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2331 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2332 | .rpc_call_done = nfs4_close_done, |
| 2333 | .rpc_release = nfs4_free_closedata, |
| 2334 | }; |
| 2335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | /* |
| 2337 | * It is possible for data to be read/written from a mem-mapped file |
| 2338 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2339 | * This means that we can't safely call nfsv4 close on a file until |
| 2340 | * the inode is cleared. This in turn means that we are not good |
| 2341 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2342 | * share state even when we are done with one of the three share |
| 2343 | * stateid's in the inode. |
| 2344 | * |
| 2345 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2346 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2347 | 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] | 2348 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2349 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2351 | struct nfs4_state_owner *sp = state->owner; |
| 2352 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2353 | struct rpc_message msg = { |
| 2354 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2355 | .rpc_cred = state->owner->so_cred, |
| 2356 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2357 | struct rpc_task_setup task_setup_data = { |
| 2358 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2359 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2360 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2361 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2362 | .flags = RPC_TASK_ASYNC, |
| 2363 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2364 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2366 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2368 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2369 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2370 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2372 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2373 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2375 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2376 | if (calldata->arg.seqid == NULL) |
| 2377 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2378 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2379 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2380 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2381 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2382 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2383 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2384 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2385 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2386 | msg.rpc_argp = &calldata->arg; |
| 2387 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2388 | task_setup_data.callback_data = calldata; |
| 2389 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2390 | if (IS_ERR(task)) |
| 2391 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2392 | status = 0; |
| 2393 | if (wait) |
| 2394 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2395 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2396 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2397 | out_free_calldata: |
| 2398 | kfree(calldata); |
| 2399 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2400 | nfs4_put_open_state(state); |
| 2401 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2402 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2405 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2406 | 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] | 2407 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | struct nfs4_state *state; |
| 2409 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2410 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2411 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2412 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2413 | if (IS_ERR(state)) |
| 2414 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2415 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2416 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2419 | 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] | 2420 | { |
| 2421 | if (ctx->state == NULL) |
| 2422 | return; |
| 2423 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2424 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2425 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2426 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | |
| 2429 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2430 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2431 | struct nfs4_server_caps_arg args = { |
| 2432 | .fhandle = fhandle, |
| 2433 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | struct nfs4_server_caps_res res = {}; |
| 2435 | struct rpc_message msg = { |
| 2436 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2437 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | .rpc_resp = &res, |
| 2439 | }; |
| 2440 | int status; |
| 2441 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2442 | 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] | 2443 | if (status == 0) { |
| 2444 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2445 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2446 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2447 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2448 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2449 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2451 | server->caps |= NFS_CAP_ACLS; |
| 2452 | if (res.has_links != 0) |
| 2453 | server->caps |= NFS_CAP_HARDLINKS; |
| 2454 | if (res.has_symlinks != 0) |
| 2455 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2456 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2457 | server->caps |= NFS_CAP_FILEID; |
| 2458 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2459 | server->caps |= NFS_CAP_MODE; |
| 2460 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2461 | server->caps |= NFS_CAP_NLINK; |
| 2462 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2463 | server->caps |= NFS_CAP_OWNER; |
| 2464 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2465 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2466 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2467 | server->caps |= NFS_CAP_ATIME; |
| 2468 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2469 | server->caps |= NFS_CAP_CTIME; |
| 2470 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2471 | server->caps |= NFS_CAP_MTIME; |
| 2472 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2473 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2474 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2475 | 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] | 2476 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2477 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | return status; |
| 2481 | } |
| 2482 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2483 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | { |
| 2485 | struct nfs4_exception exception = { }; |
| 2486 | int err; |
| 2487 | do { |
| 2488 | err = nfs4_handle_exception(server, |
| 2489 | _nfs4_server_capabilities(server, fhandle), |
| 2490 | &exception); |
| 2491 | } while (exception.retry); |
| 2492 | return err; |
| 2493 | } |
| 2494 | |
| 2495 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2496 | struct nfs_fsinfo *info) |
| 2497 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | struct nfs4_lookup_root_arg args = { |
| 2499 | .bitmask = nfs4_fattr_bitmap, |
| 2500 | }; |
| 2501 | struct nfs4_lookup_res res = { |
| 2502 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2503 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | .fh = fhandle, |
| 2505 | }; |
| 2506 | struct rpc_message msg = { |
| 2507 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2508 | .rpc_argp = &args, |
| 2509 | .rpc_resp = &res, |
| 2510 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2511 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2512 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2513 | 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] | 2514 | } |
| 2515 | |
| 2516 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2517 | struct nfs_fsinfo *info) |
| 2518 | { |
| 2519 | struct nfs4_exception exception = { }; |
| 2520 | int err; |
| 2521 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2522 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2523 | switch (err) { |
| 2524 | case 0: |
| 2525 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2526 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2527 | default: |
| 2528 | err = nfs4_handle_exception(server, err, &exception); |
| 2529 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2531 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | return err; |
| 2533 | } |
| 2534 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2535 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2536 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2537 | { |
| 2538 | struct rpc_auth *auth; |
| 2539 | int ret; |
| 2540 | |
| 2541 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2542 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2543 | ret = -EIO; |
| 2544 | goto out; |
| 2545 | } |
| 2546 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2547 | out: |
| 2548 | return ret; |
| 2549 | } |
| 2550 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2551 | 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] | 2552 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2554 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2555 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2557 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2558 | if (len < 0) |
| 2559 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2560 | |
| 2561 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2562 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2563 | * thus has already been tried. */ |
| 2564 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2565 | continue; |
| 2566 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2567 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2568 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2569 | continue; |
| 2570 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2571 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2572 | /* |
| 2573 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2574 | * to access the mount. It could also mean that we tried to mount |
| 2575 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2576 | * existing mount programs don't handle -EACCES very well so it should |
| 2577 | * be mapped to -EPERM instead. |
| 2578 | */ |
| 2579 | if (status == -EACCES) |
| 2580 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2581 | return status; |
| 2582 | } |
| 2583 | |
| 2584 | /* |
| 2585 | * get the file handle for the "/" directory on the server |
| 2586 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2587 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2588 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2589 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2590 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2591 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2592 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2593 | /* |
| 2594 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2595 | * by nfs4_map_errors() as this function exits. |
| 2596 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2597 | 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] | 2598 | if (status == 0) |
| 2599 | status = nfs4_server_capabilities(server, fhandle); |
| 2600 | if (status == 0) |
| 2601 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2602 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2605 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2606 | struct nfs_fsinfo *info) |
| 2607 | { |
| 2608 | int error; |
| 2609 | struct nfs_fattr *fattr = info->fattr; |
| 2610 | |
| 2611 | error = nfs4_server_capabilities(server, mntfh); |
| 2612 | if (error < 0) { |
| 2613 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2614 | return error; |
| 2615 | } |
| 2616 | |
| 2617 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2618 | if (error < 0) { |
| 2619 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2620 | return error; |
| 2621 | } |
| 2622 | |
| 2623 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2624 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2625 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2626 | |
| 2627 | return error; |
| 2628 | } |
| 2629 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2630 | /* |
| 2631 | * Get locations and (maybe) other attributes of a referral. |
| 2632 | * Note that we'll actually follow the referral later when |
| 2633 | * we detect fsid mismatch in inode revalidation |
| 2634 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2635 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2636 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2637 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2638 | { |
| 2639 | int status = -ENOMEM; |
| 2640 | struct page *page = NULL; |
| 2641 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2642 | |
| 2643 | page = alloc_page(GFP_KERNEL); |
| 2644 | if (page == NULL) |
| 2645 | goto out; |
| 2646 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2647 | if (locations == NULL) |
| 2648 | goto out; |
| 2649 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2650 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2651 | if (status != 0) |
| 2652 | goto out; |
| 2653 | /* Make sure server returned a different fsid for the referral */ |
| 2654 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2655 | dprintk("%s: server did not return a different fsid for" |
| 2656 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2657 | status = -EIO; |
| 2658 | goto out; |
| 2659 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2660 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2661 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2662 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2663 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2664 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2665 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2666 | out: |
| 2667 | if (page) |
| 2668 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2669 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2670 | return status; |
| 2671 | } |
| 2672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2674 | { |
| 2675 | struct nfs4_getattr_arg args = { |
| 2676 | .fh = fhandle, |
| 2677 | .bitmask = server->attr_bitmask, |
| 2678 | }; |
| 2679 | struct nfs4_getattr_res res = { |
| 2680 | .fattr = fattr, |
| 2681 | .server = server, |
| 2682 | }; |
| 2683 | struct rpc_message msg = { |
| 2684 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2685 | .rpc_argp = &args, |
| 2686 | .rpc_resp = &res, |
| 2687 | }; |
| 2688 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2689 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2690 | 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] | 2691 | } |
| 2692 | |
| 2693 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2694 | { |
| 2695 | struct nfs4_exception exception = { }; |
| 2696 | int err; |
| 2697 | do { |
| 2698 | err = nfs4_handle_exception(server, |
| 2699 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2700 | &exception); |
| 2701 | } while (exception.retry); |
| 2702 | return err; |
| 2703 | } |
| 2704 | |
| 2705 | /* |
| 2706 | * The file is not closed if it is opened due to the a request to change |
| 2707 | * the size of the file. The open call will not be needed once the |
| 2708 | * VFS layer lookup-intents are implemented. |
| 2709 | * |
| 2710 | * Close is called when the inode is destroyed. |
| 2711 | * If we haven't opened the file for O_WRONLY, we |
| 2712 | * need to in the size_change case to obtain a stateid. |
| 2713 | * |
| 2714 | * Got race? |
| 2715 | * Because OPEN is always done by name in nfsv4, it is |
| 2716 | * possible that we opened a different file by the same |
| 2717 | * name. We can recognize this race condition, but we |
| 2718 | * can't do anything about it besides returning an error. |
| 2719 | * |
| 2720 | * This will be fixed with VFS changes (lookup-intent). |
| 2721 | */ |
| 2722 | static int |
| 2723 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2724 | struct iattr *sattr) |
| 2725 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2726 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2727 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2728 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | int status; |
| 2730 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2731 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2732 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2733 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2734 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2736 | /* Deal with open(O_TRUNC) */ |
| 2737 | if (sattr->ia_valid & ATTR_OPEN) |
| 2738 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2739 | |
| 2740 | /* Optimization: if the end result is no change, don't RPC */ |
| 2741 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2742 | return 0; |
| 2743 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2744 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2745 | if (sattr->ia_valid & ATTR_FILE) { |
| 2746 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2747 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2748 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2749 | if (ctx) { |
| 2750 | cred = ctx->cred; |
| 2751 | state = ctx->state; |
| 2752 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2756 | if (status == 0) |
| 2757 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | return status; |
| 2759 | } |
| 2760 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2761 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2762 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2763 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2764 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2765 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2766 | int status; |
| 2767 | struct nfs4_lookup_arg args = { |
| 2768 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2769 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2770 | .name = name, |
| 2771 | }; |
| 2772 | struct nfs4_lookup_res res = { |
| 2773 | .server = server, |
| 2774 | .fattr = fattr, |
| 2775 | .fh = fhandle, |
| 2776 | }; |
| 2777 | struct rpc_message msg = { |
| 2778 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2779 | .rpc_argp = &args, |
| 2780 | .rpc_resp = &res, |
| 2781 | }; |
| 2782 | |
| 2783 | nfs_fattr_init(fattr); |
| 2784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2786 | 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] | 2787 | dprintk("NFS reply lookup: %d\n", status); |
| 2788 | return status; |
| 2789 | } |
| 2790 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2791 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2792 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2793 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2794 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2795 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2796 | fattr->nlink = 2; |
| 2797 | } |
| 2798 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2799 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2800 | struct qstr *name, struct nfs_fh *fhandle, |
| 2801 | struct nfs_fattr *fattr) |
| 2802 | { |
| 2803 | struct nfs4_exception exception = { }; |
| 2804 | struct rpc_clnt *client = *clnt; |
| 2805 | int err; |
| 2806 | do { |
| 2807 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2808 | switch (err) { |
| 2809 | case -NFS4ERR_BADNAME: |
| 2810 | err = -ENOENT; |
| 2811 | goto out; |
| 2812 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2813 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2814 | goto out; |
| 2815 | case -NFS4ERR_WRONGSEC: |
| 2816 | err = -EPERM; |
| 2817 | if (client != *clnt) |
| 2818 | goto out; |
| 2819 | |
| 2820 | client = nfs4_create_sec_client(client, dir, name); |
| 2821 | if (IS_ERR(client)) |
| 2822 | return PTR_ERR(client); |
| 2823 | |
| 2824 | exception.retry = 1; |
| 2825 | break; |
| 2826 | default: |
| 2827 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2828 | } |
| 2829 | } while (exception.retry); |
| 2830 | |
| 2831 | out: |
| 2832 | if (err == 0) |
| 2833 | *clnt = client; |
| 2834 | else if (client != *clnt) |
| 2835 | rpc_shutdown_client(client); |
| 2836 | |
| 2837 | return err; |
| 2838 | } |
| 2839 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2840 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2841 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2843 | int status; |
| 2844 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2845 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2846 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2847 | if (client != NFS_CLIENT(dir)) { |
| 2848 | rpc_shutdown_client(client); |
| 2849 | nfs_fixup_secinfo_attributes(fattr); |
| 2850 | } |
| 2851 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2854 | struct rpc_clnt * |
| 2855 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2856 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2857 | { |
| 2858 | int status; |
| 2859 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2860 | |
| 2861 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2862 | if (status < 0) { |
| 2863 | rpc_shutdown_client(client); |
| 2864 | return ERR_PTR(status); |
| 2865 | } |
| 2866 | return client; |
| 2867 | } |
| 2868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2870 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2871 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | struct nfs4_accessargs args = { |
| 2873 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2874 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2876 | struct nfs4_accessres res = { |
| 2877 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2878 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | struct rpc_message msg = { |
| 2880 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2881 | .rpc_argp = &args, |
| 2882 | .rpc_resp = &res, |
| 2883 | .rpc_cred = entry->cred, |
| 2884 | }; |
| 2885 | int mode = entry->mask; |
| 2886 | int status; |
| 2887 | |
| 2888 | /* |
| 2889 | * Determine which access bits we want to ask for... |
| 2890 | */ |
| 2891 | if (mode & MAY_READ) |
| 2892 | args.access |= NFS4_ACCESS_READ; |
| 2893 | if (S_ISDIR(inode->i_mode)) { |
| 2894 | if (mode & MAY_WRITE) |
| 2895 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2896 | if (mode & MAY_EXEC) |
| 2897 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2898 | } else { |
| 2899 | if (mode & MAY_WRITE) |
| 2900 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2901 | if (mode & MAY_EXEC) |
| 2902 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2903 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2904 | |
| 2905 | res.fattr = nfs_alloc_fattr(); |
| 2906 | if (res.fattr == NULL) |
| 2907 | return -ENOMEM; |
| 2908 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2909 | 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] | 2910 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2911 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2912 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2914 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | return status; |
| 2916 | } |
| 2917 | |
| 2918 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2919 | { |
| 2920 | struct nfs4_exception exception = { }; |
| 2921 | int err; |
| 2922 | do { |
| 2923 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2924 | _nfs4_proc_access(inode, entry), |
| 2925 | &exception); |
| 2926 | } while (exception.retry); |
| 2927 | return err; |
| 2928 | } |
| 2929 | |
| 2930 | /* |
| 2931 | * TODO: For the time being, we don't try to get any attributes |
| 2932 | * along with any of the zero-copy operations READ, READDIR, |
| 2933 | * READLINK, WRITE. |
| 2934 | * |
| 2935 | * In the case of the first three, we want to put the GETATTR |
| 2936 | * after the read-type operation -- this is because it is hard |
| 2937 | * to predict the length of a GETATTR response in v4, and thus |
| 2938 | * align the READ data correctly. This means that the GETATTR |
| 2939 | * may end up partially falling into the page cache, and we should |
| 2940 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2941 | * To do this efficiently, we need to know the total length |
| 2942 | * of data received, which doesn't seem to be available outside |
| 2943 | * of the RPC layer. |
| 2944 | * |
| 2945 | * In the case of WRITE, we also want to put the GETATTR after |
| 2946 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2947 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | * |
| 2949 | * Both of these changes to the XDR layer would in fact be quite |
| 2950 | * minor, but I decided to leave them for a subsequent patch. |
| 2951 | */ |
| 2952 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2953 | unsigned int pgbase, unsigned int pglen) |
| 2954 | { |
| 2955 | struct nfs4_readlink args = { |
| 2956 | .fh = NFS_FH(inode), |
| 2957 | .pgbase = pgbase, |
| 2958 | .pglen = pglen, |
| 2959 | .pages = &page, |
| 2960 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2961 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | struct rpc_message msg = { |
| 2963 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2964 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2965 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | }; |
| 2967 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2968 | 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] | 2969 | } |
| 2970 | |
| 2971 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2972 | unsigned int pgbase, unsigned int pglen) |
| 2973 | { |
| 2974 | struct nfs4_exception exception = { }; |
| 2975 | int err; |
| 2976 | do { |
| 2977 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2978 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2979 | &exception); |
| 2980 | } while (exception.retry); |
| 2981 | return err; |
| 2982 | } |
| 2983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2985 | * 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] | 2986 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | static int |
| 2988 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2989 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2991 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | int status = 0; |
| 2994 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2995 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2996 | if (IS_ERR(ctx)) |
| 2997 | return PTR_ERR(ctx); |
| 2998 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2999 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 3000 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 3001 | flags, sattr, ctx->cred, |
| 3002 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 3003 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | if (IS_ERR(state)) { |
| 3005 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3006 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 3008 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 3009 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3010 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3012 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | return status; |
| 3014 | } |
| 3015 | |
| 3016 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3017 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3018 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3019 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3021 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3023 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3024 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3025 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3027 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3028 | .rpc_argp = &args, |
| 3029 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3031 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3032 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3033 | 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] | 3034 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3035 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | return status; |
| 3037 | } |
| 3038 | |
| 3039 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3040 | { |
| 3041 | struct nfs4_exception exception = { }; |
| 3042 | int err; |
| 3043 | do { |
| 3044 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3045 | _nfs4_proc_remove(dir, name), |
| 3046 | &exception); |
| 3047 | } while (exception.retry); |
| 3048 | return err; |
| 3049 | } |
| 3050 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3051 | 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] | 3052 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3053 | struct nfs_server *server = NFS_SERVER(dir); |
| 3054 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3055 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3057 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3059 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3062 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3063 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3064 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3065 | &data->args.seq_args, |
| 3066 | &data->res.seq_res, |
| 3067 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3070 | 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] | 3071 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3072 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3073 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3074 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3075 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3076 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3077 | return 0; |
| 3078 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3079 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3082 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3083 | { |
| 3084 | struct nfs_server *server = NFS_SERVER(dir); |
| 3085 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3086 | struct nfs_renameres *res = msg->rpc_resp; |
| 3087 | |
| 3088 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3089 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3090 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3091 | } |
| 3092 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3093 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3094 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3095 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3096 | &data->args.seq_args, |
| 3097 | &data->res.seq_res, |
| 3098 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3102 | struct inode *new_dir) |
| 3103 | { |
| 3104 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3105 | |
| 3106 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3107 | return 0; |
| 3108 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3109 | return 0; |
| 3110 | |
| 3111 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3112 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3113 | return 1; |
| 3114 | } |
| 3115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3117 | struct inode *new_dir, struct qstr *new_name) |
| 3118 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3119 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3120 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | .old_dir = NFS_FH(old_dir), |
| 3122 | .new_dir = NFS_FH(new_dir), |
| 3123 | .old_name = old_name, |
| 3124 | .new_name = new_name, |
| 3125 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3126 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3127 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3128 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | struct rpc_message msg = { |
| 3130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3131 | .rpc_argp = &arg, |
| 3132 | .rpc_resp = &res, |
| 3133 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3134 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3136 | 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] | 3137 | if (!status) { |
| 3138 | update_changeattr(old_dir, &res.old_cinfo); |
| 3139 | update_changeattr(new_dir, &res.new_cinfo); |
| 3140 | } |
| 3141 | return status; |
| 3142 | } |
| 3143 | |
| 3144 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3145 | struct inode *new_dir, struct qstr *new_name) |
| 3146 | { |
| 3147 | struct nfs4_exception exception = { }; |
| 3148 | int err; |
| 3149 | do { |
| 3150 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3151 | _nfs4_proc_rename(old_dir, old_name, |
| 3152 | new_dir, new_name), |
| 3153 | &exception); |
| 3154 | } while (exception.retry); |
| 3155 | return err; |
| 3156 | } |
| 3157 | |
| 3158 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3159 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3160 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | struct nfs4_link_arg arg = { |
| 3162 | .fh = NFS_FH(inode), |
| 3163 | .dir_fh = NFS_FH(dir), |
| 3164 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3165 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3167 | struct nfs4_link_res res = { |
| 3168 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3169 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | struct rpc_message msg = { |
| 3171 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3172 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3173 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3175 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3177 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3178 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3179 | goto out; |
| 3180 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3181 | 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] | 3182 | if (!status) { |
| 3183 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3184 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3185 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3186 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3187 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | return status; |
| 3189 | } |
| 3190 | |
| 3191 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3192 | { |
| 3193 | struct nfs4_exception exception = { }; |
| 3194 | int err; |
| 3195 | do { |
| 3196 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3197 | _nfs4_proc_link(inode, dir, name), |
| 3198 | &exception); |
| 3199 | } while (exception.retry); |
| 3200 | return err; |
| 3201 | } |
| 3202 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3203 | struct nfs4_createdata { |
| 3204 | struct rpc_message msg; |
| 3205 | struct nfs4_create_arg arg; |
| 3206 | struct nfs4_create_res res; |
| 3207 | struct nfs_fh fh; |
| 3208 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3209 | }; |
| 3210 | |
| 3211 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3212 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3213 | { |
| 3214 | struct nfs4_createdata *data; |
| 3215 | |
| 3216 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3217 | if (data != NULL) { |
| 3218 | struct nfs_server *server = NFS_SERVER(dir); |
| 3219 | |
| 3220 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3221 | data->msg.rpc_argp = &data->arg; |
| 3222 | data->msg.rpc_resp = &data->res; |
| 3223 | data->arg.dir_fh = NFS_FH(dir); |
| 3224 | data->arg.server = server; |
| 3225 | data->arg.name = name; |
| 3226 | data->arg.attrs = sattr; |
| 3227 | data->arg.ftype = ftype; |
| 3228 | data->arg.bitmask = server->attr_bitmask; |
| 3229 | data->res.server = server; |
| 3230 | data->res.fh = &data->fh; |
| 3231 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3232 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3233 | } |
| 3234 | return data; |
| 3235 | } |
| 3236 | |
| 3237 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3238 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3239 | 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] | 3240 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3241 | if (status == 0) { |
| 3242 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3243 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3244 | } |
| 3245 | return status; |
| 3246 | } |
| 3247 | |
| 3248 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3249 | { |
| 3250 | kfree(data); |
| 3251 | } |
| 3252 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3253 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3254 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3256 | struct nfs4_createdata *data; |
| 3257 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3259 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3260 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3261 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3262 | status = -ENOMEM; |
| 3263 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3264 | if (data == NULL) |
| 3265 | goto out; |
| 3266 | |
| 3267 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3268 | data->arg.u.symlink.pages = &page; |
| 3269 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3271 | status = nfs4_do_create(dir, dentry, data); |
| 3272 | |
| 3273 | nfs4_free_createdata(data); |
| 3274 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | return status; |
| 3276 | } |
| 3277 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3278 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3279 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | { |
| 3281 | struct nfs4_exception exception = { }; |
| 3282 | int err; |
| 3283 | do { |
| 3284 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3285 | _nfs4_proc_symlink(dir, dentry, page, |
| 3286 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | &exception); |
| 3288 | } while (exception.retry); |
| 3289 | return err; |
| 3290 | } |
| 3291 | |
| 3292 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3293 | struct iattr *sattr) |
| 3294 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3295 | struct nfs4_createdata *data; |
| 3296 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3298 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3299 | if (data == NULL) |
| 3300 | goto out; |
| 3301 | |
| 3302 | status = nfs4_do_create(dir, dentry, data); |
| 3303 | |
| 3304 | nfs4_free_createdata(data); |
| 3305 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | return status; |
| 3307 | } |
| 3308 | |
| 3309 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3310 | struct iattr *sattr) |
| 3311 | { |
| 3312 | struct nfs4_exception exception = { }; |
| 3313 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3314 | |
| 3315 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | do { |
| 3317 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3318 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3319 | &exception); |
| 3320 | } while (exception.retry); |
| 3321 | return err; |
| 3322 | } |
| 3323 | |
| 3324 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3325 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | { |
| 3327 | struct inode *dir = dentry->d_inode; |
| 3328 | struct nfs4_readdir_arg args = { |
| 3329 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3330 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | .pgbase = 0, |
| 3332 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3333 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3334 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | }; |
| 3336 | struct nfs4_readdir_res res; |
| 3337 | struct rpc_message msg = { |
| 3338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3339 | .rpc_argp = &args, |
| 3340 | .rpc_resp = &res, |
| 3341 | .rpc_cred = cred, |
| 3342 | }; |
| 3343 | int status; |
| 3344 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3345 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3346 | dentry->d_parent->d_name.name, |
| 3347 | dentry->d_name.name, |
| 3348 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3349 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3351 | 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] | 3352 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3353 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3354 | status += args.pgbase; |
| 3355 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3356 | |
| 3357 | nfs_invalidate_atime(dir); |
| 3358 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3359 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | return status; |
| 3361 | } |
| 3362 | |
| 3363 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3364 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | { |
| 3366 | struct nfs4_exception exception = { }; |
| 3367 | int err; |
| 3368 | do { |
| 3369 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3370 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3371 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | &exception); |
| 3373 | } while (exception.retry); |
| 3374 | return err; |
| 3375 | } |
| 3376 | |
| 3377 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3378 | struct iattr *sattr, dev_t rdev) |
| 3379 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3380 | struct nfs4_createdata *data; |
| 3381 | int mode = sattr->ia_mode; |
| 3382 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3384 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3385 | if (data == NULL) |
| 3386 | goto out; |
| 3387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3389 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3391 | data->arg.ftype = NF4BLK; |
| 3392 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3393 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | } |
| 3395 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3396 | data->arg.ftype = NF4CHR; |
| 3397 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3398 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3399 | } else if (!S_ISSOCK(mode)) { |
| 3400 | status = -EINVAL; |
| 3401 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3404 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3405 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3406 | nfs4_free_createdata(data); |
| 3407 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | return status; |
| 3409 | } |
| 3410 | |
| 3411 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3412 | struct iattr *sattr, dev_t rdev) |
| 3413 | { |
| 3414 | struct nfs4_exception exception = { }; |
| 3415 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3416 | |
| 3417 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | do { |
| 3419 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3420 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3421 | &exception); |
| 3422 | } while (exception.retry); |
| 3423 | return err; |
| 3424 | } |
| 3425 | |
| 3426 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3427 | struct nfs_fsstat *fsstat) |
| 3428 | { |
| 3429 | struct nfs4_statfs_arg args = { |
| 3430 | .fh = fhandle, |
| 3431 | .bitmask = server->attr_bitmask, |
| 3432 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3433 | struct nfs4_statfs_res res = { |
| 3434 | .fsstat = fsstat, |
| 3435 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | struct rpc_message msg = { |
| 3437 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3438 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3439 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | }; |
| 3441 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3442 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3443 | 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] | 3444 | } |
| 3445 | |
| 3446 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3447 | { |
| 3448 | struct nfs4_exception exception = { }; |
| 3449 | int err; |
| 3450 | do { |
| 3451 | err = nfs4_handle_exception(server, |
| 3452 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3453 | &exception); |
| 3454 | } while (exception.retry); |
| 3455 | return err; |
| 3456 | } |
| 3457 | |
| 3458 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3459 | struct nfs_fsinfo *fsinfo) |
| 3460 | { |
| 3461 | struct nfs4_fsinfo_arg args = { |
| 3462 | .fh = fhandle, |
| 3463 | .bitmask = server->attr_bitmask, |
| 3464 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3465 | struct nfs4_fsinfo_res res = { |
| 3466 | .fsinfo = fsinfo, |
| 3467 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | struct rpc_message msg = { |
| 3469 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3470 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3471 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | }; |
| 3473 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3474 | 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] | 3475 | } |
| 3476 | |
| 3477 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3478 | { |
| 3479 | struct nfs4_exception exception = { }; |
| 3480 | int err; |
| 3481 | |
| 3482 | do { |
| 3483 | err = nfs4_handle_exception(server, |
| 3484 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3485 | &exception); |
| 3486 | } while (exception.retry); |
| 3487 | return err; |
| 3488 | } |
| 3489 | |
| 3490 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3491 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3492 | int error; |
| 3493 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3494 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3495 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3496 | if (error == 0) { |
| 3497 | /* block layout checks this! */ |
| 3498 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3499 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3500 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3501 | |
| 3502 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3506 | struct nfs_pathconf *pathconf) |
| 3507 | { |
| 3508 | struct nfs4_pathconf_arg args = { |
| 3509 | .fh = fhandle, |
| 3510 | .bitmask = server->attr_bitmask, |
| 3511 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3512 | struct nfs4_pathconf_res res = { |
| 3513 | .pathconf = pathconf, |
| 3514 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | struct rpc_message msg = { |
| 3516 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3517 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3518 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | }; |
| 3520 | |
| 3521 | /* None of the pathconf attributes are mandatory to implement */ |
| 3522 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3523 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3524 | return 0; |
| 3525 | } |
| 3526 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3527 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3528 | 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] | 3529 | } |
| 3530 | |
| 3531 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3532 | struct nfs_pathconf *pathconf) |
| 3533 | { |
| 3534 | struct nfs4_exception exception = { }; |
| 3535 | int err; |
| 3536 | |
| 3537 | do { |
| 3538 | err = nfs4_handle_exception(server, |
| 3539 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3540 | &exception); |
| 3541 | } while (exception.retry); |
| 3542 | return err; |
| 3543 | } |
| 3544 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3545 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3546 | const struct nfs_open_context *ctx, |
| 3547 | const struct nfs_lock_context *l_ctx, |
| 3548 | fmode_t fmode) |
| 3549 | { |
| 3550 | const struct nfs_lockowner *lockowner = NULL; |
| 3551 | |
| 3552 | if (l_ctx != NULL) |
| 3553 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3554 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3555 | } |
| 3556 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3557 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3558 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3559 | const struct nfs_open_context *ctx, |
| 3560 | const struct nfs_lock_context *l_ctx, |
| 3561 | fmode_t fmode) |
| 3562 | { |
| 3563 | nfs4_stateid current_stateid; |
| 3564 | |
| 3565 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3566 | return false; |
| 3567 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3568 | } |
| 3569 | |
| 3570 | static bool nfs4_error_stateid_expired(int err) |
| 3571 | { |
| 3572 | switch (err) { |
| 3573 | case -NFS4ERR_DELEG_REVOKED: |
| 3574 | case -NFS4ERR_ADMIN_REVOKED: |
| 3575 | case -NFS4ERR_BAD_STATEID: |
| 3576 | case -NFS4ERR_STALE_STATEID: |
| 3577 | case -NFS4ERR_OLD_STATEID: |
| 3578 | case -NFS4ERR_OPENMODE: |
| 3579 | case -NFS4ERR_EXPIRED: |
| 3580 | return true; |
| 3581 | } |
| 3582 | return false; |
| 3583 | } |
| 3584 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3585 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3586 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3587 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3588 | } |
| 3589 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3590 | 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] | 3591 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3592 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3594 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3595 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3596 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3598 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3599 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3601 | renew_lease(server, data->timestamp); |
| 3602 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3605 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3606 | struct nfs_readargs *args) |
| 3607 | { |
| 3608 | |
| 3609 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3610 | nfs4_stateid_is_current(&args->stateid, |
| 3611 | args->context, |
| 3612 | args->lock_context, |
| 3613 | FMODE_READ)) |
| 3614 | return false; |
| 3615 | rpc_restart_call_prepare(task); |
| 3616 | return true; |
| 3617 | } |
| 3618 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3619 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3620 | { |
| 3621 | |
| 3622 | dprintk("--> %s\n", __func__); |
| 3623 | |
| 3624 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3625 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3626 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3627 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3628 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3629 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3632 | 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] | 3633 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3635 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3636 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3637 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3640 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3641 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3642 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3643 | &data->args.seq_args, |
| 3644 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3645 | task)) |
| 3646 | return; |
| 3647 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3648 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3651 | 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] | 3652 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3653 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3655 | 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] | 3656 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3657 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3659 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3661 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3662 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3663 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3666 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3667 | struct nfs_writeargs *args) |
| 3668 | { |
| 3669 | |
| 3670 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3671 | nfs4_stateid_is_current(&args->stateid, |
| 3672 | args->context, |
| 3673 | args->lock_context, |
| 3674 | FMODE_WRITE)) |
| 3675 | return false; |
| 3676 | rpc_restart_call_prepare(task); |
| 3677 | return true; |
| 3678 | } |
| 3679 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3680 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3681 | { |
| 3682 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3683 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3684 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3685 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3686 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3687 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3688 | } |
| 3689 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3690 | static |
| 3691 | 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] | 3692 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3693 | const struct nfs_pgio_header *hdr = data->header; |
| 3694 | |
| 3695 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3696 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3697 | return false; |
| 3698 | /* Otherwise, request attributes if and only if we don't hold |
| 3699 | * a delegation |
| 3700 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3701 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3702 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3703 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3704 | 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] | 3705 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3706 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3707 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3708 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3709 | data->args.bitmask = NULL; |
| 3710 | data->res.fattr = NULL; |
| 3711 | } else |
| 3712 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3713 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3714 | if (!data->write_done_cb) |
| 3715 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3716 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | data->timestamp = jiffies; |
| 3718 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3719 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3720 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | } |
| 3722 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3723 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3724 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3725 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3726 | &data->args.seq_args, |
| 3727 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3728 | task)) |
| 3729 | return; |
| 3730 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3731 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3734 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3735 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3736 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3737 | &data->args.seq_args, |
| 3738 | &data->res.seq_res, |
| 3739 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | } |
| 3741 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3742 | 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] | 3743 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3745 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3746 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3747 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3748 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3750 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | } |
| 3752 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3753 | 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] | 3754 | { |
| 3755 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3756 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3757 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3760 | 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] | 3761 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3762 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3763 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3764 | if (data->commit_done_cb == NULL) |
| 3765 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3766 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3767 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3768 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | } |
| 3770 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3771 | struct nfs4_renewdata { |
| 3772 | struct nfs_client *client; |
| 3773 | unsigned long timestamp; |
| 3774 | }; |
| 3775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | /* |
| 3777 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3778 | * standalone procedure for queueing an asynchronous RENEW. |
| 3779 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3780 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3781 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3782 | struct nfs4_renewdata *data = calldata; |
| 3783 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3784 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3785 | if (atomic_read(&clp->cl_count) > 1) |
| 3786 | nfs4_schedule_state_renewal(clp); |
| 3787 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3788 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3789 | } |
| 3790 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3791 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3793 | struct nfs4_renewdata *data = calldata; |
| 3794 | struct nfs_client *clp = data->client; |
| 3795 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | |
| 3797 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3798 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3799 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3800 | return; |
| 3801 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3802 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3803 | return; |
| 3804 | } |
| 3805 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3807 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | } |
| 3809 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3810 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3811 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3812 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3813 | }; |
| 3814 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3815 | 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] | 3816 | { |
| 3817 | struct rpc_message msg = { |
| 3818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3819 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3820 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3822 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3824 | if (renew_flags == 0) |
| 3825 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3826 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3827 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3828 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3829 | if (data == NULL) |
| 3830 | return -ENOMEM; |
| 3831 | data->client = clp; |
| 3832 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 3833 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3834 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3837 | 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] | 3838 | { |
| 3839 | struct rpc_message msg = { |
| 3840 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3841 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3842 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | }; |
| 3844 | unsigned long now = jiffies; |
| 3845 | int status; |
| 3846 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 3847 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | if (status < 0) |
| 3849 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3850 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | return 0; |
| 3852 | } |
| 3853 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3854 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3855 | { |
| 3856 | return (server->caps & NFS_CAP_ACLS) |
| 3857 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3858 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3859 | } |
| 3860 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3861 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3862 | * 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] | 3863 | * the stack. |
| 3864 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3865 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3866 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3867 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3868 | struct page **pages, unsigned int *pgbase) |
| 3869 | { |
| 3870 | struct page *newpage, **spages; |
| 3871 | int rc = 0; |
| 3872 | size_t len; |
| 3873 | spages = pages; |
| 3874 | |
| 3875 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3876 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3877 | newpage = alloc_page(GFP_KERNEL); |
| 3878 | |
| 3879 | if (newpage == NULL) |
| 3880 | goto unwind; |
| 3881 | memcpy(page_address(newpage), buf, len); |
| 3882 | buf += len; |
| 3883 | buflen -= len; |
| 3884 | *pages++ = newpage; |
| 3885 | rc++; |
| 3886 | } while (buflen != 0); |
| 3887 | |
| 3888 | return rc; |
| 3889 | |
| 3890 | unwind: |
| 3891 | for(; rc > 0; rc--) |
| 3892 | __free_page(spages[rc-1]); |
| 3893 | return -ENOMEM; |
| 3894 | } |
| 3895 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3896 | struct nfs4_cached_acl { |
| 3897 | int cached; |
| 3898 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3899 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3900 | }; |
| 3901 | |
| 3902 | 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] | 3903 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3904 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3905 | |
| 3906 | spin_lock(&inode->i_lock); |
| 3907 | kfree(nfsi->nfs4_acl); |
| 3908 | nfsi->nfs4_acl = acl; |
| 3909 | spin_unlock(&inode->i_lock); |
| 3910 | } |
| 3911 | |
| 3912 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3913 | { |
| 3914 | nfs4_set_cached_acl(inode, NULL); |
| 3915 | } |
| 3916 | |
| 3917 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3918 | { |
| 3919 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3920 | struct nfs4_cached_acl *acl; |
| 3921 | int ret = -ENOENT; |
| 3922 | |
| 3923 | spin_lock(&inode->i_lock); |
| 3924 | acl = nfsi->nfs4_acl; |
| 3925 | if (acl == NULL) |
| 3926 | goto out; |
| 3927 | if (buf == NULL) /* user is just asking for length */ |
| 3928 | goto out_len; |
| 3929 | if (acl->cached == 0) |
| 3930 | goto out; |
| 3931 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3932 | if (acl->len > buflen) |
| 3933 | goto out; |
| 3934 | memcpy(buf, acl->data, acl->len); |
| 3935 | out_len: |
| 3936 | ret = acl->len; |
| 3937 | out: |
| 3938 | spin_unlock(&inode->i_lock); |
| 3939 | return ret; |
| 3940 | } |
| 3941 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3942 | 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] | 3943 | { |
| 3944 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3945 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3946 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3947 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3948 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3949 | if (acl == NULL) |
| 3950 | goto out; |
| 3951 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3952 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3953 | } else { |
| 3954 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3955 | if (acl == NULL) |
| 3956 | goto out; |
| 3957 | acl->cached = 0; |
| 3958 | } |
| 3959 | acl->len = acl_len; |
| 3960 | out: |
| 3961 | nfs4_set_cached_acl(inode, acl); |
| 3962 | } |
| 3963 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3964 | /* |
| 3965 | * The getxattr API returns the required buffer length when called with a |
| 3966 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3967 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3968 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3969 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3970 | * the cache. If not so, we throw away the page, and cache the required |
| 3971 | * length. The next getxattr call will then produce another round trip to |
| 3972 | * the server, this time with the input buf of the required size. |
| 3973 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3974 | 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] | 3975 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3976 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3977 | struct nfs_getaclargs args = { |
| 3978 | .fh = NFS_FH(inode), |
| 3979 | .acl_pages = pages, |
| 3980 | .acl_len = buflen, |
| 3981 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3982 | struct nfs_getaclres res = { |
| 3983 | .acl_len = buflen, |
| 3984 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3985 | struct rpc_message msg = { |
| 3986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3987 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3988 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3989 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3990 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3991 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3992 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3993 | /* As long as we're doing a round trip to the server anyway, |
| 3994 | * let's be prepared for a page of acl data. */ |
| 3995 | if (npages == 0) |
| 3996 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3997 | if (npages > ARRAY_SIZE(pages)) |
| 3998 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3999 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4000 | for (i = 0; i < npages; i++) { |
| 4001 | pages[i] = alloc_page(GFP_KERNEL); |
| 4002 | if (!pages[i]) |
| 4003 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4004 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4005 | |
| 4006 | /* for decoding across pages */ |
| 4007 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4008 | if (!res.acl_scratch) |
| 4009 | goto out_free; |
| 4010 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4011 | args.acl_len = npages * PAGE_SIZE; |
| 4012 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4013 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4014 | 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] | 4015 | __func__, buf, buflen, npages, args.acl_len); |
| 4016 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4017 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4018 | if (ret) |
| 4019 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4020 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4021 | /* Handle the case where the passed-in buffer is too short */ |
| 4022 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4023 | /* Did the user only issue a request for the acl length? */ |
| 4024 | if (buf == NULL) |
| 4025 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4026 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4027 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4028 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4029 | 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] | 4030 | if (buf) { |
| 4031 | if (res.acl_len > buflen) { |
| 4032 | ret = -ERANGE; |
| 4033 | goto out_free; |
| 4034 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4035 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4036 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4037 | out_ok: |
| 4038 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4039 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4040 | for (i = 0; i < npages; i++) |
| 4041 | if (pages[i]) |
| 4042 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4043 | if (res.acl_scratch) |
| 4044 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4045 | return ret; |
| 4046 | } |
| 4047 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4048 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4049 | { |
| 4050 | struct nfs4_exception exception = { }; |
| 4051 | ssize_t ret; |
| 4052 | do { |
| 4053 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 4054 | if (ret >= 0) |
| 4055 | break; |
| 4056 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4057 | } while (exception.retry); |
| 4058 | return ret; |
| 4059 | } |
| 4060 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4061 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4062 | { |
| 4063 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4064 | int ret; |
| 4065 | |
| 4066 | if (!nfs4_server_supports_acls(server)) |
| 4067 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4068 | ret = nfs_revalidate_inode(server, inode); |
| 4069 | if (ret < 0) |
| 4070 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4071 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4072 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4073 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4074 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4075 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4076 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4077 | return ret; |
| 4078 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4079 | } |
| 4080 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4081 | 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] | 4082 | { |
| 4083 | struct nfs_server *server = NFS_SERVER(inode); |
| 4084 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4085 | struct nfs_setaclargs arg = { |
| 4086 | .fh = NFS_FH(inode), |
| 4087 | .acl_pages = pages, |
| 4088 | .acl_len = buflen, |
| 4089 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4090 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4091 | struct rpc_message msg = { |
| 4092 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4093 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4094 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4095 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4096 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4097 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4098 | |
| 4099 | if (!nfs4_server_supports_acls(server)) |
| 4100 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4101 | if (npages > ARRAY_SIZE(pages)) |
| 4102 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4103 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4104 | if (i < 0) |
| 4105 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4106 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4107 | 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] | 4108 | |
| 4109 | /* |
| 4110 | * Free each page after tx, so the only ref left is |
| 4111 | * held by the network stack |
| 4112 | */ |
| 4113 | for (; i > 0; i--) |
| 4114 | put_page(pages[i-1]); |
| 4115 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4116 | /* |
| 4117 | * Acl update can result in inode attribute update. |
| 4118 | * so mark the attribute cache invalid. |
| 4119 | */ |
| 4120 | spin_lock(&inode->i_lock); |
| 4121 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4122 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4123 | nfs_access_zap_cache(inode); |
| 4124 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4125 | return ret; |
| 4126 | } |
| 4127 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4128 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4129 | { |
| 4130 | struct nfs4_exception exception = { }; |
| 4131 | int err; |
| 4132 | do { |
| 4133 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4134 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4135 | &exception); |
| 4136 | } while (exception.retry); |
| 4137 | return err; |
| 4138 | } |
| 4139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4141 | 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] | 4142 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4143 | struct nfs_client *clp = server->nfs_client; |
| 4144 | |
| 4145 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | return 0; |
| 4147 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4148 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4149 | case -NFS4ERR_ADMIN_REVOKED: |
| 4150 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4151 | if (state == NULL) |
| 4152 | break; |
| 4153 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4154 | case -NFS4ERR_OPENMODE: |
| 4155 | if (state == NULL) |
| 4156 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4157 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4158 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4159 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4160 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4161 | if (state != NULL) { |
| 4162 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4163 | goto stateid_invalid; |
| 4164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4166 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4167 | nfs4_schedule_lease_recovery(clp); |
| 4168 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4169 | #if defined(CONFIG_NFS_V4_1) |
| 4170 | case -NFS4ERR_BADSESSION: |
| 4171 | case -NFS4ERR_BADSLOT: |
| 4172 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4173 | case -NFS4ERR_DEADSESSION: |
| 4174 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4175 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4176 | case -NFS4ERR_SEQ_MISORDERED: |
| 4177 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4178 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4179 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4180 | task->tk_status = 0; |
| 4181 | return -EAGAIN; |
| 4182 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4184 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4185 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4187 | task->tk_status = 0; |
| 4188 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4189 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | case -NFS4ERR_OLD_STATEID: |
| 4191 | task->tk_status = 0; |
| 4192 | return -EAGAIN; |
| 4193 | } |
| 4194 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4195 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4196 | stateid_invalid: |
| 4197 | task->tk_status = -EIO; |
| 4198 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4199 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4200 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4201 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4202 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4203 | task->tk_status = 0; |
| 4204 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | } |
| 4206 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4207 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4208 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4209 | { |
| 4210 | __be32 verf[2]; |
| 4211 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4212 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4213 | /* An impossible timestamp guarantees this value |
| 4214 | * will never match a generated boot time. */ |
| 4215 | verf[0] = 0; |
| 4216 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4217 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4218 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4219 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4220 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4221 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4222 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4223 | } |
| 4224 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4225 | static unsigned int |
| 4226 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4227 | char *buf, size_t len) |
| 4228 | { |
| 4229 | unsigned int result; |
| 4230 | |
| 4231 | rcu_read_lock(); |
| 4232 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4233 | clp->cl_ipaddr, |
| 4234 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4235 | RPC_DISPLAY_ADDR), |
| 4236 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4237 | RPC_DISPLAY_PROTO)); |
| 4238 | rcu_read_unlock(); |
| 4239 | return result; |
| 4240 | } |
| 4241 | |
| 4242 | static unsigned int |
| 4243 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4244 | char *buf, size_t len) |
| 4245 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4246 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4247 | |
| 4248 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4249 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4250 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4251 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4252 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4253 | } |
| 4254 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4255 | /** |
| 4256 | * nfs4_proc_setclientid - Negotiate client ID |
| 4257 | * @clp: state data structure |
| 4258 | * @program: RPC program for NFSv4 callback service |
| 4259 | * @port: IP port number for NFS4 callback service |
| 4260 | * @cred: RPC credential to use for this call |
| 4261 | * @res: where to place the result |
| 4262 | * |
| 4263 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4264 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4265 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4266 | unsigned short port, struct rpc_cred *cred, |
| 4267 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | { |
| 4269 | nfs4_verifier sc_verifier; |
| 4270 | struct nfs4_setclientid setclientid = { |
| 4271 | .sc_verifier = &sc_verifier, |
| 4272 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4273 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | }; |
| 4275 | struct rpc_message msg = { |
| 4276 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4277 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4278 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4279 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4281 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4283 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4284 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4285 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4286 | setclientid.sc_name_len = |
| 4287 | nfs4_init_uniform_client_string(clp, |
| 4288 | setclientid.sc_name, |
| 4289 | sizeof(setclientid.sc_name)); |
| 4290 | else |
| 4291 | setclientid.sc_name_len = |
| 4292 | nfs4_init_nonuniform_client_string(clp, |
| 4293 | setclientid.sc_name, |
| 4294 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4295 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4296 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4297 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4298 | sizeof(setclientid.sc_netid), |
| 4299 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4300 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4301 | rcu_read_unlock(); |
| 4302 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4303 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4305 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4306 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4307 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4308 | setclientid.sc_name_len, setclientid.sc_name); |
| 4309 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4310 | dprintk("NFS reply setclientid: %d\n", status); |
| 4311 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4314 | /** |
| 4315 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4316 | * @clp: state data structure |
| 4317 | * @res: result of a previous SETCLIENTID |
| 4318 | * @cred: RPC credential to use for this call |
| 4319 | * |
| 4320 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4321 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4322 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4323 | struct nfs4_setclientid_res *arg, |
| 4324 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | { |
| 4326 | struct nfs_fsinfo fsinfo; |
| 4327 | struct rpc_message msg = { |
| 4328 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4329 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4331 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | }; |
| 4333 | unsigned long now; |
| 4334 | int status; |
| 4335 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4336 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4337 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4338 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4340 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | if (status == 0) { |
| 4342 | spin_lock(&clp->cl_lock); |
| 4343 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4344 | clp->cl_last_renewal = now; |
| 4345 | spin_unlock(&clp->cl_lock); |
| 4346 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4347 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | return status; |
| 4349 | } |
| 4350 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4351 | struct nfs4_delegreturndata { |
| 4352 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4353 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4354 | struct nfs_fh fh; |
| 4355 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4356 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4357 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4358 | int rpc_status; |
| 4359 | }; |
| 4360 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4361 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4362 | { |
| 4363 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4364 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4365 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4366 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4367 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4368 | switch (task->tk_status) { |
| 4369 | case -NFS4ERR_STALE_STATEID: |
| 4370 | case -NFS4ERR_EXPIRED: |
| 4371 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4372 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4373 | break; |
| 4374 | default: |
| 4375 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4376 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4377 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4378 | return; |
| 4379 | } |
| 4380 | } |
| 4381 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | static void nfs4_delegreturn_release(void *calldata) |
| 4385 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4386 | kfree(calldata); |
| 4387 | } |
| 4388 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4389 | #if defined(CONFIG_NFS_V4_1) |
| 4390 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4391 | { |
| 4392 | struct nfs4_delegreturndata *d_data; |
| 4393 | |
| 4394 | d_data = (struct nfs4_delegreturndata *)data; |
| 4395 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4396 | nfs4_setup_sequence(d_data->res.server, |
| 4397 | &d_data->args.seq_args, |
| 4398 | &d_data->res.seq_res, |
| 4399 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4400 | } |
| 4401 | #endif /* CONFIG_NFS_V4_1 */ |
| 4402 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4403 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4404 | #if defined(CONFIG_NFS_V4_1) |
| 4405 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4406 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4407 | .rpc_call_done = nfs4_delegreturn_done, |
| 4408 | .rpc_release = nfs4_delegreturn_release, |
| 4409 | }; |
| 4410 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4411 | 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] | 4412 | { |
| 4413 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4414 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4415 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4416 | struct rpc_message msg = { |
| 4417 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4418 | .rpc_cred = cred, |
| 4419 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4420 | struct rpc_task_setup task_setup_data = { |
| 4421 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4422 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4423 | .callback_ops = &nfs4_delegreturn_ops, |
| 4424 | .flags = RPC_TASK_ASYNC, |
| 4425 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4426 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4427 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4428 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4429 | if (data == NULL) |
| 4430 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4431 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4432 | data->args.fhandle = &data->fh; |
| 4433 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4434 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4435 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4436 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4437 | data->res.fattr = &data->fattr; |
| 4438 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4439 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4440 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4441 | data->rpc_status = 0; |
| 4442 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4443 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4444 | msg.rpc_argp = &data->args; |
| 4445 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4446 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4447 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4448 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4449 | if (!issync) |
| 4450 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4451 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4452 | if (status != 0) |
| 4453 | goto out; |
| 4454 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4455 | if (status == 0) |
| 4456 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4457 | else |
| 4458 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4459 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4460 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4461 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | } |
| 4463 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4464 | 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] | 4465 | { |
| 4466 | struct nfs_server *server = NFS_SERVER(inode); |
| 4467 | struct nfs4_exception exception = { }; |
| 4468 | int err; |
| 4469 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4470 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | switch (err) { |
| 4472 | case -NFS4ERR_STALE_STATEID: |
| 4473 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | case 0: |
| 4475 | return 0; |
| 4476 | } |
| 4477 | err = nfs4_handle_exception(server, err, &exception); |
| 4478 | } while (exception.retry); |
| 4479 | return err; |
| 4480 | } |
| 4481 | |
| 4482 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4483 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4484 | |
| 4485 | /* |
| 4486 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4487 | */ |
| 4488 | static unsigned long |
| 4489 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4490 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4491 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | timeout <<= 1; |
| 4493 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4494 | return NFS4_LOCK_MAXTIMEOUT; |
| 4495 | return timeout; |
| 4496 | } |
| 4497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4499 | { |
| 4500 | struct inode *inode = state->inode; |
| 4501 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4502 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4503 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4505 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4507 | struct nfs_lockt_res res = { |
| 4508 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | }; |
| 4510 | struct rpc_message msg = { |
| 4511 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4512 | .rpc_argp = &arg, |
| 4513 | .rpc_resp = &res, |
| 4514 | .rpc_cred = state->owner->so_cred, |
| 4515 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | struct nfs4_lock_state *lsp; |
| 4517 | int status; |
| 4518 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4519 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4520 | status = nfs4_set_lock_state(state, request); |
| 4521 | if (status != 0) |
| 4522 | goto out; |
| 4523 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4524 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4525 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4526 | 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] | 4527 | switch (status) { |
| 4528 | case 0: |
| 4529 | request->fl_type = F_UNLCK; |
| 4530 | break; |
| 4531 | case -NFS4ERR_DENIED: |
| 4532 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4534 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4535 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | return status; |
| 4537 | } |
| 4538 | |
| 4539 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4540 | { |
| 4541 | struct nfs4_exception exception = { }; |
| 4542 | int err; |
| 4543 | |
| 4544 | do { |
| 4545 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4546 | _nfs4_proc_getlk(state, cmd, request), |
| 4547 | &exception); |
| 4548 | } while (exception.retry); |
| 4549 | return err; |
| 4550 | } |
| 4551 | |
| 4552 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4553 | { |
| 4554 | int res = 0; |
| 4555 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4556 | case FL_POSIX: |
| 4557 | res = posix_lock_file_wait(file, fl); |
| 4558 | break; |
| 4559 | case FL_FLOCK: |
| 4560 | res = flock_lock_file_wait(file, fl); |
| 4561 | break; |
| 4562 | default: |
| 4563 | BUG(); |
| 4564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | return res; |
| 4566 | } |
| 4567 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4568 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4569 | struct nfs_locku_args arg; |
| 4570 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4571 | struct nfs4_lock_state *lsp; |
| 4572 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4573 | struct file_lock fl; |
| 4574 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4575 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4576 | }; |
| 4577 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4578 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4579 | struct nfs_open_context *ctx, |
| 4580 | struct nfs4_lock_state *lsp, |
| 4581 | struct nfs_seqid *seqid) |
| 4582 | { |
| 4583 | struct nfs4_unlockdata *p; |
| 4584 | struct inode *inode = lsp->ls_state->inode; |
| 4585 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4586 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4587 | if (p == NULL) |
| 4588 | return NULL; |
| 4589 | p->arg.fh = NFS_FH(inode); |
| 4590 | p->arg.fl = &p->fl; |
| 4591 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4592 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4593 | p->arg.stateid = &lsp->ls_stateid; |
| 4594 | p->lsp = lsp; |
| 4595 | atomic_inc(&lsp->ls_count); |
| 4596 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4597 | p->ctx = get_nfs_open_context(ctx); |
| 4598 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4599 | p->server = NFS_SERVER(inode); |
| 4600 | return p; |
| 4601 | } |
| 4602 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4603 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4604 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4605 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4606 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4607 | nfs4_put_lock_state(calldata->lsp); |
| 4608 | put_nfs_open_context(calldata->ctx); |
| 4609 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4612 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4613 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4614 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4615 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4616 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4617 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4618 | switch (task->tk_status) { |
| 4619 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4620 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4621 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4622 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4623 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4624 | case -NFS4ERR_BAD_STATEID: |
| 4625 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4626 | case -NFS4ERR_STALE_STATEID: |
| 4627 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4628 | break; |
| 4629 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4630 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4631 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4632 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4633 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4636 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4637 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4638 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4640 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4641 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4642 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4643 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4644 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4645 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4646 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4647 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4648 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4649 | &calldata->res.seq_res, |
| 4650 | task) != 0) |
| 4651 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4652 | return; |
| 4653 | out_no_action: |
| 4654 | task->tk_action = NULL; |
| 4655 | out_wait: |
| 4656 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | } |
| 4658 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4659 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4660 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4661 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4662 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4663 | }; |
| 4664 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4665 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4666 | struct nfs_open_context *ctx, |
| 4667 | struct nfs4_lock_state *lsp, |
| 4668 | struct nfs_seqid *seqid) |
| 4669 | { |
| 4670 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4671 | struct rpc_message msg = { |
| 4672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4673 | .rpc_cred = ctx->cred, |
| 4674 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4675 | struct rpc_task_setup task_setup_data = { |
| 4676 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4677 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4678 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4679 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4680 | .flags = RPC_TASK_ASYNC, |
| 4681 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4682 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4683 | /* Ensure this is an unlock - when canceling a lock, the |
| 4684 | * canceled lock is passed in, and it won't be an unlock. |
| 4685 | */ |
| 4686 | fl->fl_type = F_UNLCK; |
| 4687 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4688 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4689 | if (data == NULL) { |
| 4690 | nfs_free_seqid(seqid); |
| 4691 | return ERR_PTR(-ENOMEM); |
| 4692 | } |
| 4693 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4694 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4695 | msg.rpc_argp = &data->arg; |
| 4696 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4697 | task_setup_data.callback_data = data; |
| 4698 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4699 | } |
| 4700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4702 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4703 | struct inode *inode = state->inode; |
| 4704 | struct nfs4_state_owner *sp = state->owner; |
| 4705 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4706 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4707 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4708 | struct rpc_task *task; |
| 4709 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4710 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4712 | status = nfs4_set_lock_state(state, request); |
| 4713 | /* Unlock _before_ we do the RPC call */ |
| 4714 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4715 | /* Exclude nfs_delegation_claim_locks() */ |
| 4716 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4717 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4718 | down_read(&nfsi->rwsem); |
| 4719 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4720 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4721 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4722 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4723 | } |
| 4724 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4725 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4726 | if (status != 0) |
| 4727 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4728 | /* Is this a delegated lock? */ |
| 4729 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4730 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4731 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4732 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4733 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4734 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4735 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4736 | 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] | 4737 | status = PTR_ERR(task); |
| 4738 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4739 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4740 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4741 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4742 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4743 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4744 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4747 | struct nfs4_lockdata { |
| 4748 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4749 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4750 | struct nfs4_lock_state *lsp; |
| 4751 | struct nfs_open_context *ctx; |
| 4752 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4753 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4754 | int rpc_status; |
| 4755 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4756 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4757 | }; |
| 4758 | |
| 4759 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4760 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4761 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4762 | { |
| 4763 | struct nfs4_lockdata *p; |
| 4764 | struct inode *inode = lsp->ls_state->inode; |
| 4765 | struct nfs_server *server = NFS_SERVER(inode); |
| 4766 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4767 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4768 | if (p == NULL) |
| 4769 | return NULL; |
| 4770 | |
| 4771 | p->arg.fh = NFS_FH(inode); |
| 4772 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4773 | 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] | 4774 | if (p->arg.open_seqid == NULL) |
| 4775 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4776 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4777 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4778 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4779 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4780 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4781 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4782 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4783 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4784 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4785 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4786 | atomic_inc(&lsp->ls_count); |
| 4787 | p->ctx = get_nfs_open_context(ctx); |
| 4788 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4789 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4790 | out_free_seqid: |
| 4791 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4792 | out_free: |
| 4793 | kfree(p); |
| 4794 | return NULL; |
| 4795 | } |
| 4796 | |
| 4797 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4798 | { |
| 4799 | struct nfs4_lockdata *data = calldata; |
| 4800 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4802 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4803 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4804 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4805 | /* Do we need to do an open_to_lock_owner? */ |
| 4806 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4807 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4808 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4809 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 4810 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4811 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4812 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4813 | } else |
| 4814 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4815 | if (!nfs4_valid_open_stateid(state)) { |
| 4816 | data->rpc_status = -EBADF; |
| 4817 | task->tk_action = NULL; |
| 4818 | goto out_release_open_seqid; |
| 4819 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4820 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4821 | if (nfs4_setup_sequence(data->server, |
| 4822 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4823 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4824 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4825 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4826 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4827 | nfs_release_seqid(data->arg.open_seqid); |
| 4828 | out_release_lock_seqid: |
| 4829 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4830 | out_wait: |
| 4831 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4832 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4833 | } |
| 4834 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4835 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4836 | { |
| 4837 | struct nfs4_lockdata *data = calldata; |
| 4838 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4839 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4840 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4841 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4842 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4843 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4844 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4845 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4846 | if (data->rpc_status == 0) |
| 4847 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4848 | else |
| 4849 | goto out; |
| 4850 | } |
| 4851 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4852 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4853 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4854 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4855 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4856 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4857 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | static void nfs4_lock_release(void *calldata) |
| 4861 | { |
| 4862 | struct nfs4_lockdata *data = calldata; |
| 4863 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4864 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4865 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4866 | if (data->cancelled != 0) { |
| 4867 | struct rpc_task *task; |
| 4868 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4869 | data->arg.lock_seqid); |
| 4870 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4871 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4872 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4873 | } else |
| 4874 | nfs_free_seqid(data->arg.lock_seqid); |
| 4875 | nfs4_put_lock_state(data->lsp); |
| 4876 | put_nfs_open_context(data->ctx); |
| 4877 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4878 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4882 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4883 | .rpc_call_done = nfs4_lock_done, |
| 4884 | .rpc_release = nfs4_lock_release, |
| 4885 | }; |
| 4886 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4887 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4888 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4889 | switch (error) { |
| 4890 | case -NFS4ERR_ADMIN_REVOKED: |
| 4891 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4892 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4893 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4894 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4895 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4896 | break; |
| 4897 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4898 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4899 | case -NFS4ERR_EXPIRED: |
| 4900 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4901 | }; |
| 4902 | } |
| 4903 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4904 | 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] | 4905 | { |
| 4906 | struct nfs4_lockdata *data; |
| 4907 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4908 | struct rpc_message msg = { |
| 4909 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4910 | .rpc_cred = state->owner->so_cred, |
| 4911 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4912 | struct rpc_task_setup task_setup_data = { |
| 4913 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4914 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4915 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4916 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4917 | .flags = RPC_TASK_ASYNC, |
| 4918 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4919 | int ret; |
| 4920 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4921 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4922 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4923 | fl->fl_u.nfs4_fl.owner, |
| 4924 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4925 | if (data == NULL) |
| 4926 | return -ENOMEM; |
| 4927 | if (IS_SETLKW(cmd)) |
| 4928 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4929 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4930 | msg.rpc_argp = &data->arg; |
| 4931 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4932 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4933 | if (recovery_type > NFS_LOCK_NEW) { |
| 4934 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4935 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4936 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4937 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4938 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4939 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4940 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4941 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4942 | if (ret == 0) { |
| 4943 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4944 | if (ret) |
| 4945 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4946 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4947 | } else |
| 4948 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4949 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4950 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4951 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4955 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4956 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4957 | struct nfs4_exception exception = { |
| 4958 | .inode = state->inode, |
| 4959 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4960 | int err; |
| 4961 | |
| 4962 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4963 | /* Cache the lock if possible... */ |
| 4964 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4965 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4966 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4967 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4968 | break; |
| 4969 | nfs4_handle_exception(server, err, &exception); |
| 4970 | } while (exception.retry); |
| 4971 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4975 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4976 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4977 | struct nfs4_exception exception = { |
| 4978 | .inode = state->inode, |
| 4979 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4980 | int err; |
| 4981 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4982 | err = nfs4_set_lock_state(state, request); |
| 4983 | if (err != 0) |
| 4984 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4985 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4986 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4987 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4988 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4989 | switch (err) { |
| 4990 | default: |
| 4991 | goto out; |
| 4992 | case -NFS4ERR_GRACE: |
| 4993 | case -NFS4ERR_DELAY: |
| 4994 | nfs4_handle_exception(server, err, &exception); |
| 4995 | err = 0; |
| 4996 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4997 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4998 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4999 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | } |
| 5001 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5002 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5003 | /** |
| 5004 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5005 | * |
| 5006 | * @state: NFSv4 state for an inode |
| 5007 | * |
| 5008 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5009 | * Otherwise a negative NFS4ERR value is returned. |
| 5010 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5011 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5012 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5013 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5014 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5015 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5016 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5017 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5018 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5019 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 5020 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5021 | /* Free the stateid unless the server |
| 5022 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5023 | if (status != -NFS4ERR_BAD_STATEID) |
| 5024 | nfs41_free_stateid(server, |
| 5025 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5026 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5027 | ret = status; |
| 5028 | } |
| 5029 | } |
| 5030 | }; |
| 5031 | |
| 5032 | return ret; |
| 5033 | } |
| 5034 | |
| 5035 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5036 | { |
| 5037 | int status = NFS_OK; |
| 5038 | |
| 5039 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5040 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5041 | if (status != NFS_OK) |
| 5042 | status = nfs4_lock_expired(state, request); |
| 5043 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5044 | } |
| 5045 | #endif |
| 5046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5048 | { |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5049 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5050 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5051 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5052 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5053 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5055 | if ((fl_flags & FL_POSIX) && |
| 5056 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5057 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5058 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5059 | status = nfs4_set_lock_state(state, request); |
| 5060 | if (status != 0) |
| 5061 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5062 | request->fl_flags |= FL_ACCESS; |
| 5063 | status = do_vfs_lock(request->fl_file, request); |
| 5064 | if (status < 0) |
| 5065 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5066 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5067 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5068 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5069 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5070 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5071 | status = do_vfs_lock(request->fl_file, request); |
| 5072 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5073 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5074 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5075 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5076 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5077 | if (status != 0) |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5078 | goto out; |
| 5079 | down_read(&nfsi->rwsem); |
| 5080 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5081 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5082 | goto out_unlock; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5083 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5084 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5085 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5086 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5087 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5088 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5089 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5090 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5091 | out: |
| 5092 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | return status; |
| 5094 | } |
| 5095 | |
| 5096 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5097 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5098 | struct nfs4_exception exception = { |
| 5099 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5100 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5101 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | int err; |
| 5103 | |
| 5104 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5105 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5106 | if (err == -NFS4ERR_DENIED) |
| 5107 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5109 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | } while (exception.retry); |
| 5111 | return err; |
| 5112 | } |
| 5113 | |
| 5114 | static int |
| 5115 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5116 | { |
| 5117 | struct nfs_open_context *ctx; |
| 5118 | struct nfs4_state *state; |
| 5119 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5120 | int status; |
| 5121 | |
| 5122 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5123 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5124 | state = ctx->state; |
| 5125 | |
| 5126 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5127 | return -EINVAL; |
| 5128 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5129 | if (IS_GETLK(cmd)) { |
| 5130 | if (state != NULL) |
| 5131 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5132 | return 0; |
| 5133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | |
| 5135 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5136 | return -EINVAL; |
| 5137 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5138 | if (request->fl_type == F_UNLCK) { |
| 5139 | if (state != NULL) |
| 5140 | return nfs4_proc_unlck(state, cmd, request); |
| 5141 | return 0; |
| 5142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5144 | if (state == NULL) |
| 5145 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5146 | /* |
| 5147 | * Don't rely on the VFS having checked the file open mode, |
| 5148 | * since it won't do this for flock() locks. |
| 5149 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5150 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5151 | case F_RDLCK: |
| 5152 | if (!(filp->f_mode & FMODE_READ)) |
| 5153 | return -EBADF; |
| 5154 | break; |
| 5155 | case F_WRLCK: |
| 5156 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5157 | return -EBADF; |
| 5158 | } |
| 5159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | do { |
| 5161 | status = nfs4_proc_setlk(state, cmd, request); |
| 5162 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5163 | break; |
| 5164 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5165 | status = -ERESTARTSYS; |
| 5166 | if (signalled()) |
| 5167 | break; |
| 5168 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 | return status; |
| 5170 | } |
| 5171 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5172 | int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5173 | { |
| 5174 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5175 | int err; |
| 5176 | |
| 5177 | err = nfs4_set_lock_state(state, fl); |
| 5178 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5179 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5180 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5181 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5182 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5183 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5184 | struct nfs_release_lockowner_data { |
| 5185 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5186 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5187 | struct nfs_release_lockowner_args args; |
| 5188 | }; |
| 5189 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5190 | static void nfs4_release_lockowner_release(void *calldata) |
| 5191 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5192 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5193 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5194 | kfree(calldata); |
| 5195 | } |
| 5196 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5197 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5198 | .rpc_release = nfs4_release_lockowner_release, |
| 5199 | }; |
| 5200 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5201 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5202 | { |
| 5203 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5204 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5205 | struct rpc_message msg = { |
| 5206 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5207 | }; |
| 5208 | |
| 5209 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5210 | return -EINVAL; |
| 5211 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5212 | if (!data) |
| 5213 | return -ENOMEM; |
| 5214 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5215 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5216 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5217 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5218 | data->args.lock_owner.s_dev = server->s_dev; |
| 5219 | msg.rpc_argp = &data->args; |
| 5220 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5221 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5222 | } |
| 5223 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5224 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5225 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5226 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5227 | const void *buf, size_t buflen, |
| 5228 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5229 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5230 | if (strcmp(key, "") != 0) |
| 5231 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5232 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5233 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5236 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5237 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5238 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5239 | if (strcmp(key, "") != 0) |
| 5240 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5241 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5242 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5243 | } |
| 5244 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5245 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5246 | size_t list_len, const char *name, |
| 5247 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5248 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5249 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5250 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5251 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5252 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5253 | |
| 5254 | if (list && len <= list_len) |
| 5255 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5256 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5257 | } |
| 5258 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5259 | /* |
| 5260 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5261 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5262 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5263 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5264 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5265 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5266 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5267 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5268 | return; |
| 5269 | |
| 5270 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5271 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5272 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5273 | fattr->nlink = 2; |
| 5274 | } |
| 5275 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5276 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5277 | const struct qstr *name, |
| 5278 | struct nfs4_fs_locations *fs_locations, |
| 5279 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5280 | { |
| 5281 | struct nfs_server *server = NFS_SERVER(dir); |
| 5282 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5283 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5284 | }; |
| 5285 | struct nfs4_fs_locations_arg args = { |
| 5286 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5287 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5288 | .page = page, |
| 5289 | .bitmask = bitmask, |
| 5290 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5291 | struct nfs4_fs_locations_res res = { |
| 5292 | .fs_locations = fs_locations, |
| 5293 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5294 | struct rpc_message msg = { |
| 5295 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5296 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5297 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5298 | }; |
| 5299 | int status; |
| 5300 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5301 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5302 | |
| 5303 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5304 | * is not supported */ |
| 5305 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5306 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5307 | else |
| 5308 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5309 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5310 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5311 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5312 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5313 | 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] | 5314 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5315 | return status; |
| 5316 | } |
| 5317 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5318 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5319 | const struct qstr *name, |
| 5320 | struct nfs4_fs_locations *fs_locations, |
| 5321 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5322 | { |
| 5323 | struct nfs4_exception exception = { }; |
| 5324 | int err; |
| 5325 | do { |
| 5326 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5327 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5328 | &exception); |
| 5329 | } while (exception.retry); |
| 5330 | return err; |
| 5331 | } |
| 5332 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5333 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5334 | { |
| 5335 | int status; |
| 5336 | struct nfs4_secinfo_arg args = { |
| 5337 | .dir_fh = NFS_FH(dir), |
| 5338 | .name = name, |
| 5339 | }; |
| 5340 | struct nfs4_secinfo_res res = { |
| 5341 | .flavors = flavors, |
| 5342 | }; |
| 5343 | struct rpc_message msg = { |
| 5344 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5345 | .rpc_argp = &args, |
| 5346 | .rpc_resp = &res, |
| 5347 | }; |
| 5348 | |
| 5349 | dprintk("NFS call secinfo %s\n", name->name); |
| 5350 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5351 | dprintk("NFS reply secinfo: %d\n", status); |
| 5352 | return status; |
| 5353 | } |
| 5354 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5355 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5356 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5357 | { |
| 5358 | struct nfs4_exception exception = { }; |
| 5359 | int err; |
| 5360 | do { |
| 5361 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5362 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5363 | &exception); |
| 5364 | } while (exception.retry); |
| 5365 | return err; |
| 5366 | } |
| 5367 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5368 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5369 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5370 | * Check the exchange flags returned by the server for invalid flags, having |
| 5371 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5372 | * DS flags set. |
| 5373 | */ |
| 5374 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5375 | { |
| 5376 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5377 | goto out_inval; |
| 5378 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5379 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5380 | goto out_inval; |
| 5381 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5382 | goto out_inval; |
| 5383 | return NFS_OK; |
| 5384 | out_inval: |
| 5385 | return -NFS4ERR_INVAL; |
| 5386 | } |
| 5387 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5388 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5389 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5390 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5391 | { |
| 5392 | if (a->server_scope_sz == b->server_scope_sz && |
| 5393 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5394 | return true; |
| 5395 | |
| 5396 | return false; |
| 5397 | } |
| 5398 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5399 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5400 | * nfs4_proc_bind_conn_to_session() |
| 5401 | * |
| 5402 | * The 4.1 client currently uses the same TCP connection for the |
| 5403 | * fore and backchannel. |
| 5404 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5405 | 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] | 5406 | { |
| 5407 | int status; |
| 5408 | struct nfs41_bind_conn_to_session_res res; |
| 5409 | struct rpc_message msg = { |
| 5410 | .rpc_proc = |
| 5411 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5412 | .rpc_argp = clp, |
| 5413 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5414 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5415 | }; |
| 5416 | |
| 5417 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5418 | |
| 5419 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5420 | if (unlikely(res.session == NULL)) { |
| 5421 | status = -ENOMEM; |
| 5422 | goto out; |
| 5423 | } |
| 5424 | |
| 5425 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5426 | if (status == 0) { |
| 5427 | if (memcmp(res.session->sess_id.data, |
| 5428 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5429 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5430 | status = -EIO; |
| 5431 | goto out_session; |
| 5432 | } |
| 5433 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5434 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5435 | __func__); |
| 5436 | status = -EIO; |
| 5437 | goto out_session; |
| 5438 | } |
| 5439 | if (res.use_conn_in_rdma_mode) { |
| 5440 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5441 | __func__); |
| 5442 | status = -EIO; |
| 5443 | goto out_session; |
| 5444 | } |
| 5445 | } |
| 5446 | out_session: |
| 5447 | kfree(res.session); |
| 5448 | out: |
| 5449 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5450 | return status; |
| 5451 | } |
| 5452 | |
| 5453 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5454 | * nfs4_proc_exchange_id() |
| 5455 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5456 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5457 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5458 | * Since the clientid has expired, all compounds using sessions |
| 5459 | * associated with the stale clientid will be returning |
| 5460 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5461 | * be in some phase of session reset. |
| 5462 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5463 | 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] | 5464 | { |
| 5465 | nfs4_verifier verifier; |
| 5466 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5467 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5468 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5469 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5470 | }; |
| 5471 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5472 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5473 | }; |
| 5474 | int status; |
| 5475 | struct rpc_message msg = { |
| 5476 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5477 | .rpc_argp = &args, |
| 5478 | .rpc_resp = &res, |
| 5479 | .rpc_cred = cred, |
| 5480 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5481 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5482 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5483 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5484 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5485 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5486 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5487 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5488 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5489 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5490 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5491 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5492 | status = -ENOMEM; |
| 5493 | goto out; |
| 5494 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5495 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5496 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5497 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5498 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5499 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5500 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5501 | } |
| 5502 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5503 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5504 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5505 | status = -ENOMEM; |
| 5506 | goto out_server_scope; |
| 5507 | } |
| 5508 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5509 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5510 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5511 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5512 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5513 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5514 | clp->cl_clientid = res.clientid; |
| 5515 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5516 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5517 | clp->cl_seqid = res.seqid; |
| 5518 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5519 | kfree(clp->cl_serverowner); |
| 5520 | clp->cl_serverowner = res.server_owner; |
| 5521 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5522 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5523 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5524 | kfree(clp->cl_implid); |
| 5525 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5526 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5527 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5528 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5529 | res.server_scope)) { |
| 5530 | dprintk("%s: server_scope mismatch detected\n", |
| 5531 | __func__); |
| 5532 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5533 | kfree(clp->cl_serverscope); |
| 5534 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5535 | } |
| 5536 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5537 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5538 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5539 | goto out; |
| 5540 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5541 | } else |
| 5542 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5543 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5544 | out_server_owner: |
| 5545 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5546 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5547 | kfree(res.server_scope); |
| 5548 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5549 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5550 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5551 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5552 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5553 | clp->cl_implid->date.seconds, |
| 5554 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5555 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5556 | return status; |
| 5557 | } |
| 5558 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5559 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5560 | struct rpc_cred *cred) |
| 5561 | { |
| 5562 | struct rpc_message msg = { |
| 5563 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5564 | .rpc_argp = clp, |
| 5565 | .rpc_cred = cred, |
| 5566 | }; |
| 5567 | int status; |
| 5568 | |
| 5569 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5570 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5571 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5572 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5573 | return status; |
| 5574 | } |
| 5575 | |
| 5576 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5577 | struct rpc_cred *cred) |
| 5578 | { |
| 5579 | unsigned int loop; |
| 5580 | int ret; |
| 5581 | |
| 5582 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5583 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5584 | switch (ret) { |
| 5585 | case -NFS4ERR_DELAY: |
| 5586 | case -NFS4ERR_CLIENTID_BUSY: |
| 5587 | ssleep(1); |
| 5588 | break; |
| 5589 | default: |
| 5590 | return ret; |
| 5591 | } |
| 5592 | } |
| 5593 | return 0; |
| 5594 | } |
| 5595 | |
| 5596 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5597 | { |
| 5598 | struct rpc_cred *cred; |
| 5599 | int ret = 0; |
| 5600 | |
| 5601 | if (clp->cl_mvops->minor_version < 1) |
| 5602 | goto out; |
| 5603 | if (clp->cl_exchange_flags == 0) |
| 5604 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5605 | if (clp->cl_preserve_clid) |
| 5606 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5607 | cred = nfs4_get_exchange_id_cred(clp); |
| 5608 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5609 | if (cred) |
| 5610 | put_rpccred(cred); |
| 5611 | switch (ret) { |
| 5612 | case 0: |
| 5613 | case -NFS4ERR_STALE_CLIENTID: |
| 5614 | clp->cl_exchange_flags = 0; |
| 5615 | } |
| 5616 | out: |
| 5617 | return ret; |
| 5618 | } |
| 5619 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5620 | struct nfs4_get_lease_time_data { |
| 5621 | struct nfs4_get_lease_time_args *args; |
| 5622 | struct nfs4_get_lease_time_res *res; |
| 5623 | struct nfs_client *clp; |
| 5624 | }; |
| 5625 | |
| 5626 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5627 | void *calldata) |
| 5628 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5629 | struct nfs4_get_lease_time_data *data = |
| 5630 | (struct nfs4_get_lease_time_data *)calldata; |
| 5631 | |
| 5632 | dprintk("--> %s\n", __func__); |
| 5633 | /* just setup sequence, do not trigger session recovery |
| 5634 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5635 | nfs41_setup_sequence(data->clp->cl_session, |
| 5636 | &data->args->la_seq_args, |
| 5637 | &data->res->lr_seq_res, |
| 5638 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5639 | dprintk("<-- %s\n", __func__); |
| 5640 | } |
| 5641 | |
| 5642 | /* |
| 5643 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5644 | * from sequence operation or clientid errors. |
| 5645 | */ |
| 5646 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5647 | { |
| 5648 | struct nfs4_get_lease_time_data *data = |
| 5649 | (struct nfs4_get_lease_time_data *)calldata; |
| 5650 | |
| 5651 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5652 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5653 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5654 | switch (task->tk_status) { |
| 5655 | case -NFS4ERR_DELAY: |
| 5656 | case -NFS4ERR_GRACE: |
| 5657 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5658 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5659 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5660 | /* fall through */ |
| 5661 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5662 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5663 | return; |
| 5664 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5665 | dprintk("<-- %s\n", __func__); |
| 5666 | } |
| 5667 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5668 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5669 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5670 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5671 | }; |
| 5672 | |
| 5673 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5674 | { |
| 5675 | struct rpc_task *task; |
| 5676 | struct nfs4_get_lease_time_args args; |
| 5677 | struct nfs4_get_lease_time_res res = { |
| 5678 | .lr_fsinfo = fsinfo, |
| 5679 | }; |
| 5680 | struct nfs4_get_lease_time_data data = { |
| 5681 | .args = &args, |
| 5682 | .res = &res, |
| 5683 | .clp = clp, |
| 5684 | }; |
| 5685 | struct rpc_message msg = { |
| 5686 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5687 | .rpc_argp = &args, |
| 5688 | .rpc_resp = &res, |
| 5689 | }; |
| 5690 | struct rpc_task_setup task_setup = { |
| 5691 | .rpc_client = clp->cl_rpcclient, |
| 5692 | .rpc_message = &msg, |
| 5693 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5694 | .callback_data = &data, |
| 5695 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5696 | }; |
| 5697 | int status; |
| 5698 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5699 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5700 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5701 | dprintk("--> %s\n", __func__); |
| 5702 | task = rpc_run_task(&task_setup); |
| 5703 | |
| 5704 | if (IS_ERR(task)) |
| 5705 | status = PTR_ERR(task); |
| 5706 | else { |
| 5707 | status = task->tk_status; |
| 5708 | rpc_put_task(task); |
| 5709 | } |
| 5710 | dprintk("<-- %s return %d\n", __func__, status); |
| 5711 | |
| 5712 | return status; |
| 5713 | } |
| 5714 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5715 | /* |
| 5716 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5717 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5718 | * use them. |
| 5719 | * |
| 5720 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5721 | * always set csa_cachethis to FALSE because the current implementation |
| 5722 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5723 | */ |
| 5724 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5725 | { |
| 5726 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5727 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5728 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5729 | |
| 5730 | if (mxrqst_sz == 0) |
| 5731 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5732 | if (mxresp_sz == 0) |
| 5733 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5734 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5735 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5736 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5737 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5738 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5739 | |
| 5740 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5741 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5742 | __func__, |
| 5743 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5744 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5745 | |
| 5746 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5747 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5748 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5749 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5750 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5751 | args->bc_attrs.max_reqs = 1; |
| 5752 | |
| 5753 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5754 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5755 | __func__, |
| 5756 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5757 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5758 | args->bc_attrs.max_reqs); |
| 5759 | } |
| 5760 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5761 | 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] | 5762 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5763 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5764 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5765 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5766 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5767 | return -EINVAL; |
| 5768 | /* |
| 5769 | * Our requested max_ops is the minimum we need; we're not |
| 5770 | * prepared to break up compounds into smaller pieces than that. |
| 5771 | * So, no point even trying to continue if the server won't |
| 5772 | * cooperate: |
| 5773 | */ |
| 5774 | if (rcvd->max_ops < sent->max_ops) |
| 5775 | return -EINVAL; |
| 5776 | if (rcvd->max_reqs == 0) |
| 5777 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5778 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5779 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5780 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5781 | } |
| 5782 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5783 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5784 | { |
| 5785 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5786 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5787 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5788 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5789 | return -EINVAL; |
| 5790 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5791 | return -EINVAL; |
| 5792 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5793 | return -EINVAL; |
| 5794 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5795 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5796 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5797 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5798 | return -EINVAL; |
| 5799 | return 0; |
| 5800 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5801 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5802 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5803 | struct nfs4_session *session) |
| 5804 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5805 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5806 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5807 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5808 | if (ret) |
| 5809 | return ret; |
| 5810 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5811 | } |
| 5812 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5813 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5814 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5815 | { |
| 5816 | struct nfs4_session *session = clp->cl_session; |
| 5817 | struct nfs41_create_session_args args = { |
| 5818 | .client = clp, |
| 5819 | .cb_program = NFS4_CALLBACK, |
| 5820 | }; |
| 5821 | struct nfs41_create_session_res res = { |
| 5822 | .client = clp, |
| 5823 | }; |
| 5824 | struct rpc_message msg = { |
| 5825 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5826 | .rpc_argp = &args, |
| 5827 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5828 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5829 | }; |
| 5830 | int status; |
| 5831 | |
| 5832 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5833 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5834 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5835 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5836 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5837 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5838 | /* Verify the session's negotiated channel_attrs values */ |
| 5839 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5840 | /* Increment the clientid slot sequence id */ |
| 5841 | clp->cl_seqid++; |
| 5842 | } |
| 5843 | |
| 5844 | return status; |
| 5845 | } |
| 5846 | |
| 5847 | /* |
| 5848 | * Issues a CREATE_SESSION operation to the server. |
| 5849 | * It is the responsibility of the caller to verify the session is |
| 5850 | * expired before calling this routine. |
| 5851 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5852 | 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] | 5853 | { |
| 5854 | int status; |
| 5855 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5856 | struct nfs4_session *session = clp->cl_session; |
| 5857 | |
| 5858 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5859 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5860 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5861 | if (status) |
| 5862 | goto out; |
| 5863 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5864 | /* Init or reset the session slot tables */ |
| 5865 | status = nfs4_setup_session_slot_tables(session); |
| 5866 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5867 | if (status) |
| 5868 | goto out; |
| 5869 | |
| 5870 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5871 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5872 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5873 | out: |
| 5874 | dprintk("<-- %s\n", __func__); |
| 5875 | return status; |
| 5876 | } |
| 5877 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5878 | /* |
| 5879 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5880 | * The caller must serialize access to this routine. |
| 5881 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5882 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5883 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5884 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5885 | struct rpc_message msg = { |
| 5886 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5887 | .rpc_argp = session, |
| 5888 | .rpc_cred = cred, |
| 5889 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5890 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5891 | |
| 5892 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5893 | |
| 5894 | /* session is still being setup */ |
| 5895 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5896 | return status; |
| 5897 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5898 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5899 | |
| 5900 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5901 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5902 | "Session has been destroyed regardless...\n", status); |
| 5903 | |
| 5904 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5905 | return status; |
| 5906 | } |
| 5907 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5908 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5909 | * Renew the cl_session lease. |
| 5910 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5911 | struct nfs4_sequence_data { |
| 5912 | struct nfs_client *clp; |
| 5913 | struct nfs4_sequence_args args; |
| 5914 | struct nfs4_sequence_res res; |
| 5915 | }; |
| 5916 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5917 | static void nfs41_sequence_release(void *data) |
| 5918 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5919 | struct nfs4_sequence_data *calldata = data; |
| 5920 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5921 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5922 | if (atomic_read(&clp->cl_count) > 1) |
| 5923 | nfs4_schedule_state_renewal(clp); |
| 5924 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5925 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5926 | } |
| 5927 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5928 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5929 | { |
| 5930 | switch(task->tk_status) { |
| 5931 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5932 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5933 | return -EAGAIN; |
| 5934 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5935 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5936 | } |
| 5937 | return 0; |
| 5938 | } |
| 5939 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5940 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5941 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5942 | struct nfs4_sequence_data *calldata = data; |
| 5943 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5944 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5945 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5946 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5947 | |
| 5948 | if (task->tk_status < 0) { |
| 5949 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5950 | if (atomic_read(&clp->cl_count) == 1) |
| 5951 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5952 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5953 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5954 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5955 | return; |
| 5956 | } |
| 5957 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5958 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5959 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5960 | dprintk("<-- %s\n", __func__); |
| 5961 | } |
| 5962 | |
| 5963 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5964 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5965 | struct nfs4_sequence_data *calldata = data; |
| 5966 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5967 | struct nfs4_sequence_args *args; |
| 5968 | struct nfs4_sequence_res *res; |
| 5969 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5970 | args = task->tk_msg.rpc_argp; |
| 5971 | res = task->tk_msg.rpc_resp; |
| 5972 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5973 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5977 | .rpc_call_done = nfs41_sequence_call_done, |
| 5978 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5979 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5980 | }; |
| 5981 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5982 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5983 | struct rpc_cred *cred, |
| 5984 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5985 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5986 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5987 | struct rpc_message msg = { |
| 5988 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5989 | .rpc_cred = cred, |
| 5990 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5991 | struct rpc_task_setup task_setup_data = { |
| 5992 | .rpc_client = clp->cl_rpcclient, |
| 5993 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5994 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5995 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5996 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5997 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5998 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5999 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6000 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6001 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6002 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6003 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6004 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6005 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6006 | if (is_privileged) |
| 6007 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6008 | msg.rpc_argp = &calldata->args; |
| 6009 | msg.rpc_resp = &calldata->res; |
| 6010 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6011 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6012 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6013 | return rpc_run_task(&task_setup_data); |
| 6014 | } |
| 6015 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6016 | 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] | 6017 | { |
| 6018 | struct rpc_task *task; |
| 6019 | int ret = 0; |
| 6020 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6021 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6022 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6023 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6024 | if (IS_ERR(task)) |
| 6025 | ret = PTR_ERR(task); |
| 6026 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6027 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6028 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6029 | return ret; |
| 6030 | } |
| 6031 | |
| 6032 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6033 | { |
| 6034 | struct rpc_task *task; |
| 6035 | int ret; |
| 6036 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6037 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6038 | if (IS_ERR(task)) { |
| 6039 | ret = PTR_ERR(task); |
| 6040 | goto out; |
| 6041 | } |
| 6042 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6043 | if (!ret) { |
| 6044 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6045 | |
| 6046 | if (task->tk_status == 0) |
| 6047 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6048 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6049 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6050 | rpc_put_task(task); |
| 6051 | out: |
| 6052 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6053 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6054 | } |
| 6055 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6056 | struct nfs4_reclaim_complete_data { |
| 6057 | struct nfs_client *clp; |
| 6058 | struct nfs41_reclaim_complete_args arg; |
| 6059 | struct nfs41_reclaim_complete_res res; |
| 6060 | }; |
| 6061 | |
| 6062 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6063 | { |
| 6064 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6065 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6066 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6067 | &calldata->arg.seq_args, |
| 6068 | &calldata->res.seq_res, |
| 6069 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6070 | } |
| 6071 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6072 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6073 | { |
| 6074 | switch(task->tk_status) { |
| 6075 | case 0: |
| 6076 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6077 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6078 | break; |
| 6079 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6080 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6081 | /* fall through */ |
| 6082 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6083 | return -EAGAIN; |
| 6084 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6085 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6086 | } |
| 6087 | return 0; |
| 6088 | } |
| 6089 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6090 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6091 | { |
| 6092 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6093 | struct nfs_client *clp = calldata->clp; |
| 6094 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6095 | |
| 6096 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6097 | if (!nfs41_sequence_done(task, res)) |
| 6098 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6099 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6100 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6101 | rpc_restart_call_prepare(task); |
| 6102 | return; |
| 6103 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6104 | dprintk("<-- %s\n", __func__); |
| 6105 | } |
| 6106 | |
| 6107 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6108 | { |
| 6109 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6110 | |
| 6111 | kfree(calldata); |
| 6112 | } |
| 6113 | |
| 6114 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6115 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6116 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6117 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6118 | }; |
| 6119 | |
| 6120 | /* |
| 6121 | * Issue a global reclaim complete. |
| 6122 | */ |
| 6123 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6124 | { |
| 6125 | struct nfs4_reclaim_complete_data *calldata; |
| 6126 | struct rpc_task *task; |
| 6127 | struct rpc_message msg = { |
| 6128 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6129 | }; |
| 6130 | struct rpc_task_setup task_setup_data = { |
| 6131 | .rpc_client = clp->cl_rpcclient, |
| 6132 | .rpc_message = &msg, |
| 6133 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6134 | .flags = RPC_TASK_ASYNC, |
| 6135 | }; |
| 6136 | int status = -ENOMEM; |
| 6137 | |
| 6138 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6139 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6140 | if (calldata == NULL) |
| 6141 | goto out; |
| 6142 | calldata->clp = clp; |
| 6143 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6144 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6145 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6146 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6147 | msg.rpc_argp = &calldata->arg; |
| 6148 | msg.rpc_resp = &calldata->res; |
| 6149 | task_setup_data.callback_data = calldata; |
| 6150 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6151 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6152 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6153 | goto out; |
| 6154 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6155 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6156 | if (status == 0) |
| 6157 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6158 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6159 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6160 | out: |
| 6161 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6162 | return status; |
| 6163 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6164 | |
| 6165 | static void |
| 6166 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6167 | { |
| 6168 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6169 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6170 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6171 | |
| 6172 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6173 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6174 | * right now covering the LAYOUTGET we are about to send. |
| 6175 | * However, that is not so catastrophic, and there seems |
| 6176 | * to be no way to prevent it completely. |
| 6177 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6178 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6179 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6180 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6181 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6182 | NFS_I(lgp->args.inode)->layout, |
| 6183 | lgp->args.ctx->state)) { |
| 6184 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6185 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6189 | { |
| 6190 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6191 | struct inode *inode = lgp->args.inode; |
| 6192 | struct nfs_server *server = NFS_SERVER(inode); |
| 6193 | struct pnfs_layout_hdr *lo; |
| 6194 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6195 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6196 | |
| 6197 | dprintk("--> %s\n", __func__); |
| 6198 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6199 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6200 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6201 | |
| 6202 | switch (task->tk_status) { |
| 6203 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6204 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6205 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6206 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6207 | timeo = rpc_get_timeout(task->tk_client); |
| 6208 | giveup = lgp->args.timestamp + timeo; |
| 6209 | if (time_after(giveup, jiffies)) |
| 6210 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6211 | break; |
| 6212 | case -NFS4ERR_EXPIRED: |
| 6213 | case -NFS4ERR_BAD_STATEID: |
| 6214 | spin_lock(&inode->i_lock); |
| 6215 | lo = NFS_I(inode)->layout; |
| 6216 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6217 | spin_unlock(&inode->i_lock); |
| 6218 | /* If the open stateid was bad, then recover it. */ |
| 6219 | state = lgp->args.ctx->state; |
| 6220 | } else { |
| 6221 | LIST_HEAD(head); |
| 6222 | |
| 6223 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6224 | spin_unlock(&inode->i_lock); |
| 6225 | /* Mark the bad layout state as invalid, then |
| 6226 | * retry using the open stateid. */ |
| 6227 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6228 | } |
| 6229 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6230 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6231 | rpc_restart_call_prepare(task); |
| 6232 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6233 | dprintk("<-- %s\n", __func__); |
| 6234 | } |
| 6235 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6236 | static size_t max_response_pages(struct nfs_server *server) |
| 6237 | { |
| 6238 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6239 | return nfs_page_array_len(0, max_resp_sz); |
| 6240 | } |
| 6241 | |
| 6242 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6243 | { |
| 6244 | int i; |
| 6245 | |
| 6246 | if (!pages) |
| 6247 | return; |
| 6248 | |
| 6249 | for (i = 0; i < size; i++) { |
| 6250 | if (!pages[i]) |
| 6251 | break; |
| 6252 | __free_page(pages[i]); |
| 6253 | } |
| 6254 | kfree(pages); |
| 6255 | } |
| 6256 | |
| 6257 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6258 | { |
| 6259 | struct page **pages; |
| 6260 | int i; |
| 6261 | |
| 6262 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6263 | if (!pages) { |
| 6264 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6265 | return NULL; |
| 6266 | } |
| 6267 | |
| 6268 | for (i = 0; i < size; i++) { |
| 6269 | pages[i] = alloc_page(gfp_flags); |
| 6270 | if (!pages[i]) { |
| 6271 | dprintk("%s: failed to allocate page\n", __func__); |
| 6272 | nfs4_free_pages(pages, size); |
| 6273 | return NULL; |
| 6274 | } |
| 6275 | } |
| 6276 | |
| 6277 | return pages; |
| 6278 | } |
| 6279 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6280 | static void nfs4_layoutget_release(void *calldata) |
| 6281 | { |
| 6282 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6283 | struct inode *inode = lgp->args.inode; |
| 6284 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6285 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6286 | |
| 6287 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6288 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6289 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6290 | put_nfs_open_context(lgp->args.ctx); |
| 6291 | kfree(calldata); |
| 6292 | dprintk("<-- %s\n", __func__); |
| 6293 | } |
| 6294 | |
| 6295 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6296 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6297 | .rpc_call_done = nfs4_layoutget_done, |
| 6298 | .rpc_release = nfs4_layoutget_release, |
| 6299 | }; |
| 6300 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6301 | struct pnfs_layout_segment * |
| 6302 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6303 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6304 | struct inode *inode = lgp->args.inode; |
| 6305 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6306 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6307 | struct rpc_task *task; |
| 6308 | struct rpc_message msg = { |
| 6309 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6310 | .rpc_argp = &lgp->args, |
| 6311 | .rpc_resp = &lgp->res, |
| 6312 | }; |
| 6313 | struct rpc_task_setup task_setup_data = { |
| 6314 | .rpc_client = server->client, |
| 6315 | .rpc_message = &msg, |
| 6316 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6317 | .callback_data = lgp, |
| 6318 | .flags = RPC_TASK_ASYNC, |
| 6319 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6320 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6321 | int status = 0; |
| 6322 | |
| 6323 | dprintk("--> %s\n", __func__); |
| 6324 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6325 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6326 | if (!lgp->args.layout.pages) { |
| 6327 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6328 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6329 | } |
| 6330 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6331 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6332 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6333 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6334 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6335 | 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] | 6336 | |
| 6337 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6338 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6339 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6340 | task = rpc_run_task(&task_setup_data); |
| 6341 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6342 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6343 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6344 | if (status == 0) |
| 6345 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6346 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6347 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6348 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6349 | rpc_put_task(task); |
| 6350 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6351 | if (status) |
| 6352 | return ERR_PTR(status); |
| 6353 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6354 | } |
| 6355 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6356 | static void |
| 6357 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6358 | { |
| 6359 | struct nfs4_layoutreturn *lrp = calldata; |
| 6360 | |
| 6361 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6362 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6363 | &lrp->args.seq_args, |
| 6364 | &lrp->res.seq_res, |
| 6365 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6369 | { |
| 6370 | struct nfs4_layoutreturn *lrp = calldata; |
| 6371 | struct nfs_server *server; |
| 6372 | |
| 6373 | dprintk("--> %s\n", __func__); |
| 6374 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6375 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6376 | return; |
| 6377 | |
| 6378 | server = NFS_SERVER(lrp->args.inode); |
| 6379 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6380 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6381 | return; |
| 6382 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6383 | dprintk("<-- %s\n", __func__); |
| 6384 | } |
| 6385 | |
| 6386 | static void nfs4_layoutreturn_release(void *calldata) |
| 6387 | { |
| 6388 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6389 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6390 | |
| 6391 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6392 | spin_lock(&lo->plh_inode->i_lock); |
| 6393 | if (lrp->res.lrs_present) |
| 6394 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6395 | lo->plh_block_lgets--; |
| 6396 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6397 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6398 | kfree(calldata); |
| 6399 | dprintk("<-- %s\n", __func__); |
| 6400 | } |
| 6401 | |
| 6402 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6403 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6404 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6405 | .rpc_release = nfs4_layoutreturn_release, |
| 6406 | }; |
| 6407 | |
| 6408 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6409 | { |
| 6410 | struct rpc_task *task; |
| 6411 | struct rpc_message msg = { |
| 6412 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6413 | .rpc_argp = &lrp->args, |
| 6414 | .rpc_resp = &lrp->res, |
| 6415 | }; |
| 6416 | struct rpc_task_setup task_setup_data = { |
| 6417 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6418 | .rpc_message = &msg, |
| 6419 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6420 | .callback_data = lrp, |
| 6421 | }; |
| 6422 | int status; |
| 6423 | |
| 6424 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6425 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6426 | task = rpc_run_task(&task_setup_data); |
| 6427 | if (IS_ERR(task)) |
| 6428 | return PTR_ERR(task); |
| 6429 | status = task->tk_status; |
| 6430 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6431 | rpc_put_task(task); |
| 6432 | return status; |
| 6433 | } |
| 6434 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6435 | /* |
| 6436 | * Retrieve the list of Data Server devices from the MDS. |
| 6437 | */ |
| 6438 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6439 | const struct nfs_fh *fh, |
| 6440 | struct pnfs_devicelist *devlist) |
| 6441 | { |
| 6442 | struct nfs4_getdevicelist_args args = { |
| 6443 | .fh = fh, |
| 6444 | .layoutclass = server->pnfs_curr_ld->id, |
| 6445 | }; |
| 6446 | struct nfs4_getdevicelist_res res = { |
| 6447 | .devlist = devlist, |
| 6448 | }; |
| 6449 | struct rpc_message msg = { |
| 6450 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6451 | .rpc_argp = &args, |
| 6452 | .rpc_resp = &res, |
| 6453 | }; |
| 6454 | int status; |
| 6455 | |
| 6456 | dprintk("--> %s\n", __func__); |
| 6457 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6458 | &res.seq_res, 0); |
| 6459 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6460 | return status; |
| 6461 | } |
| 6462 | |
| 6463 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6464 | const struct nfs_fh *fh, |
| 6465 | struct pnfs_devicelist *devlist) |
| 6466 | { |
| 6467 | struct nfs4_exception exception = { }; |
| 6468 | int err; |
| 6469 | |
| 6470 | do { |
| 6471 | err = nfs4_handle_exception(server, |
| 6472 | _nfs4_getdevicelist(server, fh, devlist), |
| 6473 | &exception); |
| 6474 | } while (exception.retry); |
| 6475 | |
| 6476 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6477 | err, devlist->num_devs); |
| 6478 | |
| 6479 | return err; |
| 6480 | } |
| 6481 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6482 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6483 | static int |
| 6484 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6485 | { |
| 6486 | struct nfs4_getdeviceinfo_args args = { |
| 6487 | .pdev = pdev, |
| 6488 | }; |
| 6489 | struct nfs4_getdeviceinfo_res res = { |
| 6490 | .pdev = pdev, |
| 6491 | }; |
| 6492 | struct rpc_message msg = { |
| 6493 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6494 | .rpc_argp = &args, |
| 6495 | .rpc_resp = &res, |
| 6496 | }; |
| 6497 | int status; |
| 6498 | |
| 6499 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6500 | 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] | 6501 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6502 | |
| 6503 | return status; |
| 6504 | } |
| 6505 | |
| 6506 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6507 | { |
| 6508 | struct nfs4_exception exception = { }; |
| 6509 | int err; |
| 6510 | |
| 6511 | do { |
| 6512 | err = nfs4_handle_exception(server, |
| 6513 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6514 | &exception); |
| 6515 | } while (exception.retry); |
| 6516 | return err; |
| 6517 | } |
| 6518 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6519 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6520 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6521 | { |
| 6522 | struct nfs4_layoutcommit_data *data = calldata; |
| 6523 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6524 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6525 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6526 | nfs41_setup_sequence(session, |
| 6527 | &data->args.seq_args, |
| 6528 | &data->res.seq_res, |
| 6529 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6530 | } |
| 6531 | |
| 6532 | static void |
| 6533 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6534 | { |
| 6535 | struct nfs4_layoutcommit_data *data = calldata; |
| 6536 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6537 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6538 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6539 | return; |
| 6540 | |
| 6541 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6542 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6543 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6544 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6545 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6546 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6547 | break; |
| 6548 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6549 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6550 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6551 | break; |
| 6552 | default: |
| 6553 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6554 | rpc_restart_call_prepare(task); |
| 6555 | return; |
| 6556 | } |
| 6557 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | static void nfs4_layoutcommit_release(void *calldata) |
| 6561 | { |
| 6562 | struct nfs4_layoutcommit_data *data = calldata; |
| 6563 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6564 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6565 | put_rpccred(data->cred); |
| 6566 | kfree(data); |
| 6567 | } |
| 6568 | |
| 6569 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6570 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6571 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6572 | .rpc_release = nfs4_layoutcommit_release, |
| 6573 | }; |
| 6574 | |
| 6575 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6576 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6577 | { |
| 6578 | struct rpc_message msg = { |
| 6579 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6580 | .rpc_argp = &data->args, |
| 6581 | .rpc_resp = &data->res, |
| 6582 | .rpc_cred = data->cred, |
| 6583 | }; |
| 6584 | struct rpc_task_setup task_setup_data = { |
| 6585 | .task = &data->task, |
| 6586 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6587 | .rpc_message = &msg, |
| 6588 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6589 | .callback_data = data, |
| 6590 | .flags = RPC_TASK_ASYNC, |
| 6591 | }; |
| 6592 | struct rpc_task *task; |
| 6593 | int status = 0; |
| 6594 | |
| 6595 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6596 | "lbw: %llu inode %lu\n", |
| 6597 | data->task.tk_pid, sync, |
| 6598 | data->args.lastbytewritten, |
| 6599 | data->args.inode->i_ino); |
| 6600 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6601 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6602 | task = rpc_run_task(&task_setup_data); |
| 6603 | if (IS_ERR(task)) |
| 6604 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6605 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6606 | goto out; |
| 6607 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6608 | if (status != 0) |
| 6609 | goto out; |
| 6610 | status = task->tk_status; |
| 6611 | out: |
| 6612 | dprintk("%s: status %d\n", __func__, status); |
| 6613 | rpc_put_task(task); |
| 6614 | return status; |
| 6615 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6616 | |
| 6617 | static int |
| 6618 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6619 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6620 | { |
| 6621 | struct nfs41_secinfo_no_name_args args = { |
| 6622 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6623 | }; |
| 6624 | struct nfs4_secinfo_res res = { |
| 6625 | .flavors = flavors, |
| 6626 | }; |
| 6627 | struct rpc_message msg = { |
| 6628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6629 | .rpc_argp = &args, |
| 6630 | .rpc_resp = &res, |
| 6631 | }; |
| 6632 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6633 | } |
| 6634 | |
| 6635 | static int |
| 6636 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6637 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6638 | { |
| 6639 | struct nfs4_exception exception = { }; |
| 6640 | int err; |
| 6641 | do { |
| 6642 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6643 | switch (err) { |
| 6644 | case 0: |
| 6645 | case -NFS4ERR_WRONGSEC: |
| 6646 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6647 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6648 | default: |
| 6649 | err = nfs4_handle_exception(server, err, &exception); |
| 6650 | } |
| 6651 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6652 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6653 | return err; |
| 6654 | } |
| 6655 | |
| 6656 | static int |
| 6657 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6658 | struct nfs_fsinfo *info) |
| 6659 | { |
| 6660 | int err; |
| 6661 | struct page *page; |
| 6662 | rpc_authflavor_t flavor; |
| 6663 | struct nfs4_secinfo_flavors *flavors; |
| 6664 | |
| 6665 | page = alloc_page(GFP_KERNEL); |
| 6666 | if (!page) { |
| 6667 | err = -ENOMEM; |
| 6668 | goto out; |
| 6669 | } |
| 6670 | |
| 6671 | flavors = page_address(page); |
| 6672 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6673 | |
| 6674 | /* |
| 6675 | * Fall back on "guess and check" method if |
| 6676 | * the server doesn't support SECINFO_NO_NAME |
| 6677 | */ |
| 6678 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6679 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6680 | goto out_freepage; |
| 6681 | } |
| 6682 | if (err) |
| 6683 | goto out_freepage; |
| 6684 | |
| 6685 | flavor = nfs_find_best_sec(flavors); |
| 6686 | if (err == 0) |
| 6687 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6688 | |
| 6689 | out_freepage: |
| 6690 | put_page(page); |
| 6691 | if (err == -EACCES) |
| 6692 | return -EPERM; |
| 6693 | out: |
| 6694 | return err; |
| 6695 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6696 | |
| 6697 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6698 | { |
| 6699 | int status; |
| 6700 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6701 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6702 | }; |
| 6703 | struct nfs41_test_stateid_res res; |
| 6704 | struct rpc_message msg = { |
| 6705 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6706 | .rpc_argp = &args, |
| 6707 | .rpc_resp = &res, |
| 6708 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6709 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6710 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6711 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6712 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6713 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6714 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6715 | if (status != NFS_OK) { |
| 6716 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6717 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6718 | } |
| 6719 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6720 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6721 | } |
| 6722 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6723 | /** |
| 6724 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6725 | * |
| 6726 | * @server: server / transport on which to perform the operation |
| 6727 | * @stateid: state ID to test |
| 6728 | * |
| 6729 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6730 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6731 | * failed or the state ID is not currently valid. |
| 6732 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6733 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6734 | { |
| 6735 | struct nfs4_exception exception = { }; |
| 6736 | int err; |
| 6737 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6738 | err = _nfs41_test_stateid(server, stateid); |
| 6739 | if (err != -NFS4ERR_DELAY) |
| 6740 | break; |
| 6741 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6742 | } while (exception.retry); |
| 6743 | return err; |
| 6744 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6745 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6746 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6747 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6748 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6749 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6750 | }; |
| 6751 | struct nfs41_free_stateid_res res; |
| 6752 | struct rpc_message msg = { |
| 6753 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6754 | .rpc_argp = &args, |
| 6755 | .rpc_resp = &res, |
| 6756 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6757 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6758 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6759 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6760 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6761 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6762 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6763 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6764 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6765 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6766 | } |
| 6767 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6768 | /** |
| 6769 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6770 | * |
| 6771 | * @server: server / transport on which to perform the operation |
| 6772 | * @stateid: state ID to release |
| 6773 | * |
| 6774 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6775 | * negative NFS4ERR value is returned. |
| 6776 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6777 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6778 | { |
| 6779 | struct nfs4_exception exception = { }; |
| 6780 | int err; |
| 6781 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6782 | err = _nfs4_free_stateid(server, stateid); |
| 6783 | if (err != -NFS4ERR_DELAY) |
| 6784 | break; |
| 6785 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6786 | } while (exception.retry); |
| 6787 | return err; |
| 6788 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6789 | |
| 6790 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6791 | const nfs4_stateid *s2) |
| 6792 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6793 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6794 | return false; |
| 6795 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6796 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6797 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6798 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6799 | return true; |
| 6800 | |
| 6801 | return false; |
| 6802 | } |
| 6803 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6804 | #endif /* CONFIG_NFS_V4_1 */ |
| 6805 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6806 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6807 | const nfs4_stateid *s2) |
| 6808 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6809 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6810 | } |
| 6811 | |
| 6812 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6813 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6814 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6815 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6816 | .recover_open = nfs4_open_reclaim, |
| 6817 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6818 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6819 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6820 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6821 | }; |
| 6822 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6823 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6824 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6825 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6826 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6827 | .recover_open = nfs4_open_reclaim, |
| 6828 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6829 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6830 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6831 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6832 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6833 | }; |
| 6834 | #endif /* CONFIG_NFS_V4_1 */ |
| 6835 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6836 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6837 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6838 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6839 | .recover_open = nfs4_open_expired, |
| 6840 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6841 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6842 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6843 | }; |
| 6844 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6845 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6846 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6847 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6848 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6849 | .recover_open = nfs41_open_expired, |
| 6850 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6851 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6852 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6853 | }; |
| 6854 | #endif /* CONFIG_NFS_V4_1 */ |
| 6855 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6856 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6857 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6858 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6859 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6860 | }; |
| 6861 | |
| 6862 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6863 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6864 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6865 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6866 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6867 | }; |
| 6868 | #endif |
| 6869 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6870 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6871 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6872 | .init_caps = NFS_CAP_READDIRPLUS |
| 6873 | | NFS_CAP_ATOMIC_OPEN |
| 6874 | | NFS_CAP_CHANGE_ATTR |
| 6875 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6876 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6877 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6878 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6879 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6880 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6881 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6882 | }; |
| 6883 | |
| 6884 | #if defined(CONFIG_NFS_V4_1) |
| 6885 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6886 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6887 | .init_caps = NFS_CAP_READDIRPLUS |
| 6888 | | NFS_CAP_ATOMIC_OPEN |
| 6889 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 6890 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 6891 | | NFS_CAP_STATEID_NFSV41 |
| 6892 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6893 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6894 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6895 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6896 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6897 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6898 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6899 | }; |
| 6900 | #endif |
| 6901 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6902 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6903 | [0] = &nfs_v4_0_minor_ops, |
| 6904 | #if defined(CONFIG_NFS_V4_1) |
| 6905 | [1] = &nfs_v4_1_minor_ops, |
| 6906 | #endif |
| 6907 | }; |
| 6908 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6909 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6910 | .create = nfs_create, |
| 6911 | .lookup = nfs_lookup, |
| 6912 | .atomic_open = nfs_atomic_open, |
| 6913 | .link = nfs_link, |
| 6914 | .unlink = nfs_unlink, |
| 6915 | .symlink = nfs_symlink, |
| 6916 | .mkdir = nfs_mkdir, |
| 6917 | .rmdir = nfs_rmdir, |
| 6918 | .mknod = nfs_mknod, |
| 6919 | .rename = nfs_rename, |
| 6920 | .permission = nfs_permission, |
| 6921 | .getattr = nfs_getattr, |
| 6922 | .setattr = nfs_setattr, |
| 6923 | .getxattr = generic_getxattr, |
| 6924 | .setxattr = generic_setxattr, |
| 6925 | .listxattr = generic_listxattr, |
| 6926 | .removexattr = generic_removexattr, |
| 6927 | }; |
| 6928 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6929 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6930 | .permission = nfs_permission, |
| 6931 | .getattr = nfs_getattr, |
| 6932 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6933 | .getxattr = generic_getxattr, |
| 6934 | .setxattr = generic_setxattr, |
| 6935 | .listxattr = generic_listxattr, |
| 6936 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6937 | }; |
| 6938 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6939 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6940 | .version = 4, /* protocol version */ |
| 6941 | .dentry_ops = &nfs4_dentry_operations, |
| 6942 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6943 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6944 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6945 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6946 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6947 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6948 | .getattr = nfs4_proc_getattr, |
| 6949 | .setattr = nfs4_proc_setattr, |
| 6950 | .lookup = nfs4_proc_lookup, |
| 6951 | .access = nfs4_proc_access, |
| 6952 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6953 | .create = nfs4_proc_create, |
| 6954 | .remove = nfs4_proc_remove, |
| 6955 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6956 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6957 | .unlink_done = nfs4_proc_unlink_done, |
| 6958 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6959 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6960 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6961 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6962 | .link = nfs4_proc_link, |
| 6963 | .symlink = nfs4_proc_symlink, |
| 6964 | .mkdir = nfs4_proc_mkdir, |
| 6965 | .rmdir = nfs4_proc_remove, |
| 6966 | .readdir = nfs4_proc_readdir, |
| 6967 | .mknod = nfs4_proc_mknod, |
| 6968 | .statfs = nfs4_proc_statfs, |
| 6969 | .fsinfo = nfs4_proc_fsinfo, |
| 6970 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6971 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6972 | .decode_dirent = nfs4_decode_dirent, |
| 6973 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6974 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6975 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6976 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6977 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6978 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6979 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6980 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6981 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6982 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6983 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6984 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6985 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6986 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6987 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6988 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6989 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6990 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6991 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6992 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6993 | .create_server = nfs4_create_server, |
| 6994 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6995 | }; |
| 6996 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6997 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6998 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6999 | .list = nfs4_xattr_list_nfs4_acl, |
| 7000 | .get = nfs4_xattr_get_nfs4_acl, |
| 7001 | .set = nfs4_xattr_set_nfs4_acl, |
| 7002 | }; |
| 7003 | |
| 7004 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7005 | &nfs4_xattr_nfs4_acl_handler, |
| 7006 | NULL |
| 7007 | }; |
| 7008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7009 | /* |
| 7010 | * Local variables: |
| 7011 | * c-basic-offset: 8 |
| 7012 | * End: |
| 7013 | */ |