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 | 6926afd1 | 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 | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 307 | if (state == NULL) |
| 308 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 309 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 310 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 311 | if (ret < 0) |
| 312 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 313 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 314 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 315 | if (state != NULL) { |
| 316 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 317 | if (ret < 0) |
| 318 | break; |
| 319 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 320 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 321 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 322 | nfs4_schedule_lease_recovery(clp); |
| 323 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 324 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 325 | case -NFS4ERR_BADSESSION: |
| 326 | case -NFS4ERR_BADSLOT: |
| 327 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 328 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 329 | case -NFS4ERR_DEADSESSION: |
| 330 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 331 | case -NFS4ERR_SEQ_MISORDERED: |
| 332 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 333 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 334 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 335 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 336 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 337 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 338 | if (exception->timeout > HZ) { |
| 339 | /* We have retried a decent amount, time to |
| 340 | * fail |
| 341 | */ |
| 342 | ret = -EBUSY; |
| 343 | break; |
| 344 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | case -NFS4ERR_GRACE: |
| 346 | case -NFS4ERR_DELAY: |
| 347 | ret = nfs4_delay(server->client, &exception->timeout); |
| 348 | if (ret != 0) |
| 349 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 350 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 351 | case -NFS4ERR_OLD_STATEID: |
| 352 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 353 | break; |
| 354 | case -NFS4ERR_BADOWNER: |
| 355 | /* The following works around a Linux server bug! */ |
| 356 | case -NFS4ERR_BADNAME: |
| 357 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 358 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 359 | exception->retry = 1; |
| 360 | printk(KERN_WARNING "NFS: v4 server %s " |
| 361 | "does not accept raw " |
| 362 | "uid/gids. " |
| 363 | "Reenabling the idmapper.\n", |
| 364 | server->nfs_client->cl_hostname); |
| 365 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 366 | } |
| 367 | /* We failed to handle the error */ |
| 368 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 369 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 370 | ret = nfs4_wait_clnt_recover(clp); |
| 371 | if (ret == 0) |
| 372 | exception->retry = 1; |
| 373 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 377 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | spin_lock(&clp->cl_lock); |
| 380 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 381 | clp->cl_last_renewal = timestamp; |
| 382 | spin_unlock(&clp->cl_lock); |
| 383 | } |
| 384 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 385 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 386 | { |
| 387 | do_renew_lease(server->nfs_client, timestamp); |
| 388 | } |
| 389 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 390 | #if defined(CONFIG_NFS_V4_1) |
| 391 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 392 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 393 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 394 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 395 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 396 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 397 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 398 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 399 | /* just wake up the next guy waiting since |
| 400 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 401 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 402 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 403 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 404 | tbl = res->sr_slot->table; |
| 405 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 406 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 407 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 408 | /* Be nice to the server: try to ensure that the last transmitted |
| 409 | * value for highest_user_slotid <= target_highest_slotid |
| 410 | */ |
| 411 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 412 | send_new_highest_used_slotid = true; |
| 413 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 414 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 415 | send_new_highest_used_slotid = false; |
| 416 | goto out_unlock; |
| 417 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 418 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 419 | |
| 420 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 421 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 422 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 423 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 424 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 425 | if (send_new_highest_used_slotid) |
| 426 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 429 | 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] | 430 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 431 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 432 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 433 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 434 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 435 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 436 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 437 | /* don't increment the sequence number if the task wasn't sent */ |
| 438 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 439 | goto out; |
| 440 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 441 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 442 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 443 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 444 | if (slot->interrupted) { |
| 445 | slot->interrupted = 0; |
| 446 | interrupted = true; |
| 447 | } |
| 448 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 449 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 450 | switch (res->sr_status) { |
| 451 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 452 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 453 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 454 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 455 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 456 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 457 | if (res->sr_status_flags != 0) |
| 458 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 459 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 461 | case 1: |
| 462 | /* |
| 463 | * sr_status remains 1 if an RPC level error occurred. |
| 464 | * The server may or may not have processed the sequence |
| 465 | * operation.. |
| 466 | * Mark the slot as having hosted an interrupted RPC call. |
| 467 | */ |
| 468 | slot->interrupted = 1; |
| 469 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 470 | case -NFS4ERR_DELAY: |
| 471 | /* The server detected a resend of the RPC call and |
| 472 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 473 | * of RFC5661. |
| 474 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 475 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 476 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 477 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 478 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 479 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 480 | case -NFS4ERR_BADSLOT: |
| 481 | /* |
| 482 | * The slot id we used was probably retired. Try again |
| 483 | * using a different slot id. |
| 484 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 485 | goto retry_nowait; |
| 486 | case -NFS4ERR_SEQ_MISORDERED: |
| 487 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 488 | * Was the last operation on this sequence interrupted? |
| 489 | * If so, retry after bumping the sequence number. |
| 490 | */ |
| 491 | if (interrupted) { |
| 492 | ++slot->seq_nr; |
| 493 | goto retry_nowait; |
| 494 | } |
| 495 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 496 | * Could this slot have been previously retired? |
| 497 | * If so, then the server may be expecting seq_nr = 1! |
| 498 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 499 | if (slot->seq_nr != 1) { |
| 500 | slot->seq_nr = 1; |
| 501 | goto retry_nowait; |
| 502 | } |
| 503 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 504 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 505 | ++slot->seq_nr; |
| 506 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 507 | default: |
| 508 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 509 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 510 | } |
| 511 | out: |
| 512 | /* The session may be reset by one of the error handlers. */ |
| 513 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 514 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 515 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 516 | retry_nowait: |
| 517 | if (rpc_restart_call_prepare(task)) { |
| 518 | task->tk_status = 0; |
| 519 | ret = 0; |
| 520 | } |
| 521 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 522 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 523 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 524 | goto out; |
| 525 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 526 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 527 | } |
| 528 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 529 | static int nfs4_sequence_done(struct rpc_task *task, |
| 530 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 531 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 532 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 533 | return 1; |
| 534 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 535 | } |
| 536 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 537 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 538 | struct nfs4_sequence_res *res, int cache_reply) |
| 539 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 540 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 541 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 542 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 543 | if (cache_reply) |
| 544 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 545 | res->sr_slot = NULL; |
| 546 | } |
| 547 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 548 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 549 | { |
| 550 | args->sa_privileged = 1; |
| 551 | } |
| 552 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 553 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 554 | struct nfs4_sequence_args *args, |
| 555 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 556 | struct rpc_task *task) |
| 557 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 558 | struct nfs4_slot *slot; |
| 559 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 560 | |
| 561 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 562 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 563 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 564 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 565 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 566 | tbl = &session->fc_slot_table; |
| 567 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 568 | task->tk_timeout = 0; |
| 569 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 570 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 571 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 572 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 573 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 574 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 575 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 576 | } |
| 577 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 578 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 579 | if (IS_ERR(slot)) { |
| 580 | /* If out of memory, try again in 1/4 second */ |
| 581 | if (slot == ERR_PTR(-ENOMEM)) |
| 582 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 583 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 584 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 585 | } |
| 586 | spin_unlock(&tbl->slot_tbl_lock); |
| 587 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 588 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 589 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 590 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 591 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 592 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 593 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 594 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 595 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 596 | /* |
| 597 | * sr_status is only set in decode_sequence, and so will remain |
| 598 | * set to 1 if an rpc level failure occurs. |
| 599 | */ |
| 600 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 601 | out_success: |
| 602 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 603 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 604 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 605 | /* Privileged tasks are queued with top priority */ |
| 606 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 607 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 608 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 609 | else |
| 610 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 611 | spin_unlock(&tbl->slot_tbl_lock); |
| 612 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 614 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 616 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | struct nfs4_sequence_args *args, |
| 618 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | struct rpc_task *task) |
| 620 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 621 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 622 | int ret = 0; |
| 623 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 624 | if (session == NULL) { |
| 625 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 626 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 627 | } |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 628 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 629 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 630 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 631 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 632 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 633 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | out: |
| 635 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 640 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 641 | struct nfs4_sequence_args *seq_args; |
| 642 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 646 | { |
| 647 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 648 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 649 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 650 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 651 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 652 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | } |
| 654 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 655 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 656 | { |
| 657 | struct nfs41_call_sync_data *data = calldata; |
| 658 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 659 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 660 | } |
| 661 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 662 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 664 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 665 | }; |
| 666 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 667 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 668 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | struct rpc_message *msg, |
| 670 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 671 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 672 | { |
| 673 | int ret; |
| 674 | struct rpc_task *task; |
| 675 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 676 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | .seq_args = args, |
| 678 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 679 | }; |
| 680 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 681 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | .rpc_message = msg, |
| 683 | .callback_ops = &nfs41_call_sync_ops, |
| 684 | .callback_data = &data |
| 685 | }; |
| 686 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 687 | task = rpc_run_task(&task_setup); |
| 688 | if (IS_ERR(task)) |
| 689 | ret = PTR_ERR(task); |
| 690 | else { |
| 691 | ret = task->tk_status; |
| 692 | rpc_put_task(task); |
| 693 | } |
| 694 | return ret; |
| 695 | } |
| 696 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 697 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 698 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 699 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 700 | struct nfs4_sequence_res *res, int cache_reply) |
| 701 | { |
| 702 | } |
| 703 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 704 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 705 | { |
| 706 | } |
| 707 | |
| 708 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 709 | static int nfs4_sequence_done(struct rpc_task *task, |
| 710 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 711 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 712 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 713 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 714 | #endif /* CONFIG_NFS_V4_1 */ |
| 715 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 716 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 717 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 718 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 719 | struct rpc_message *msg, |
| 720 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 721 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 722 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 723 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 724 | } |
| 725 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 726 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 727 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 728 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 729 | struct rpc_message *msg, |
| 730 | struct nfs4_sequence_args *args, |
| 731 | struct nfs4_sequence_res *res, |
| 732 | int cache_reply) |
| 733 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 734 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 735 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 736 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 737 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 738 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 739 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 741 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 743 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 744 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 745 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 746 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 747 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 748 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 749 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 752 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 753 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 754 | struct nfs_openargs o_arg; |
| 755 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 756 | struct nfs_open_confirmargs c_arg; |
| 757 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 758 | struct nfs4_string owner_name; |
| 759 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 760 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 762 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 764 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 766 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 767 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 768 | int rpc_status; |
| 769 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | }; |
| 771 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 772 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 773 | int err, struct nfs4_exception *exception) |
| 774 | { |
| 775 | if (err != -EINVAL) |
| 776 | return false; |
| 777 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 778 | return false; |
| 779 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 780 | exception->retry = 1; |
| 781 | return true; |
| 782 | } |
| 783 | |
| 784 | static enum open_claim_type4 |
| 785 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 786 | enum open_claim_type4 claim) |
| 787 | { |
| 788 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 789 | return claim; |
| 790 | switch (claim) { |
| 791 | default: |
| 792 | return claim; |
| 793 | case NFS4_OPEN_CLAIM_FH: |
| 794 | return NFS4_OPEN_CLAIM_NULL; |
| 795 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 796 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 797 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 798 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 799 | } |
| 800 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 801 | |
| 802 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 803 | { |
| 804 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 805 | p->o_res.seqid = p->o_arg.seqid; |
| 806 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 807 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 808 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 809 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 810 | 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] | 811 | } |
| 812 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 813 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 814 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 815 | const struct iattr *attrs, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 816 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 817 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 819 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | struct inode *dir = parent->d_inode; |
| 821 | struct nfs_server *server = NFS_SERVER(dir); |
| 822 | struct nfs4_opendata *p; |
| 823 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 824 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | if (p == NULL) |
| 826 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 827 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | if (p->o_arg.seqid == NULL) |
| 829 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 830 | nfs_sb_active(dentry->d_sb); |
| 831 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | p->dir = parent; |
| 833 | p->owner = sp; |
| 834 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 835 | p->o_arg.open_flags = flags; |
| 836 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 837 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 838 | * will return permission denied for all bits until close */ |
| 839 | if (!(flags & O_EXCL)) { |
| 840 | /* ask server to check for all possible rights as results |
| 841 | * are cached */ |
| 842 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 843 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 844 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 845 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 846 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 847 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 848 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 849 | p->o_arg.server = server; |
| 850 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 851 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 852 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 853 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 854 | case NFS4_OPEN_CLAIM_NULL: |
| 855 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 856 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 857 | p->o_arg.fh = NFS_FH(dir); |
| 858 | break; |
| 859 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 860 | case NFS4_OPEN_CLAIM_FH: |
| 861 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 862 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 863 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 864 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 865 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 866 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 867 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 868 | p->o_arg.u.attrs = &p->attrs; |
| 869 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 870 | |
| 871 | verf[0] = jiffies; |
| 872 | verf[1] = current->pid; |
| 873 | memcpy(p->o_arg.u.verifier.data, verf, |
| 874 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 875 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 876 | p->c_arg.fh = &p->o_res.fh; |
| 877 | p->c_arg.stateid = &p->o_res.stateid; |
| 878 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 879 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 880 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 881 | return p; |
| 882 | err_free: |
| 883 | kfree(p); |
| 884 | err: |
| 885 | dput(parent); |
| 886 | return NULL; |
| 887 | } |
| 888 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 889 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 890 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 891 | struct nfs4_opendata *p = container_of(kref, |
| 892 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 893 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 894 | |
| 895 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 896 | if (p->state != NULL) |
| 897 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 898 | nfs4_put_state_owner(p->owner); |
| 899 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 900 | dput(p->dentry); |
| 901 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 902 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 903 | kfree(p); |
| 904 | } |
| 905 | |
| 906 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 907 | { |
| 908 | if (p != NULL) |
| 909 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 910 | } |
| 911 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 912 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 913 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 914 | int ret; |
| 915 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 916 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 917 | return ret; |
| 918 | } |
| 919 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | 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] | 921 | { |
| 922 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 923 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 924 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 925 | goto out; |
| 926 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 927 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 928 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 929 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 930 | break; |
| 931 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 932 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 933 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 934 | break; |
| 935 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 936 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 937 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 938 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 939 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 940 | return ret; |
| 941 | } |
| 942 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 943 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 944 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 945 | if (delegation == NULL) |
| 946 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 948 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 949 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 950 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 951 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 952 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 953 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 954 | return 1; |
| 955 | } |
| 956 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 957 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 958 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 960 | case FMODE_WRITE: |
| 961 | state->n_wronly++; |
| 962 | break; |
| 963 | case FMODE_READ: |
| 964 | state->n_rdonly++; |
| 965 | break; |
| 966 | case FMODE_READ|FMODE_WRITE: |
| 967 | state->n_rdwr++; |
| 968 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 970 | } |
| 971 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 972 | 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] | 973 | { |
| 974 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 975 | nfs4_stateid_copy(&state->stateid, stateid); |
| 976 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 977 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 978 | case FMODE_READ: |
| 979 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 980 | break; |
| 981 | case FMODE_WRITE: |
| 982 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 983 | break; |
| 984 | case FMODE_READ|FMODE_WRITE: |
| 985 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 986 | } |
| 987 | } |
| 988 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | 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] | 990 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 991 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 992 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 993 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 994 | } |
| 995 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | 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] | 997 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 998 | /* |
| 999 | * Protect the call to nfs4_state_set_mode_locked and |
| 1000 | * serialise the stateid update |
| 1001 | */ |
| 1002 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1003 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1004 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1005 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1006 | } |
| 1007 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1008 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1009 | write_sequnlock(&state->seqlock); |
| 1010 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1011 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1012 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1015 | 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] | 1016 | { |
| 1017 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1018 | struct nfs_delegation *deleg_cur; |
| 1019 | int ret = 0; |
| 1020 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1021 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1022 | |
| 1023 | rcu_read_lock(); |
| 1024 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1025 | if (deleg_cur == NULL) |
| 1026 | goto no_delegation; |
| 1027 | |
| 1028 | spin_lock(&deleg_cur->lock); |
| 1029 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1030 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1032 | goto no_delegation_unlock; |
| 1033 | |
| 1034 | if (delegation == NULL) |
| 1035 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1036 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1037 | goto no_delegation_unlock; |
| 1038 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1039 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1041 | ret = 1; |
| 1042 | no_delegation_unlock: |
| 1043 | spin_unlock(&deleg_cur->lock); |
| 1044 | no_delegation: |
| 1045 | rcu_read_unlock(); |
| 1046 | |
| 1047 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1048 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1049 | ret = 1; |
| 1050 | } |
| 1051 | |
| 1052 | return ret; |
| 1053 | } |
| 1054 | |
| 1055 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1057 | { |
| 1058 | struct nfs_delegation *delegation; |
| 1059 | |
| 1060 | rcu_read_lock(); |
| 1061 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1062 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1063 | rcu_read_unlock(); |
| 1064 | return; |
| 1065 | } |
| 1066 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1067 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1070 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1071 | { |
| 1072 | struct nfs4_state *state = opendata->state; |
| 1073 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1074 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1075 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1076 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1077 | nfs4_stateid stateid; |
| 1078 | int ret = -EAGAIN; |
| 1079 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1080 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1081 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1082 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1083 | if (can_open_cached(state, fmode, open_mode)) { |
| 1084 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1085 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1086 | goto out_return_state; |
| 1087 | } |
| 1088 | spin_unlock(&state->owner->so_lock); |
| 1089 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1090 | rcu_read_lock(); |
| 1091 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1092 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1093 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1094 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1095 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1096 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1097 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1098 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1099 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1100 | if (ret != 0) |
| 1101 | goto out; |
| 1102 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1103 | |
| 1104 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1105 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1106 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1107 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1108 | out: |
| 1109 | return ERR_PTR(ret); |
| 1110 | out_return_state: |
| 1111 | atomic_inc(&state->count); |
| 1112 | return state; |
| 1113 | } |
| 1114 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1115 | static void |
| 1116 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1117 | { |
| 1118 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1119 | struct nfs_delegation *delegation; |
| 1120 | int delegation_flags = 0; |
| 1121 | |
| 1122 | rcu_read_lock(); |
| 1123 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1124 | if (delegation) |
| 1125 | delegation_flags = delegation->flags; |
| 1126 | rcu_read_unlock(); |
| 1127 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1128 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1129 | "returning a delegation for " |
| 1130 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1131 | clp->cl_hostname); |
| 1132 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1133 | nfs_inode_set_delegation(state->inode, |
| 1134 | data->owner->so_cred, |
| 1135 | &data->o_res); |
| 1136 | else |
| 1137 | nfs_inode_reclaim_delegation(state->inode, |
| 1138 | data->owner->so_cred, |
| 1139 | &data->o_res); |
| 1140 | } |
| 1141 | |
| 1142 | /* |
| 1143 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1144 | * and update the nfs4_state. |
| 1145 | */ |
| 1146 | static struct nfs4_state * |
| 1147 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1148 | { |
| 1149 | struct inode *inode = data->state->inode; |
| 1150 | struct nfs4_state *state = data->state; |
| 1151 | int ret; |
| 1152 | |
| 1153 | if (!data->rpc_done) { |
| 1154 | ret = data->rpc_status; |
| 1155 | goto err; |
| 1156 | } |
| 1157 | |
| 1158 | ret = -ESTALE; |
| 1159 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1160 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1161 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1162 | goto err; |
| 1163 | |
| 1164 | ret = -ENOMEM; |
| 1165 | state = nfs4_get_open_state(inode, data->owner); |
| 1166 | if (state == NULL) |
| 1167 | goto err; |
| 1168 | |
| 1169 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1170 | if (ret) |
| 1171 | goto err; |
| 1172 | |
| 1173 | if (data->o_res.delegation_type != 0) |
| 1174 | nfs4_opendata_check_deleg(data, state); |
| 1175 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1176 | data->o_arg.fmode); |
| 1177 | |
| 1178 | return state; |
| 1179 | err: |
| 1180 | return ERR_PTR(ret); |
| 1181 | |
| 1182 | } |
| 1183 | |
| 1184 | static struct nfs4_state * |
| 1185 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1186 | { |
| 1187 | struct inode *inode; |
| 1188 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1189 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1190 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1191 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1192 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1193 | goto out; |
| 1194 | } |
| 1195 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1196 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1197 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1198 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1199 | 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] | 1200 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1201 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1202 | goto err; |
| 1203 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1204 | state = nfs4_get_open_state(inode, data->owner); |
| 1205 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1206 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1207 | if (data->o_res.delegation_type != 0) |
| 1208 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1209 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1210 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1211 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1212 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1213 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1214 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1215 | err_put_inode: |
| 1216 | iput(inode); |
| 1217 | err: |
| 1218 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1221 | static struct nfs4_state * |
| 1222 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1223 | { |
| 1224 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1225 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1226 | return _nfs4_opendata_to_nfs4_state(data); |
| 1227 | } |
| 1228 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1230 | { |
| 1231 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1232 | struct nfs_open_context *ctx; |
| 1233 | |
| 1234 | spin_lock(&state->inode->i_lock); |
| 1235 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1236 | if (ctx->state != state) |
| 1237 | continue; |
| 1238 | get_nfs_open_context(ctx); |
| 1239 | spin_unlock(&state->inode->i_lock); |
| 1240 | return ctx; |
| 1241 | } |
| 1242 | spin_unlock(&state->inode->i_lock); |
| 1243 | return ERR_PTR(-ENOENT); |
| 1244 | } |
| 1245 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1246 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1247 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1248 | { |
| 1249 | struct nfs4_opendata *opendata; |
| 1250 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1251 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
| 1252 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1253 | if (opendata == NULL) |
| 1254 | return ERR_PTR(-ENOMEM); |
| 1255 | opendata->state = state; |
| 1256 | atomic_inc(&state->count); |
| 1257 | return opendata; |
| 1258 | } |
| 1259 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1260 | 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] | 1261 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1262 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1263 | int ret; |
| 1264 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1265 | opendata->o_arg.open_flags = 0; |
| 1266 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1267 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1268 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1269 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1270 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1271 | if (ret != 0) |
| 1272 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1273 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1274 | if (IS_ERR(newstate)) |
| 1275 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1276 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1277 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1282 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1283 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1284 | int ret; |
| 1285 | |
| 1286 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1287 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1288 | smp_rmb(); |
| 1289 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1290 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1291 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1292 | if (ret != 0) |
| 1293 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1294 | if (newstate != state) |
| 1295 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1296 | } |
| 1297 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1298 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1299 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1300 | if (ret != 0) |
| 1301 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1302 | if (newstate != state) |
| 1303 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1304 | } |
| 1305 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1306 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1307 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1308 | if (ret != 0) |
| 1309 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1310 | if (newstate != state) |
| 1311 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1312 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1313 | /* |
| 1314 | * We may have performed cached opens for all three recoveries. |
| 1315 | * Check if we need to update the current stateid. |
| 1316 | */ |
| 1317 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1318 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1319 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1320 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1321 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1322 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1323 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | /* |
| 1328 | * OPEN_RECLAIM: |
| 1329 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1331 | 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] | 1332 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1333 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1334 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1335 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | int status; |
| 1337 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1338 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1339 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1340 | if (IS_ERR(opendata)) |
| 1341 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1342 | rcu_read_lock(); |
| 1343 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1344 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1345 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1346 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1347 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1348 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1349 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | return status; |
| 1351 | } |
| 1352 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1353 | 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] | 1354 | { |
| 1355 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1356 | struct nfs4_exception exception = { }; |
| 1357 | int err; |
| 1358 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1359 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1360 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1361 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1362 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1363 | break; |
| 1364 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | } while (exception.retry); |
| 1366 | return err; |
| 1367 | } |
| 1368 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1369 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1370 | { |
| 1371 | struct nfs_open_context *ctx; |
| 1372 | int ret; |
| 1373 | |
| 1374 | ctx = nfs4_state_find_open_context(state); |
| 1375 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1376 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1377 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1378 | put_nfs_open_context(ctx); |
| 1379 | return ret; |
| 1380 | } |
| 1381 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1382 | static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1384 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1385 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1387 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | ccb46e2 | 2013-03-18 12:50:59 -0400 | [diff] [blame] | 1388 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1389 | if (IS_ERR(opendata)) |
| 1390 | return PTR_ERR(opendata); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1391 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1392 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1393 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1394 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1397 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | { |
| 1399 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1400 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | int err; |
| 1402 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1403 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | switch (err) { |
| 1405 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1406 | case -ENOENT: |
| 1407 | case -ESTALE: |
| 1408 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1409 | case -NFS4ERR_BADSESSION: |
| 1410 | case -NFS4ERR_BADSLOT: |
| 1411 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1412 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1413 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1414 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1415 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1416 | err = -EAGAIN; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1417 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | case -NFS4ERR_STALE_CLIENTID: |
| 1419 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1420 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | case -NFS4ERR_EXPIRED: |
| 1422 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1423 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1424 | err = -EAGAIN; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1425 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1426 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1427 | case -NFS4ERR_ADMIN_REVOKED: |
| 1428 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1429 | nfs_inode_find_state_and_recover(state->inode, |
| 1430 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1431 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1432 | case -ENOMEM: |
| 1433 | err = 0; |
| 1434 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1436 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | err = nfs4_handle_exception(server, err, &exception); |
| 1438 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1439 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | return err; |
| 1441 | } |
| 1442 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1443 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1444 | { |
| 1445 | struct nfs4_opendata *data = calldata; |
| 1446 | |
| 1447 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1448 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1449 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1450 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1451 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1452 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1453 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | static void nfs4_open_confirm_release(void *calldata) |
| 1457 | { |
| 1458 | struct nfs4_opendata *data = calldata; |
| 1459 | struct nfs4_state *state = NULL; |
| 1460 | |
| 1461 | /* If this request hasn't been cancelled, do nothing */ |
| 1462 | if (data->cancelled == 0) |
| 1463 | goto out_free; |
| 1464 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1465 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1466 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1467 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1468 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1469 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1470 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1471 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1475 | .rpc_call_done = nfs4_open_confirm_done, |
| 1476 | .rpc_release = nfs4_open_confirm_release, |
| 1477 | }; |
| 1478 | |
| 1479 | /* |
| 1480 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1481 | */ |
| 1482 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1483 | { |
| 1484 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1485 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1486 | struct rpc_message msg = { |
| 1487 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1488 | .rpc_argp = &data->c_arg, |
| 1489 | .rpc_resp = &data->c_res, |
| 1490 | .rpc_cred = data->owner->so_cred, |
| 1491 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1492 | struct rpc_task_setup task_setup_data = { |
| 1493 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1494 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1495 | .callback_ops = &nfs4_open_confirm_ops, |
| 1496 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1497 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1498 | .flags = RPC_TASK_ASYNC, |
| 1499 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | int status; |
| 1501 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1502 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1503 | data->rpc_done = 0; |
| 1504 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1505 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1506 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1507 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1508 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1509 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1510 | if (status != 0) { |
| 1511 | data->cancelled = 1; |
| 1512 | smp_wmb(); |
| 1513 | } else |
| 1514 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1515 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | return status; |
| 1517 | } |
| 1518 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1519 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1521 | struct nfs4_opendata *data = calldata; |
| 1522 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1523 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1524 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1525 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1526 | /* |
| 1527 | * Check if we still need to send an OPEN call, or if we can use |
| 1528 | * a delegation instead. |
| 1529 | */ |
| 1530 | if (data->state != NULL) { |
| 1531 | struct nfs_delegation *delegation; |
| 1532 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1533 | 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] | 1534 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1535 | rcu_read_lock(); |
| 1536 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1537 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1538 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1539 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1540 | rcu_read_unlock(); |
| 1541 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1542 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1543 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1544 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1545 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1546 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1547 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1548 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1549 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1550 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1551 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1552 | &data->o_res.seq_res, |
| 1553 | task) != 0) |
| 1554 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1555 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1556 | unlock_no_action: |
| 1557 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1558 | out_no_action: |
| 1559 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1560 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1561 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1562 | } |
| 1563 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1564 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1565 | { |
| 1566 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1568 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1569 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1570 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1571 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1572 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1573 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1574 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1575 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1576 | case S_IFREG: |
| 1577 | break; |
| 1578 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1579 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1580 | break; |
| 1581 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1582 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1583 | break; |
| 1584 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1585 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1586 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1587 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1588 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1589 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1590 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1591 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1592 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1593 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1594 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1595 | static void nfs4_open_release(void *calldata) |
| 1596 | { |
| 1597 | struct nfs4_opendata *data = calldata; |
| 1598 | struct nfs4_state *state = NULL; |
| 1599 | |
| 1600 | /* If this request hasn't been cancelled, do nothing */ |
| 1601 | if (data->cancelled == 0) |
| 1602 | goto out_free; |
| 1603 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1604 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1605 | goto out_free; |
| 1606 | /* In case we need an open_confirm, no cleanup! */ |
| 1607 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1608 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1609 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1610 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1611 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1612 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1613 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1617 | .rpc_call_prepare = nfs4_open_prepare, |
| 1618 | .rpc_call_done = nfs4_open_done, |
| 1619 | .rpc_release = nfs4_open_release, |
| 1620 | }; |
| 1621 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1622 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1623 | { |
| 1624 | struct inode *dir = data->dir->d_inode; |
| 1625 | struct nfs_server *server = NFS_SERVER(dir); |
| 1626 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1627 | struct nfs_openres *o_res = &data->o_res; |
| 1628 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1629 | struct rpc_message msg = { |
| 1630 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1631 | .rpc_argp = o_arg, |
| 1632 | .rpc_resp = o_res, |
| 1633 | .rpc_cred = data->owner->so_cred, |
| 1634 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1635 | struct rpc_task_setup task_setup_data = { |
| 1636 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1637 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1638 | .callback_ops = &nfs4_open_ops, |
| 1639 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1640 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1641 | .flags = RPC_TASK_ASYNC, |
| 1642 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1643 | int status; |
| 1644 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1645 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1646 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1647 | data->rpc_done = 0; |
| 1648 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1649 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1650 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1651 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1652 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1653 | if (IS_ERR(task)) |
| 1654 | return PTR_ERR(task); |
| 1655 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1656 | if (status != 0) { |
| 1657 | data->cancelled = 1; |
| 1658 | smp_wmb(); |
| 1659 | } else |
| 1660 | status = data->rpc_status; |
| 1661 | rpc_put_task(task); |
| 1662 | |
| 1663 | return status; |
| 1664 | } |
| 1665 | |
| 1666 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1667 | { |
| 1668 | struct inode *dir = data->dir->d_inode; |
| 1669 | struct nfs_openres *o_res = &data->o_res; |
| 1670 | int status; |
| 1671 | |
| 1672 | status = nfs4_run_open_task(data, 1); |
| 1673 | if (status != 0 || !data->rpc_done) |
| 1674 | return status; |
| 1675 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1676 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1677 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1678 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1679 | status = _nfs4_proc_open_confirm(data); |
| 1680 | if (status != 0) |
| 1681 | return status; |
| 1682 | } |
| 1683 | |
| 1684 | return status; |
| 1685 | } |
| 1686 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1687 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1688 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1689 | struct nfs4_state *state, fmode_t fmode, |
| 1690 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1691 | { |
| 1692 | struct nfs_access_entry cache; |
| 1693 | u32 mask; |
| 1694 | |
| 1695 | /* access call failed or for some reason the server doesn't |
| 1696 | * support any access modes -- defer access call until later */ |
| 1697 | if (opendata->o_res.access_supported == 0) |
| 1698 | return 0; |
| 1699 | |
| 1700 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1701 | /* 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] | 1702 | * write mode bits, but POSIX allows the creating process to write. |
| 1703 | * use openflags to check for exec, because fmode won't |
| 1704 | * always have FMODE_EXEC set when file open for exec. */ |
| 1705 | if (openflags & __FMODE_EXEC) { |
| 1706 | /* ONLY check for exec rights */ |
| 1707 | mask = MAY_EXEC; |
| 1708 | } else if (fmode & FMODE_READ) |
| 1709 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1710 | |
| 1711 | cache.cred = cred; |
| 1712 | cache.jiffies = jiffies; |
| 1713 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1714 | nfs_access_add_cache(state->inode, &cache); |
| 1715 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1716 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1717 | return 0; |
| 1718 | |
| 1719 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1720 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1721 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1724 | /* |
| 1725 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1726 | */ |
| 1727 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1728 | { |
| 1729 | struct inode *dir = data->dir->d_inode; |
| 1730 | struct nfs_server *server = NFS_SERVER(dir); |
| 1731 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1732 | struct nfs_openres *o_res = &data->o_res; |
| 1733 | int status; |
| 1734 | |
| 1735 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1736 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1737 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1738 | if (status != 0) { |
| 1739 | if (status == -NFS4ERR_BADNAME && |
| 1740 | !(o_arg->open_flags & O_CREAT)) |
| 1741 | return -ENOENT; |
| 1742 | return status; |
| 1743 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1744 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1745 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1746 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1747 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1748 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1749 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1750 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1752 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1754 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | } |
| 1756 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1757 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1758 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1761 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1762 | { |
| 1763 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1764 | } |
| 1765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | /* |
| 1767 | * OPEN_EXPIRED: |
| 1768 | * reclaim state on the server after a network partition. |
| 1769 | * Assumes caller holds the appropriate lock |
| 1770 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1771 | 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] | 1772 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1773 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1774 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1776 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1777 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1778 | if (IS_ERR(opendata)) |
| 1779 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1781 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1782 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1783 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1784 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1787 | 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] | 1788 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1789 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1790 | struct nfs4_exception exception = { }; |
| 1791 | int err; |
| 1792 | |
| 1793 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1794 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1795 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1796 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1797 | switch (err) { |
| 1798 | default: |
| 1799 | goto out; |
| 1800 | case -NFS4ERR_GRACE: |
| 1801 | case -NFS4ERR_DELAY: |
| 1802 | nfs4_handle_exception(server, err, &exception); |
| 1803 | err = 0; |
| 1804 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1805 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1806 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1807 | return err; |
| 1808 | } |
| 1809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1811 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1813 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1815 | ctx = nfs4_state_find_open_context(state); |
| 1816 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1817 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1818 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1819 | put_nfs_open_context(ctx); |
| 1820 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1823 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1824 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1825 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1826 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1827 | nfs4_stateid *stateid = &state->stateid; |
| 1828 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1829 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1830 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1831 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1832 | return; |
| 1833 | |
| 1834 | status = nfs41_test_stateid(server, stateid); |
| 1835 | if (status != NFS_OK) { |
| 1836 | /* Free the stateid unless the server explicitly |
| 1837 | * informs us the stateid is unrecognized. */ |
| 1838 | if (status != -NFS4ERR_BAD_STATEID) |
| 1839 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1840 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1841 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1842 | write_seqlock(&state->seqlock); |
| 1843 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1844 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1845 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | /** |
| 1850 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1851 | * |
| 1852 | * @state: NFSv4 state for an inode |
| 1853 | * |
| 1854 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1855 | * Otherwise a negative NFS4ERR value is returned. |
| 1856 | */ |
| 1857 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1858 | { |
| 1859 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1860 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1861 | int status; |
| 1862 | |
| 1863 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1864 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1865 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1866 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1867 | return -NFS4ERR_BAD_STATEID; |
| 1868 | |
| 1869 | status = nfs41_test_stateid(server, stateid); |
| 1870 | if (status != NFS_OK) { |
| 1871 | /* Free the stateid unless the server explicitly |
| 1872 | * informs us the stateid is unrecognized. */ |
| 1873 | if (status != -NFS4ERR_BAD_STATEID) |
| 1874 | nfs41_free_stateid(server, stateid); |
| 1875 | |
| 1876 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1877 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1878 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1879 | } |
| 1880 | return status; |
| 1881 | } |
| 1882 | |
| 1883 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1884 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1885 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1886 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1887 | nfs41_clear_delegation_stateid(state); |
| 1888 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1889 | if (status != NFS_OK) |
| 1890 | status = nfs4_open_expired(sp, state); |
| 1891 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1892 | } |
| 1893 | #endif |
| 1894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1896 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1897 | * fields corresponding to attributes that were used to store the verifier. |
| 1898 | * Make sure we clobber those fields in the later setattr call |
| 1899 | */ |
| 1900 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1901 | { |
| 1902 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1903 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1904 | sattr->ia_valid |= ATTR_ATIME; |
| 1905 | |
| 1906 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1907 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1908 | sattr->ia_valid |= ATTR_MTIME; |
| 1909 | } |
| 1910 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1911 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1912 | fmode_t fmode, |
| 1913 | int flags, |
| 1914 | struct nfs4_state **res) |
| 1915 | { |
| 1916 | struct nfs4_state_owner *sp = opendata->owner; |
| 1917 | struct nfs_server *server = sp->so_server; |
| 1918 | struct nfs4_state *state; |
| 1919 | unsigned int seq; |
| 1920 | int ret; |
| 1921 | |
| 1922 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1923 | |
| 1924 | ret = _nfs4_proc_open(opendata); |
| 1925 | if (ret != 0) |
| 1926 | goto out; |
| 1927 | |
| 1928 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1929 | ret = PTR_ERR(state); |
| 1930 | if (IS_ERR(state)) |
| 1931 | goto out; |
| 1932 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1933 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1934 | |
| 1935 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 1936 | if (ret != 0) |
| 1937 | goto out; |
| 1938 | |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1939 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1940 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1941 | *res = state; |
| 1942 | out: |
| 1943 | return ret; |
| 1944 | } |
| 1945 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1946 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1947 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1949 | static int _nfs4_do_open(struct inode *dir, |
| 1950 | struct dentry *dentry, |
| 1951 | fmode_t fmode, |
| 1952 | int flags, |
| 1953 | struct iattr *sattr, |
| 1954 | struct rpc_cred *cred, |
| 1955 | struct nfs4_state **res, |
| 1956 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | { |
| 1958 | struct nfs4_state_owner *sp; |
| 1959 | struct nfs4_state *state = NULL; |
| 1960 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1961 | struct nfs4_opendata *opendata; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1962 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1963 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | |
| 1965 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1967 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1968 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1970 | goto out_err; |
| 1971 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1972 | status = nfs4_recover_expired_lease(server); |
| 1973 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1974 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1975 | if (dentry->d_inode != NULL) |
| 1976 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1977 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1978 | if (dentry->d_inode) |
| 1979 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1980 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1981 | claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1982 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1983 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1985 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1986 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1987 | if (!opendata->f_attr.mdsthreshold) |
| 1988 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1989 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1990 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1991 | if (dentry->d_inode != NULL) |
| 1992 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1993 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1994 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1995 | if (status != 0) |
| 1996 | goto err_opendata_put; |
| 1997 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1998 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1999 | nfs4_exclusive_attrset(opendata, sattr); |
| 2000 | |
| 2001 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2002 | status = nfs4_do_setattr(state->inode, cred, |
| 2003 | opendata->o_res.f_attr, sattr, |
| 2004 | state); |
| 2005 | if (status == 0) |
| 2006 | nfs_setattr_update_inode(state->inode, sattr); |
| 2007 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2008 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2009 | |
| 2010 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2011 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2012 | else |
| 2013 | kfree(opendata->f_attr.mdsthreshold); |
| 2014 | opendata->f_attr.mdsthreshold = NULL; |
| 2015 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2016 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | *res = state; |
| 2019 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2020 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2021 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2022 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2023 | err_put_state_owner: |
| 2024 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | *res = NULL; |
| 2027 | return status; |
| 2028 | } |
| 2029 | |
| 2030 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2031 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2032 | struct dentry *dentry, |
| 2033 | fmode_t fmode, |
| 2034 | int flags, |
| 2035 | struct iattr *sattr, |
| 2036 | struct rpc_cred *cred, |
| 2037 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2039 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | struct nfs4_exception exception = { }; |
| 2041 | struct nfs4_state *res; |
| 2042 | int status; |
| 2043 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2044 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2046 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2047 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | if (status == 0) |
| 2049 | break; |
| 2050 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2051 | * book-keeping w.r.t. state-changing operations |
| 2052 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2053 | * It is actually a sign of a bug on the client or on the server. |
| 2054 | * |
| 2055 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2056 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | * have unhashed the old state_owner for us, and that we can |
| 2058 | * therefore safely retry using a new one. We should still warn |
| 2059 | * the user though... |
| 2060 | */ |
| 2061 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2062 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2063 | " returned a bad sequence-id error!\n", |
| 2064 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | exception.retry = 1; |
| 2066 | continue; |
| 2067 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2068 | /* |
| 2069 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2070 | * state before it received the OPEN_CONFIRM. |
| 2071 | * Recover by retrying the request as per the discussion |
| 2072 | * on Page 181 of RFC3530. |
| 2073 | */ |
| 2074 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2075 | exception.retry = 1; |
| 2076 | continue; |
| 2077 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2078 | if (status == -EAGAIN) { |
| 2079 | /* We must have found a delegation */ |
| 2080 | exception.retry = 1; |
| 2081 | continue; |
| 2082 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2083 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2084 | continue; |
| 2085 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | status, &exception)); |
| 2087 | } while (exception.retry); |
| 2088 | return res; |
| 2089 | } |
| 2090 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2091 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2092 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2093 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2095 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2097 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | .iap = sattr, |
| 2099 | .server = server, |
| 2100 | .bitmask = server->attr_bitmask, |
| 2101 | }; |
| 2102 | struct nfs_setattrres res = { |
| 2103 | .fattr = fattr, |
| 2104 | .server = server, |
| 2105 | }; |
| 2106 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2107 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2108 | .rpc_argp = &arg, |
| 2109 | .rpc_resp = &res, |
| 2110 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2112 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2113 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2115 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2117 | if (state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2118 | struct nfs_lockowner lockowner = { |
| 2119 | .l_owner = current->files, |
| 2120 | .l_pid = current->tgid, |
| 2121 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2122 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2123 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2124 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2125 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2126 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2127 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2128 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2130 | 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] | 2131 | if (status == 0 && state != NULL) |
| 2132 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2133 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2136 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2137 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2138 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2140 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2141 | struct nfs4_exception exception = { |
| 2142 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2143 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2144 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | int err; |
| 2146 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2147 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2148 | switch (err) { |
| 2149 | case -NFS4ERR_OPENMODE: |
| 2150 | if (state && !(state->state & FMODE_WRITE)) { |
| 2151 | err = -EBADF; |
| 2152 | if (sattr->ia_valid & ATTR_OPEN) |
| 2153 | err = -EACCES; |
| 2154 | goto out; |
| 2155 | } |
| 2156 | } |
| 2157 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2159 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | return err; |
| 2161 | } |
| 2162 | |
| 2163 | struct nfs4_closedata { |
| 2164 | struct inode *inode; |
| 2165 | struct nfs4_state *state; |
| 2166 | struct nfs_closeargs arg; |
| 2167 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2168 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2169 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2170 | bool roc; |
| 2171 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | }; |
| 2173 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2174 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2175 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2176 | struct nfs4_closedata *calldata = data; |
| 2177 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2178 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2179 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2180 | if (calldata->roc) |
| 2181 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2182 | nfs4_put_open_state(calldata->state); |
| 2183 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2184 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2185 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2186 | kfree(calldata); |
| 2187 | } |
| 2188 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2189 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2190 | fmode_t fmode) |
| 2191 | { |
| 2192 | spin_lock(&state->owner->so_lock); |
| 2193 | if (!(fmode & FMODE_READ)) |
| 2194 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2195 | if (!(fmode & FMODE_WRITE)) |
| 2196 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2197 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2198 | spin_unlock(&state->owner->so_lock); |
| 2199 | } |
| 2200 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2201 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2203 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2206 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2207 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2208 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2209 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | /* hmm. we are done with the inode, and in the process of freeing |
| 2211 | * the state_owner. we keep this around to process errors |
| 2212 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | switch (task->tk_status) { |
| 2214 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2215 | if (calldata->roc) |
| 2216 | pnfs_roc_set_barrier(state->inode, |
| 2217 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2218 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2219 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2220 | nfs4_close_clear_stateid_flags(state, |
| 2221 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | break; |
| 2223 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2224 | case -NFS4ERR_OLD_STATEID: |
| 2225 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2227 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2228 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2230 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2231 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2233 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2234 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2235 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2238 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2240 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2241 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2242 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2243 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2244 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2245 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2246 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2247 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2248 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2249 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2250 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2251 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2252 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2253 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2254 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2255 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2256 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2257 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2258 | } |
| 2259 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2260 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2261 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2262 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2263 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2264 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2265 | if (!nfs4_valid_open_stateid(state)) |
| 2266 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2267 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2268 | |
| 2269 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2270 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2271 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2272 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2273 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2274 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2275 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2276 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2277 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2278 | goto out_wait; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2279 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2280 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2281 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2282 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2283 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2284 | &calldata->arg.seq_args, |
| 2285 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2286 | task) != 0) |
| 2287 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2288 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2289 | return; |
| 2290 | out_no_action: |
| 2291 | task->tk_action = NULL; |
| 2292 | out_wait: |
| 2293 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2296 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2297 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2298 | .rpc_call_done = nfs4_close_done, |
| 2299 | .rpc_release = nfs4_free_closedata, |
| 2300 | }; |
| 2301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | /* |
| 2303 | * It is possible for data to be read/written from a mem-mapped file |
| 2304 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2305 | * This means that we can't safely call nfsv4 close on a file until |
| 2306 | * the inode is cleared. This in turn means that we are not good |
| 2307 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2308 | * share state even when we are done with one of the three share |
| 2309 | * stateid's in the inode. |
| 2310 | * |
| 2311 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2312 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2313 | 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] | 2314 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2315 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2317 | struct nfs4_state_owner *sp = state->owner; |
| 2318 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2319 | struct rpc_message msg = { |
| 2320 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2321 | .rpc_cred = state->owner->so_cred, |
| 2322 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2323 | struct rpc_task_setup task_setup_data = { |
| 2324 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2325 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2326 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2327 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2328 | .flags = RPC_TASK_ASYNC, |
| 2329 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2330 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2332 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2334 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2335 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2336 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2338 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2339 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2341 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2342 | if (calldata->arg.seqid == NULL) |
| 2343 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2344 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2345 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2346 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2347 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2348 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2349 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2350 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2351 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2352 | msg.rpc_argp = &calldata->arg; |
| 2353 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2354 | task_setup_data.callback_data = calldata; |
| 2355 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2356 | if (IS_ERR(task)) |
| 2357 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2358 | status = 0; |
| 2359 | if (wait) |
| 2360 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2361 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2362 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2363 | out_free_calldata: |
| 2364 | kfree(calldata); |
| 2365 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2366 | nfs4_put_open_state(state); |
| 2367 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2368 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2371 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2372 | 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] | 2373 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | struct nfs4_state *state; |
| 2375 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2376 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2377 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2378 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2379 | if (IS_ERR(state)) |
| 2380 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2381 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2382 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2385 | 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] | 2386 | { |
| 2387 | if (ctx->state == NULL) |
| 2388 | return; |
| 2389 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2390 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2391 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2392 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | |
| 2395 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2396 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2397 | struct nfs4_server_caps_arg args = { |
| 2398 | .fhandle = fhandle, |
| 2399 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | struct nfs4_server_caps_res res = {}; |
| 2401 | struct rpc_message msg = { |
| 2402 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2403 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | .rpc_resp = &res, |
| 2405 | }; |
| 2406 | int status; |
| 2407 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2408 | 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] | 2409 | if (status == 0) { |
| 2410 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2411 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2412 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2413 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2414 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2415 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2417 | server->caps |= NFS_CAP_ACLS; |
| 2418 | if (res.has_links != 0) |
| 2419 | server->caps |= NFS_CAP_HARDLINKS; |
| 2420 | if (res.has_symlinks != 0) |
| 2421 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2422 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2423 | server->caps |= NFS_CAP_FILEID; |
| 2424 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2425 | server->caps |= NFS_CAP_MODE; |
| 2426 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2427 | server->caps |= NFS_CAP_NLINK; |
| 2428 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2429 | server->caps |= NFS_CAP_OWNER; |
| 2430 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2431 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2432 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2433 | server->caps |= NFS_CAP_ATIME; |
| 2434 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2435 | server->caps |= NFS_CAP_CTIME; |
| 2436 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2437 | server->caps |= NFS_CAP_MTIME; |
| 2438 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2439 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2440 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2441 | 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] | 2442 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2443 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | return status; |
| 2447 | } |
| 2448 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2449 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | { |
| 2451 | struct nfs4_exception exception = { }; |
| 2452 | int err; |
| 2453 | do { |
| 2454 | err = nfs4_handle_exception(server, |
| 2455 | _nfs4_server_capabilities(server, fhandle), |
| 2456 | &exception); |
| 2457 | } while (exception.retry); |
| 2458 | return err; |
| 2459 | } |
| 2460 | |
| 2461 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2462 | struct nfs_fsinfo *info) |
| 2463 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | struct nfs4_lookup_root_arg args = { |
| 2465 | .bitmask = nfs4_fattr_bitmap, |
| 2466 | }; |
| 2467 | struct nfs4_lookup_res res = { |
| 2468 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2469 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | .fh = fhandle, |
| 2471 | }; |
| 2472 | struct rpc_message msg = { |
| 2473 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2474 | .rpc_argp = &args, |
| 2475 | .rpc_resp = &res, |
| 2476 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2477 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2478 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2479 | 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] | 2480 | } |
| 2481 | |
| 2482 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2483 | struct nfs_fsinfo *info) |
| 2484 | { |
| 2485 | struct nfs4_exception exception = { }; |
| 2486 | int err; |
| 2487 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2488 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2489 | switch (err) { |
| 2490 | case 0: |
| 2491 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2492 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2493 | default: |
| 2494 | err = nfs4_handle_exception(server, err, &exception); |
| 2495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2497 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | return err; |
| 2499 | } |
| 2500 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2501 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2502 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2503 | { |
| 2504 | struct rpc_auth *auth; |
| 2505 | int ret; |
| 2506 | |
| 2507 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2508 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2509 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2510 | goto out; |
| 2511 | } |
| 2512 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2513 | out: |
| 2514 | return ret; |
| 2515 | } |
| 2516 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2517 | /* |
| 2518 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2519 | * |
| 2520 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2521 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2522 | * |
| 2523 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2524 | * negative errno value. |
| 2525 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2526 | 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] | 2527 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2529 | /* Per 3530bis 15.33.5 */ |
| 2530 | static const rpc_authflavor_t flav_array[] = { |
| 2531 | RPC_AUTH_GSS_KRB5P, |
| 2532 | RPC_AUTH_GSS_KRB5I, |
| 2533 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame^] | 2534 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2535 | RPC_AUTH_NULL, |
| 2536 | }; |
| 2537 | int status = -EPERM; |
| 2538 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2540 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2541 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2542 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2543 | continue; |
| 2544 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2545 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2546 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2547 | /* |
| 2548 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2549 | * to access the mount. It could also mean that we tried to mount |
| 2550 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2551 | * existing mount programs don't handle -EACCES very well so it should |
| 2552 | * be mapped to -EPERM instead. |
| 2553 | */ |
| 2554 | if (status == -EACCES) |
| 2555 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2556 | return status; |
| 2557 | } |
| 2558 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2559 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2560 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2561 | { |
| 2562 | int mv = server->nfs_client->cl_minorversion; |
| 2563 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2564 | } |
| 2565 | |
| 2566 | /** |
| 2567 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2568 | * @server: initialized nfs_server handle |
| 2569 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2570 | * @info: we fill in an FSINFO struct |
| 2571 | * |
| 2572 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2573 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2574 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2575 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2576 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2577 | int status; |
| 2578 | |
| 2579 | status = nfs4_lookup_root(server, fhandle, info); |
| 2580 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2581 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2582 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | if (status == 0) |
| 2585 | status = nfs4_server_capabilities(server, fhandle); |
| 2586 | if (status == 0) |
| 2587 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2588 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2589 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2592 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2593 | struct nfs_fsinfo *info) |
| 2594 | { |
| 2595 | int error; |
| 2596 | struct nfs_fattr *fattr = info->fattr; |
| 2597 | |
| 2598 | error = nfs4_server_capabilities(server, mntfh); |
| 2599 | if (error < 0) { |
| 2600 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2601 | return error; |
| 2602 | } |
| 2603 | |
| 2604 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2605 | if (error < 0) { |
| 2606 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2607 | return error; |
| 2608 | } |
| 2609 | |
| 2610 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2611 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2612 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2613 | |
| 2614 | return error; |
| 2615 | } |
| 2616 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2617 | /* |
| 2618 | * Get locations and (maybe) other attributes of a referral. |
| 2619 | * Note that we'll actually follow the referral later when |
| 2620 | * we detect fsid mismatch in inode revalidation |
| 2621 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2622 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2623 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2624 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2625 | { |
| 2626 | int status = -ENOMEM; |
| 2627 | struct page *page = NULL; |
| 2628 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2629 | |
| 2630 | page = alloc_page(GFP_KERNEL); |
| 2631 | if (page == NULL) |
| 2632 | goto out; |
| 2633 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2634 | if (locations == NULL) |
| 2635 | goto out; |
| 2636 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2637 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2638 | if (status != 0) |
| 2639 | goto out; |
| 2640 | /* Make sure server returned a different fsid for the referral */ |
| 2641 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2642 | dprintk("%s: server did not return a different fsid for" |
| 2643 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2644 | status = -EIO; |
| 2645 | goto out; |
| 2646 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2647 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2648 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2649 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2650 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2651 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2652 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2653 | out: |
| 2654 | if (page) |
| 2655 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2656 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2657 | return status; |
| 2658 | } |
| 2659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2661 | { |
| 2662 | struct nfs4_getattr_arg args = { |
| 2663 | .fh = fhandle, |
| 2664 | .bitmask = server->attr_bitmask, |
| 2665 | }; |
| 2666 | struct nfs4_getattr_res res = { |
| 2667 | .fattr = fattr, |
| 2668 | .server = server, |
| 2669 | }; |
| 2670 | struct rpc_message msg = { |
| 2671 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2672 | .rpc_argp = &args, |
| 2673 | .rpc_resp = &res, |
| 2674 | }; |
| 2675 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2676 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2677 | 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] | 2678 | } |
| 2679 | |
| 2680 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2681 | { |
| 2682 | struct nfs4_exception exception = { }; |
| 2683 | int err; |
| 2684 | do { |
| 2685 | err = nfs4_handle_exception(server, |
| 2686 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2687 | &exception); |
| 2688 | } while (exception.retry); |
| 2689 | return err; |
| 2690 | } |
| 2691 | |
| 2692 | /* |
| 2693 | * The file is not closed if it is opened due to the a request to change |
| 2694 | * the size of the file. The open call will not be needed once the |
| 2695 | * VFS layer lookup-intents are implemented. |
| 2696 | * |
| 2697 | * Close is called when the inode is destroyed. |
| 2698 | * If we haven't opened the file for O_WRONLY, we |
| 2699 | * need to in the size_change case to obtain a stateid. |
| 2700 | * |
| 2701 | * Got race? |
| 2702 | * Because OPEN is always done by name in nfsv4, it is |
| 2703 | * possible that we opened a different file by the same |
| 2704 | * name. We can recognize this race condition, but we |
| 2705 | * can't do anything about it besides returning an error. |
| 2706 | * |
| 2707 | * This will be fixed with VFS changes (lookup-intent). |
| 2708 | */ |
| 2709 | static int |
| 2710 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2711 | struct iattr *sattr) |
| 2712 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2713 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2714 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2715 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | int status; |
| 2717 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2718 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2719 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2720 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2721 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2723 | /* Deal with open(O_TRUNC) */ |
| 2724 | if (sattr->ia_valid & ATTR_OPEN) |
| 2725 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2726 | |
| 2727 | /* Optimization: if the end result is no change, don't RPC */ |
| 2728 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2729 | return 0; |
| 2730 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2731 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2732 | if (sattr->ia_valid & ATTR_FILE) { |
| 2733 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2734 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2735 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2736 | if (ctx) { |
| 2737 | cred = ctx->cred; |
| 2738 | state = ctx->state; |
| 2739 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2743 | if (status == 0) |
| 2744 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | return status; |
| 2746 | } |
| 2747 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2748 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2749 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2750 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2751 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2752 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2753 | int status; |
| 2754 | struct nfs4_lookup_arg args = { |
| 2755 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2756 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2757 | .name = name, |
| 2758 | }; |
| 2759 | struct nfs4_lookup_res res = { |
| 2760 | .server = server, |
| 2761 | .fattr = fattr, |
| 2762 | .fh = fhandle, |
| 2763 | }; |
| 2764 | struct rpc_message msg = { |
| 2765 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2766 | .rpc_argp = &args, |
| 2767 | .rpc_resp = &res, |
| 2768 | }; |
| 2769 | |
| 2770 | nfs_fattr_init(fattr); |
| 2771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2773 | 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] | 2774 | dprintk("NFS reply lookup: %d\n", status); |
| 2775 | return status; |
| 2776 | } |
| 2777 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2778 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2779 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2780 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2781 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2782 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2783 | fattr->nlink = 2; |
| 2784 | } |
| 2785 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2786 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2787 | struct qstr *name, struct nfs_fh *fhandle, |
| 2788 | struct nfs_fattr *fattr) |
| 2789 | { |
| 2790 | struct nfs4_exception exception = { }; |
| 2791 | struct rpc_clnt *client = *clnt; |
| 2792 | int err; |
| 2793 | do { |
| 2794 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2795 | switch (err) { |
| 2796 | case -NFS4ERR_BADNAME: |
| 2797 | err = -ENOENT; |
| 2798 | goto out; |
| 2799 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2800 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2801 | goto out; |
| 2802 | case -NFS4ERR_WRONGSEC: |
| 2803 | err = -EPERM; |
| 2804 | if (client != *clnt) |
| 2805 | goto out; |
| 2806 | |
| 2807 | client = nfs4_create_sec_client(client, dir, name); |
| 2808 | if (IS_ERR(client)) |
| 2809 | return PTR_ERR(client); |
| 2810 | |
| 2811 | exception.retry = 1; |
| 2812 | break; |
| 2813 | default: |
| 2814 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2815 | } |
| 2816 | } while (exception.retry); |
| 2817 | |
| 2818 | out: |
| 2819 | if (err == 0) |
| 2820 | *clnt = client; |
| 2821 | else if (client != *clnt) |
| 2822 | rpc_shutdown_client(client); |
| 2823 | |
| 2824 | return err; |
| 2825 | } |
| 2826 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2827 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2828 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2830 | int status; |
| 2831 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2832 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2833 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2834 | if (client != NFS_CLIENT(dir)) { |
| 2835 | rpc_shutdown_client(client); |
| 2836 | nfs_fixup_secinfo_attributes(fattr); |
| 2837 | } |
| 2838 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | } |
| 2840 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2841 | struct rpc_clnt * |
| 2842 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2843 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2844 | { |
| 2845 | int status; |
| 2846 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2847 | |
| 2848 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2849 | if (status < 0) { |
| 2850 | rpc_shutdown_client(client); |
| 2851 | return ERR_PTR(status); |
| 2852 | } |
| 2853 | return client; |
| 2854 | } |
| 2855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2857 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2858 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | struct nfs4_accessargs args = { |
| 2860 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2861 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2863 | struct nfs4_accessres res = { |
| 2864 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2865 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | struct rpc_message msg = { |
| 2867 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2868 | .rpc_argp = &args, |
| 2869 | .rpc_resp = &res, |
| 2870 | .rpc_cred = entry->cred, |
| 2871 | }; |
| 2872 | int mode = entry->mask; |
| 2873 | int status; |
| 2874 | |
| 2875 | /* |
| 2876 | * Determine which access bits we want to ask for... |
| 2877 | */ |
| 2878 | if (mode & MAY_READ) |
| 2879 | args.access |= NFS4_ACCESS_READ; |
| 2880 | if (S_ISDIR(inode->i_mode)) { |
| 2881 | if (mode & MAY_WRITE) |
| 2882 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2883 | if (mode & MAY_EXEC) |
| 2884 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2885 | } else { |
| 2886 | if (mode & MAY_WRITE) |
| 2887 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2888 | if (mode & MAY_EXEC) |
| 2889 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2890 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2891 | |
| 2892 | res.fattr = nfs_alloc_fattr(); |
| 2893 | if (res.fattr == NULL) |
| 2894 | return -ENOMEM; |
| 2895 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2896 | 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] | 2897 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2898 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2899 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2901 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | return status; |
| 2903 | } |
| 2904 | |
| 2905 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2906 | { |
| 2907 | struct nfs4_exception exception = { }; |
| 2908 | int err; |
| 2909 | do { |
| 2910 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2911 | _nfs4_proc_access(inode, entry), |
| 2912 | &exception); |
| 2913 | } while (exception.retry); |
| 2914 | return err; |
| 2915 | } |
| 2916 | |
| 2917 | /* |
| 2918 | * TODO: For the time being, we don't try to get any attributes |
| 2919 | * along with any of the zero-copy operations READ, READDIR, |
| 2920 | * READLINK, WRITE. |
| 2921 | * |
| 2922 | * In the case of the first three, we want to put the GETATTR |
| 2923 | * after the read-type operation -- this is because it is hard |
| 2924 | * to predict the length of a GETATTR response in v4, and thus |
| 2925 | * align the READ data correctly. This means that the GETATTR |
| 2926 | * may end up partially falling into the page cache, and we should |
| 2927 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2928 | * To do this efficiently, we need to know the total length |
| 2929 | * of data received, which doesn't seem to be available outside |
| 2930 | * of the RPC layer. |
| 2931 | * |
| 2932 | * In the case of WRITE, we also want to put the GETATTR after |
| 2933 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2934 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | * |
| 2936 | * Both of these changes to the XDR layer would in fact be quite |
| 2937 | * minor, but I decided to leave them for a subsequent patch. |
| 2938 | */ |
| 2939 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2940 | unsigned int pgbase, unsigned int pglen) |
| 2941 | { |
| 2942 | struct nfs4_readlink args = { |
| 2943 | .fh = NFS_FH(inode), |
| 2944 | .pgbase = pgbase, |
| 2945 | .pglen = pglen, |
| 2946 | .pages = &page, |
| 2947 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2948 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | struct rpc_message msg = { |
| 2950 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2951 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2952 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | }; |
| 2954 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2955 | 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] | 2956 | } |
| 2957 | |
| 2958 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2959 | unsigned int pgbase, unsigned int pglen) |
| 2960 | { |
| 2961 | struct nfs4_exception exception = { }; |
| 2962 | int err; |
| 2963 | do { |
| 2964 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2965 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2966 | &exception); |
| 2967 | } while (exception.retry); |
| 2968 | return err; |
| 2969 | } |
| 2970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2972 | * 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] | 2973 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | static int |
| 2975 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2976 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2978 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | int status = 0; |
| 2981 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2982 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2983 | if (IS_ERR(ctx)) |
| 2984 | return PTR_ERR(ctx); |
| 2985 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2986 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2987 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2988 | flags, sattr, ctx->cred, |
| 2989 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2990 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | if (IS_ERR(state)) { |
| 2992 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2993 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2995 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2996 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2997 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2999 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | return status; |
| 3001 | } |
| 3002 | |
| 3003 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3004 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3005 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3006 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3008 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3010 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3011 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3012 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3014 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3015 | .rpc_argp = &args, |
| 3016 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3018 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3019 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3020 | 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] | 3021 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3022 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | return status; |
| 3024 | } |
| 3025 | |
| 3026 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3027 | { |
| 3028 | struct nfs4_exception exception = { }; |
| 3029 | int err; |
| 3030 | do { |
| 3031 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3032 | _nfs4_proc_remove(dir, name), |
| 3033 | &exception); |
| 3034 | } while (exception.retry); |
| 3035 | return err; |
| 3036 | } |
| 3037 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3038 | 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] | 3039 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3040 | struct nfs_server *server = NFS_SERVER(dir); |
| 3041 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3042 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3044 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3046 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3049 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3050 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3051 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3052 | &data->args.seq_args, |
| 3053 | &data->res.seq_res, |
| 3054 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3057 | 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] | 3058 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3059 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3060 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3061 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3062 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3063 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3064 | return 0; |
| 3065 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3066 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3069 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3070 | { |
| 3071 | struct nfs_server *server = NFS_SERVER(dir); |
| 3072 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3073 | struct nfs_renameres *res = msg->rpc_resp; |
| 3074 | |
| 3075 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3076 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3077 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3078 | } |
| 3079 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3080 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3081 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3082 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3083 | &data->args.seq_args, |
| 3084 | &data->res.seq_res, |
| 3085 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3089 | struct inode *new_dir) |
| 3090 | { |
| 3091 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3092 | |
| 3093 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3094 | return 0; |
| 3095 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3096 | return 0; |
| 3097 | |
| 3098 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3099 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3100 | return 1; |
| 3101 | } |
| 3102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3104 | struct inode *new_dir, struct qstr *new_name) |
| 3105 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3106 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3107 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | .old_dir = NFS_FH(old_dir), |
| 3109 | .new_dir = NFS_FH(new_dir), |
| 3110 | .old_name = old_name, |
| 3111 | .new_name = new_name, |
| 3112 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3113 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3114 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3115 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | struct rpc_message msg = { |
| 3117 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3118 | .rpc_argp = &arg, |
| 3119 | .rpc_resp = &res, |
| 3120 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3121 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3123 | 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] | 3124 | if (!status) { |
| 3125 | update_changeattr(old_dir, &res.old_cinfo); |
| 3126 | update_changeattr(new_dir, &res.new_cinfo); |
| 3127 | } |
| 3128 | return status; |
| 3129 | } |
| 3130 | |
| 3131 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3132 | struct inode *new_dir, struct qstr *new_name) |
| 3133 | { |
| 3134 | struct nfs4_exception exception = { }; |
| 3135 | int err; |
| 3136 | do { |
| 3137 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3138 | _nfs4_proc_rename(old_dir, old_name, |
| 3139 | new_dir, new_name), |
| 3140 | &exception); |
| 3141 | } while (exception.retry); |
| 3142 | return err; |
| 3143 | } |
| 3144 | |
| 3145 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3146 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3147 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | struct nfs4_link_arg arg = { |
| 3149 | .fh = NFS_FH(inode), |
| 3150 | .dir_fh = NFS_FH(dir), |
| 3151 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3152 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3154 | struct nfs4_link_res res = { |
| 3155 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3156 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | struct rpc_message msg = { |
| 3158 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3159 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3160 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3162 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3164 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3165 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3166 | goto out; |
| 3167 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3168 | 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] | 3169 | if (!status) { |
| 3170 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3171 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3172 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3173 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3174 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | return status; |
| 3176 | } |
| 3177 | |
| 3178 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3179 | { |
| 3180 | struct nfs4_exception exception = { }; |
| 3181 | int err; |
| 3182 | do { |
| 3183 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3184 | _nfs4_proc_link(inode, dir, name), |
| 3185 | &exception); |
| 3186 | } while (exception.retry); |
| 3187 | return err; |
| 3188 | } |
| 3189 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3190 | struct nfs4_createdata { |
| 3191 | struct rpc_message msg; |
| 3192 | struct nfs4_create_arg arg; |
| 3193 | struct nfs4_create_res res; |
| 3194 | struct nfs_fh fh; |
| 3195 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3196 | }; |
| 3197 | |
| 3198 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3199 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3200 | { |
| 3201 | struct nfs4_createdata *data; |
| 3202 | |
| 3203 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3204 | if (data != NULL) { |
| 3205 | struct nfs_server *server = NFS_SERVER(dir); |
| 3206 | |
| 3207 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3208 | data->msg.rpc_argp = &data->arg; |
| 3209 | data->msg.rpc_resp = &data->res; |
| 3210 | data->arg.dir_fh = NFS_FH(dir); |
| 3211 | data->arg.server = server; |
| 3212 | data->arg.name = name; |
| 3213 | data->arg.attrs = sattr; |
| 3214 | data->arg.ftype = ftype; |
| 3215 | data->arg.bitmask = server->attr_bitmask; |
| 3216 | data->res.server = server; |
| 3217 | data->res.fh = &data->fh; |
| 3218 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3219 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3220 | } |
| 3221 | return data; |
| 3222 | } |
| 3223 | |
| 3224 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3225 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3226 | 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] | 3227 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3228 | if (status == 0) { |
| 3229 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3230 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3231 | } |
| 3232 | return status; |
| 3233 | } |
| 3234 | |
| 3235 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3236 | { |
| 3237 | kfree(data); |
| 3238 | } |
| 3239 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3240 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3241 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3243 | struct nfs4_createdata *data; |
| 3244 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3246 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3247 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3248 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3249 | status = -ENOMEM; |
| 3250 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3251 | if (data == NULL) |
| 3252 | goto out; |
| 3253 | |
| 3254 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3255 | data->arg.u.symlink.pages = &page; |
| 3256 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3258 | status = nfs4_do_create(dir, dentry, data); |
| 3259 | |
| 3260 | nfs4_free_createdata(data); |
| 3261 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | return status; |
| 3263 | } |
| 3264 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3265 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3266 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | { |
| 3268 | struct nfs4_exception exception = { }; |
| 3269 | int err; |
| 3270 | do { |
| 3271 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3272 | _nfs4_proc_symlink(dir, dentry, page, |
| 3273 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | &exception); |
| 3275 | } while (exception.retry); |
| 3276 | return err; |
| 3277 | } |
| 3278 | |
| 3279 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3280 | struct iattr *sattr) |
| 3281 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3282 | struct nfs4_createdata *data; |
| 3283 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3285 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3286 | if (data == NULL) |
| 3287 | goto out; |
| 3288 | |
| 3289 | status = nfs4_do_create(dir, dentry, data); |
| 3290 | |
| 3291 | nfs4_free_createdata(data); |
| 3292 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | return status; |
| 3294 | } |
| 3295 | |
| 3296 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3297 | struct iattr *sattr) |
| 3298 | { |
| 3299 | struct nfs4_exception exception = { }; |
| 3300 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3301 | |
| 3302 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | do { |
| 3304 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3305 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3306 | &exception); |
| 3307 | } while (exception.retry); |
| 3308 | return err; |
| 3309 | } |
| 3310 | |
| 3311 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3312 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | { |
| 3314 | struct inode *dir = dentry->d_inode; |
| 3315 | struct nfs4_readdir_arg args = { |
| 3316 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3317 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | .pgbase = 0, |
| 3319 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3320 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3321 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | }; |
| 3323 | struct nfs4_readdir_res res; |
| 3324 | struct rpc_message msg = { |
| 3325 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3326 | .rpc_argp = &args, |
| 3327 | .rpc_resp = &res, |
| 3328 | .rpc_cred = cred, |
| 3329 | }; |
| 3330 | int status; |
| 3331 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3332 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3333 | dentry->d_parent->d_name.name, |
| 3334 | dentry->d_name.name, |
| 3335 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3336 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3338 | 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] | 3339 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3340 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3341 | status += args.pgbase; |
| 3342 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3343 | |
| 3344 | nfs_invalidate_atime(dir); |
| 3345 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3346 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | return status; |
| 3348 | } |
| 3349 | |
| 3350 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3351 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | { |
| 3353 | struct nfs4_exception exception = { }; |
| 3354 | int err; |
| 3355 | do { |
| 3356 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3357 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3358 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | &exception); |
| 3360 | } while (exception.retry); |
| 3361 | return err; |
| 3362 | } |
| 3363 | |
| 3364 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3365 | struct iattr *sattr, dev_t rdev) |
| 3366 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3367 | struct nfs4_createdata *data; |
| 3368 | int mode = sattr->ia_mode; |
| 3369 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3371 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3372 | if (data == NULL) |
| 3373 | goto out; |
| 3374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3376 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3378 | data->arg.ftype = NF4BLK; |
| 3379 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3380 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | } |
| 3382 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3383 | data->arg.ftype = NF4CHR; |
| 3384 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3385 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3386 | } else if (!S_ISSOCK(mode)) { |
| 3387 | status = -EINVAL; |
| 3388 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3391 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3392 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3393 | nfs4_free_createdata(data); |
| 3394 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | return status; |
| 3396 | } |
| 3397 | |
| 3398 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3399 | struct iattr *sattr, dev_t rdev) |
| 3400 | { |
| 3401 | struct nfs4_exception exception = { }; |
| 3402 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3403 | |
| 3404 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | do { |
| 3406 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3407 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3408 | &exception); |
| 3409 | } while (exception.retry); |
| 3410 | return err; |
| 3411 | } |
| 3412 | |
| 3413 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3414 | struct nfs_fsstat *fsstat) |
| 3415 | { |
| 3416 | struct nfs4_statfs_arg args = { |
| 3417 | .fh = fhandle, |
| 3418 | .bitmask = server->attr_bitmask, |
| 3419 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3420 | struct nfs4_statfs_res res = { |
| 3421 | .fsstat = fsstat, |
| 3422 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | struct rpc_message msg = { |
| 3424 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3425 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3426 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | }; |
| 3428 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3429 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3430 | 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] | 3431 | } |
| 3432 | |
| 3433 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3434 | { |
| 3435 | struct nfs4_exception exception = { }; |
| 3436 | int err; |
| 3437 | do { |
| 3438 | err = nfs4_handle_exception(server, |
| 3439 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3440 | &exception); |
| 3441 | } while (exception.retry); |
| 3442 | return err; |
| 3443 | } |
| 3444 | |
| 3445 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3446 | struct nfs_fsinfo *fsinfo) |
| 3447 | { |
| 3448 | struct nfs4_fsinfo_arg args = { |
| 3449 | .fh = fhandle, |
| 3450 | .bitmask = server->attr_bitmask, |
| 3451 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3452 | struct nfs4_fsinfo_res res = { |
| 3453 | .fsinfo = fsinfo, |
| 3454 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | struct rpc_message msg = { |
| 3456 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3457 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3458 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | }; |
| 3460 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3461 | 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] | 3462 | } |
| 3463 | |
| 3464 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3465 | { |
| 3466 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3467 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | int err; |
| 3469 | |
| 3470 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3471 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3472 | if (err == 0) { |
| 3473 | struct nfs_client *clp = server->nfs_client; |
| 3474 | |
| 3475 | spin_lock(&clp->cl_lock); |
| 3476 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3477 | clp->cl_last_renewal = now; |
| 3478 | spin_unlock(&clp->cl_lock); |
| 3479 | break; |
| 3480 | } |
| 3481 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | } while (exception.retry); |
| 3483 | return err; |
| 3484 | } |
| 3485 | |
| 3486 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3487 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3488 | int error; |
| 3489 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3490 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3491 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3492 | if (error == 0) { |
| 3493 | /* block layout checks this! */ |
| 3494 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3495 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3496 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3497 | |
| 3498 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3502 | struct nfs_pathconf *pathconf) |
| 3503 | { |
| 3504 | struct nfs4_pathconf_arg args = { |
| 3505 | .fh = fhandle, |
| 3506 | .bitmask = server->attr_bitmask, |
| 3507 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3508 | struct nfs4_pathconf_res res = { |
| 3509 | .pathconf = pathconf, |
| 3510 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | struct rpc_message msg = { |
| 3512 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3513 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3514 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | }; |
| 3516 | |
| 3517 | /* None of the pathconf attributes are mandatory to implement */ |
| 3518 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3519 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3520 | return 0; |
| 3521 | } |
| 3522 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3523 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3524 | 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] | 3525 | } |
| 3526 | |
| 3527 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3528 | struct nfs_pathconf *pathconf) |
| 3529 | { |
| 3530 | struct nfs4_exception exception = { }; |
| 3531 | int err; |
| 3532 | |
| 3533 | do { |
| 3534 | err = nfs4_handle_exception(server, |
| 3535 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3536 | &exception); |
| 3537 | } while (exception.retry); |
| 3538 | return err; |
| 3539 | } |
| 3540 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3541 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3542 | const struct nfs_open_context *ctx, |
| 3543 | const struct nfs_lock_context *l_ctx, |
| 3544 | fmode_t fmode) |
| 3545 | { |
| 3546 | const struct nfs_lockowner *lockowner = NULL; |
| 3547 | |
| 3548 | if (l_ctx != NULL) |
| 3549 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3550 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3551 | } |
| 3552 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3553 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3554 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3555 | const struct nfs_open_context *ctx, |
| 3556 | const struct nfs_lock_context *l_ctx, |
| 3557 | fmode_t fmode) |
| 3558 | { |
| 3559 | nfs4_stateid current_stateid; |
| 3560 | |
| 3561 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3562 | return false; |
| 3563 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3564 | } |
| 3565 | |
| 3566 | static bool nfs4_error_stateid_expired(int err) |
| 3567 | { |
| 3568 | switch (err) { |
| 3569 | case -NFS4ERR_DELEG_REVOKED: |
| 3570 | case -NFS4ERR_ADMIN_REVOKED: |
| 3571 | case -NFS4ERR_BAD_STATEID: |
| 3572 | case -NFS4ERR_STALE_STATEID: |
| 3573 | case -NFS4ERR_OLD_STATEID: |
| 3574 | case -NFS4ERR_OPENMODE: |
| 3575 | case -NFS4ERR_EXPIRED: |
| 3576 | return true; |
| 3577 | } |
| 3578 | return false; |
| 3579 | } |
| 3580 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3581 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3582 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3583 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3584 | } |
| 3585 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3586 | 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] | 3587 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3588 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3590 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3591 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3592 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3594 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3595 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3597 | renew_lease(server, data->timestamp); |
| 3598 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3601 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3602 | struct nfs_readargs *args) |
| 3603 | { |
| 3604 | |
| 3605 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3606 | nfs4_stateid_is_current(&args->stateid, |
| 3607 | args->context, |
| 3608 | args->lock_context, |
| 3609 | FMODE_READ)) |
| 3610 | return false; |
| 3611 | rpc_restart_call_prepare(task); |
| 3612 | return true; |
| 3613 | } |
| 3614 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3615 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3616 | { |
| 3617 | |
| 3618 | dprintk("--> %s\n", __func__); |
| 3619 | |
| 3620 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3621 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3622 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3623 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3624 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3625 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3626 | } |
| 3627 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3628 | 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] | 3629 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3631 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3632 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3633 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3636 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3637 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3638 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3639 | &data->args.seq_args, |
| 3640 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3641 | task)) |
| 3642 | return; |
| 3643 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3644 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3647 | 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] | 3648 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3649 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3651 | 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] | 3652 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3653 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3655 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3657 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3658 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3659 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3662 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3663 | struct nfs_writeargs *args) |
| 3664 | { |
| 3665 | |
| 3666 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3667 | nfs4_stateid_is_current(&args->stateid, |
| 3668 | args->context, |
| 3669 | args->lock_context, |
| 3670 | FMODE_WRITE)) |
| 3671 | return false; |
| 3672 | rpc_restart_call_prepare(task); |
| 3673 | return true; |
| 3674 | } |
| 3675 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3676 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3677 | { |
| 3678 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3679 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3680 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3681 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3682 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3683 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3684 | } |
| 3685 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3686 | static |
| 3687 | 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] | 3688 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3689 | const struct nfs_pgio_header *hdr = data->header; |
| 3690 | |
| 3691 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3692 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3693 | return false; |
| 3694 | /* Otherwise, request attributes if and only if we don't hold |
| 3695 | * a delegation |
| 3696 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3697 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3698 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3699 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3700 | 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] | 3701 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3702 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3703 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3704 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3705 | data->args.bitmask = NULL; |
| 3706 | data->res.fattr = NULL; |
| 3707 | } else |
| 3708 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3709 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3710 | if (!data->write_done_cb) |
| 3711 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3712 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | data->timestamp = jiffies; |
| 3714 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3715 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3716 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | } |
| 3718 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3719 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3720 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3721 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3722 | &data->args.seq_args, |
| 3723 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3724 | task)) |
| 3725 | return; |
| 3726 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3727 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3730 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3731 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3732 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3733 | &data->args.seq_args, |
| 3734 | &data->res.seq_res, |
| 3735 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | } |
| 3737 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3738 | 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] | 3739 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3741 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3742 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3743 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3744 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3746 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3749 | 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] | 3750 | { |
| 3751 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3752 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3753 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3754 | } |
| 3755 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3756 | 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] | 3757 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3758 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3759 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3760 | if (data->commit_done_cb == NULL) |
| 3761 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3762 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3763 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3764 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | } |
| 3766 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3767 | struct nfs4_renewdata { |
| 3768 | struct nfs_client *client; |
| 3769 | unsigned long timestamp; |
| 3770 | }; |
| 3771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | /* |
| 3773 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3774 | * standalone procedure for queueing an asynchronous RENEW. |
| 3775 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3776 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3777 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3778 | struct nfs4_renewdata *data = calldata; |
| 3779 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3780 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3781 | if (atomic_read(&clp->cl_count) > 1) |
| 3782 | nfs4_schedule_state_renewal(clp); |
| 3783 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3784 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3785 | } |
| 3786 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3787 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3789 | struct nfs4_renewdata *data = calldata; |
| 3790 | struct nfs_client *clp = data->client; |
| 3791 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | |
| 3793 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3794 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3795 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3796 | return; |
| 3797 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3798 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3799 | return; |
| 3800 | } |
| 3801 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3803 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3806 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3807 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3808 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3809 | }; |
| 3810 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3811 | 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] | 3812 | { |
| 3813 | struct rpc_message msg = { |
| 3814 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3815 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3816 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3818 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3820 | if (renew_flags == 0) |
| 3821 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3822 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3823 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3824 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3825 | if (data == NULL) |
| 3826 | return -ENOMEM; |
| 3827 | data->client = clp; |
| 3828 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3830 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3833 | 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] | 3834 | { |
| 3835 | struct rpc_message msg = { |
| 3836 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3837 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3838 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | }; |
| 3840 | unsigned long now = jiffies; |
| 3841 | int status; |
| 3842 | |
| 3843 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3844 | if (status < 0) |
| 3845 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3846 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | return 0; |
| 3848 | } |
| 3849 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3850 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3851 | { |
| 3852 | return (server->caps & NFS_CAP_ACLS) |
| 3853 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3854 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3855 | } |
| 3856 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3857 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3858 | * 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] | 3859 | * the stack. |
| 3860 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3861 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3862 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3863 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3864 | struct page **pages, unsigned int *pgbase) |
| 3865 | { |
| 3866 | struct page *newpage, **spages; |
| 3867 | int rc = 0; |
| 3868 | size_t len; |
| 3869 | spages = pages; |
| 3870 | |
| 3871 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3872 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3873 | newpage = alloc_page(GFP_KERNEL); |
| 3874 | |
| 3875 | if (newpage == NULL) |
| 3876 | goto unwind; |
| 3877 | memcpy(page_address(newpage), buf, len); |
| 3878 | buf += len; |
| 3879 | buflen -= len; |
| 3880 | *pages++ = newpage; |
| 3881 | rc++; |
| 3882 | } while (buflen != 0); |
| 3883 | |
| 3884 | return rc; |
| 3885 | |
| 3886 | unwind: |
| 3887 | for(; rc > 0; rc--) |
| 3888 | __free_page(spages[rc-1]); |
| 3889 | return -ENOMEM; |
| 3890 | } |
| 3891 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3892 | struct nfs4_cached_acl { |
| 3893 | int cached; |
| 3894 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3895 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3896 | }; |
| 3897 | |
| 3898 | 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] | 3899 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3900 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3901 | |
| 3902 | spin_lock(&inode->i_lock); |
| 3903 | kfree(nfsi->nfs4_acl); |
| 3904 | nfsi->nfs4_acl = acl; |
| 3905 | spin_unlock(&inode->i_lock); |
| 3906 | } |
| 3907 | |
| 3908 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3909 | { |
| 3910 | nfs4_set_cached_acl(inode, NULL); |
| 3911 | } |
| 3912 | |
| 3913 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3914 | { |
| 3915 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3916 | struct nfs4_cached_acl *acl; |
| 3917 | int ret = -ENOENT; |
| 3918 | |
| 3919 | spin_lock(&inode->i_lock); |
| 3920 | acl = nfsi->nfs4_acl; |
| 3921 | if (acl == NULL) |
| 3922 | goto out; |
| 3923 | if (buf == NULL) /* user is just asking for length */ |
| 3924 | goto out_len; |
| 3925 | if (acl->cached == 0) |
| 3926 | goto out; |
| 3927 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3928 | if (acl->len > buflen) |
| 3929 | goto out; |
| 3930 | memcpy(buf, acl->data, acl->len); |
| 3931 | out_len: |
| 3932 | ret = acl->len; |
| 3933 | out: |
| 3934 | spin_unlock(&inode->i_lock); |
| 3935 | return ret; |
| 3936 | } |
| 3937 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3938 | 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] | 3939 | { |
| 3940 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3941 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3942 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3943 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3944 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3945 | if (acl == NULL) |
| 3946 | goto out; |
| 3947 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3948 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3949 | } else { |
| 3950 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3951 | if (acl == NULL) |
| 3952 | goto out; |
| 3953 | acl->cached = 0; |
| 3954 | } |
| 3955 | acl->len = acl_len; |
| 3956 | out: |
| 3957 | nfs4_set_cached_acl(inode, acl); |
| 3958 | } |
| 3959 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3960 | /* |
| 3961 | * The getxattr API returns the required buffer length when called with a |
| 3962 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3963 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3964 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3965 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3966 | * the cache. If not so, we throw away the page, and cache the required |
| 3967 | * length. The next getxattr call will then produce another round trip to |
| 3968 | * the server, this time with the input buf of the required size. |
| 3969 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3970 | 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] | 3971 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3972 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3973 | struct nfs_getaclargs args = { |
| 3974 | .fh = NFS_FH(inode), |
| 3975 | .acl_pages = pages, |
| 3976 | .acl_len = buflen, |
| 3977 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3978 | struct nfs_getaclres res = { |
| 3979 | .acl_len = buflen, |
| 3980 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3981 | struct rpc_message msg = { |
| 3982 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3983 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3984 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3985 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3986 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3987 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3988 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3989 | /* As long as we're doing a round trip to the server anyway, |
| 3990 | * let's be prepared for a page of acl data. */ |
| 3991 | if (npages == 0) |
| 3992 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3993 | if (npages > ARRAY_SIZE(pages)) |
| 3994 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3995 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3996 | for (i = 0; i < npages; i++) { |
| 3997 | pages[i] = alloc_page(GFP_KERNEL); |
| 3998 | if (!pages[i]) |
| 3999 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4000 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4001 | |
| 4002 | /* for decoding across pages */ |
| 4003 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4004 | if (!res.acl_scratch) |
| 4005 | goto out_free; |
| 4006 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4007 | args.acl_len = npages * PAGE_SIZE; |
| 4008 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4009 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4010 | 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] | 4011 | __func__, buf, buflen, npages, args.acl_len); |
| 4012 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4013 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4014 | if (ret) |
| 4015 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4016 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4017 | /* Handle the case where the passed-in buffer is too short */ |
| 4018 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4019 | /* Did the user only issue a request for the acl length? */ |
| 4020 | if (buf == NULL) |
| 4021 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4022 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4023 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4024 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4025 | 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] | 4026 | if (buf) { |
| 4027 | if (res.acl_len > buflen) { |
| 4028 | ret = -ERANGE; |
| 4029 | goto out_free; |
| 4030 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4031 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4032 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4033 | out_ok: |
| 4034 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4035 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4036 | for (i = 0; i < npages; i++) |
| 4037 | if (pages[i]) |
| 4038 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4039 | if (res.acl_scratch) |
| 4040 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4041 | return ret; |
| 4042 | } |
| 4043 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4044 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4045 | { |
| 4046 | struct nfs4_exception exception = { }; |
| 4047 | ssize_t ret; |
| 4048 | do { |
| 4049 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 4050 | if (ret >= 0) |
| 4051 | break; |
| 4052 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4053 | } while (exception.retry); |
| 4054 | return ret; |
| 4055 | } |
| 4056 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4057 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4058 | { |
| 4059 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4060 | int ret; |
| 4061 | |
| 4062 | if (!nfs4_server_supports_acls(server)) |
| 4063 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4064 | ret = nfs_revalidate_inode(server, inode); |
| 4065 | if (ret < 0) |
| 4066 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4067 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4068 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4069 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4070 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4071 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4072 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4073 | return ret; |
| 4074 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4075 | } |
| 4076 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4077 | 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] | 4078 | { |
| 4079 | struct nfs_server *server = NFS_SERVER(inode); |
| 4080 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4081 | struct nfs_setaclargs arg = { |
| 4082 | .fh = NFS_FH(inode), |
| 4083 | .acl_pages = pages, |
| 4084 | .acl_len = buflen, |
| 4085 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4086 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4087 | struct rpc_message msg = { |
| 4088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4089 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4090 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4091 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4092 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4093 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4094 | |
| 4095 | if (!nfs4_server_supports_acls(server)) |
| 4096 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4097 | if (npages > ARRAY_SIZE(pages)) |
| 4098 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4099 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4100 | if (i < 0) |
| 4101 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4102 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4103 | 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] | 4104 | |
| 4105 | /* |
| 4106 | * Free each page after tx, so the only ref left is |
| 4107 | * held by the network stack |
| 4108 | */ |
| 4109 | for (; i > 0; i--) |
| 4110 | put_page(pages[i-1]); |
| 4111 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4112 | /* |
| 4113 | * Acl update can result in inode attribute update. |
| 4114 | * so mark the attribute cache invalid. |
| 4115 | */ |
| 4116 | spin_lock(&inode->i_lock); |
| 4117 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4118 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4119 | nfs_access_zap_cache(inode); |
| 4120 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4121 | return ret; |
| 4122 | } |
| 4123 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4124 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4125 | { |
| 4126 | struct nfs4_exception exception = { }; |
| 4127 | int err; |
| 4128 | do { |
| 4129 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4130 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4131 | &exception); |
| 4132 | } while (exception.retry); |
| 4133 | return err; |
| 4134 | } |
| 4135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4137 | 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] | 4138 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4139 | struct nfs_client *clp = server->nfs_client; |
| 4140 | |
| 4141 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | return 0; |
| 4143 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4144 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4145 | case -NFS4ERR_ADMIN_REVOKED: |
| 4146 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4147 | if (state == NULL) |
| 4148 | break; |
| 4149 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4150 | case -NFS4ERR_OPENMODE: |
| 4151 | if (state == NULL) |
| 4152 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4153 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4154 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4155 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4156 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4157 | if (state != NULL) { |
| 4158 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4159 | goto stateid_invalid; |
| 4160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4162 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4163 | nfs4_schedule_lease_recovery(clp); |
| 4164 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4165 | #if defined(CONFIG_NFS_V4_1) |
| 4166 | case -NFS4ERR_BADSESSION: |
| 4167 | case -NFS4ERR_BADSLOT: |
| 4168 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4169 | case -NFS4ERR_DEADSESSION: |
| 4170 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4171 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4172 | case -NFS4ERR_SEQ_MISORDERED: |
| 4173 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4174 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4175 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4176 | task->tk_status = 0; |
| 4177 | return -EAGAIN; |
| 4178 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4180 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4181 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4183 | task->tk_status = 0; |
| 4184 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4185 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | case -NFS4ERR_OLD_STATEID: |
| 4187 | task->tk_status = 0; |
| 4188 | return -EAGAIN; |
| 4189 | } |
| 4190 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4191 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4192 | stateid_invalid: |
| 4193 | task->tk_status = -EIO; |
| 4194 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4195 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4196 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4197 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4198 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4199 | task->tk_status = 0; |
| 4200 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | } |
| 4202 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4203 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4204 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4205 | { |
| 4206 | __be32 verf[2]; |
| 4207 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4208 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4209 | /* An impossible timestamp guarantees this value |
| 4210 | * will never match a generated boot time. */ |
| 4211 | verf[0] = 0; |
| 4212 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4213 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4214 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4215 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4216 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4217 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4218 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4219 | } |
| 4220 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4221 | static unsigned int |
| 4222 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4223 | char *buf, size_t len) |
| 4224 | { |
| 4225 | unsigned int result; |
| 4226 | |
| 4227 | rcu_read_lock(); |
| 4228 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4229 | clp->cl_ipaddr, |
| 4230 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4231 | RPC_DISPLAY_ADDR), |
| 4232 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4233 | RPC_DISPLAY_PROTO)); |
| 4234 | rcu_read_unlock(); |
| 4235 | return result; |
| 4236 | } |
| 4237 | |
| 4238 | static unsigned int |
| 4239 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4240 | char *buf, size_t len) |
| 4241 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4242 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4243 | |
| 4244 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4245 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4246 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4247 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4248 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4249 | } |
| 4250 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4251 | /** |
| 4252 | * nfs4_proc_setclientid - Negotiate client ID |
| 4253 | * @clp: state data structure |
| 4254 | * @program: RPC program for NFSv4 callback service |
| 4255 | * @port: IP port number for NFS4 callback service |
| 4256 | * @cred: RPC credential to use for this call |
| 4257 | * @res: where to place the result |
| 4258 | * |
| 4259 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4260 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4261 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4262 | unsigned short port, struct rpc_cred *cred, |
| 4263 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | { |
| 4265 | nfs4_verifier sc_verifier; |
| 4266 | struct nfs4_setclientid setclientid = { |
| 4267 | .sc_verifier = &sc_verifier, |
| 4268 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4269 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | }; |
| 4271 | struct rpc_message msg = { |
| 4272 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4273 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4274 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4275 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4277 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4279 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4280 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4281 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4282 | setclientid.sc_name_len = |
| 4283 | nfs4_init_uniform_client_string(clp, |
| 4284 | setclientid.sc_name, |
| 4285 | sizeof(setclientid.sc_name)); |
| 4286 | else |
| 4287 | setclientid.sc_name_len = |
| 4288 | nfs4_init_nonuniform_client_string(clp, |
| 4289 | setclientid.sc_name, |
| 4290 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4291 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4292 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4293 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4294 | sizeof(setclientid.sc_netid), |
| 4295 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4296 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4297 | rcu_read_unlock(); |
| 4298 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4299 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4301 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4302 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4303 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4304 | setclientid.sc_name_len, setclientid.sc_name); |
| 4305 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4306 | dprintk("NFS reply setclientid: %d\n", status); |
| 4307 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4310 | /** |
| 4311 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4312 | * @clp: state data structure |
| 4313 | * @res: result of a previous SETCLIENTID |
| 4314 | * @cred: RPC credential to use for this call |
| 4315 | * |
| 4316 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4317 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4318 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4319 | struct nfs4_setclientid_res *arg, |
| 4320 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | struct rpc_message msg = { |
| 4323 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4324 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4325 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | int status; |
| 4328 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4329 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4330 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4331 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4332 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4333 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | return status; |
| 4335 | } |
| 4336 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4337 | struct nfs4_delegreturndata { |
| 4338 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4339 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4340 | struct nfs_fh fh; |
| 4341 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4342 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4343 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4344 | int rpc_status; |
| 4345 | }; |
| 4346 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4347 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4348 | { |
| 4349 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4350 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4351 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4352 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4353 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4354 | switch (task->tk_status) { |
| 4355 | case -NFS4ERR_STALE_STATEID: |
| 4356 | case -NFS4ERR_EXPIRED: |
| 4357 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4358 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4359 | break; |
| 4360 | default: |
| 4361 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4362 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4363 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4364 | return; |
| 4365 | } |
| 4366 | } |
| 4367 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | static void nfs4_delegreturn_release(void *calldata) |
| 4371 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4372 | kfree(calldata); |
| 4373 | } |
| 4374 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4375 | #if defined(CONFIG_NFS_V4_1) |
| 4376 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4377 | { |
| 4378 | struct nfs4_delegreturndata *d_data; |
| 4379 | |
| 4380 | d_data = (struct nfs4_delegreturndata *)data; |
| 4381 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4382 | nfs4_setup_sequence(d_data->res.server, |
| 4383 | &d_data->args.seq_args, |
| 4384 | &d_data->res.seq_res, |
| 4385 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4386 | } |
| 4387 | #endif /* CONFIG_NFS_V4_1 */ |
| 4388 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4389 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4390 | #if defined(CONFIG_NFS_V4_1) |
| 4391 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4392 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4393 | .rpc_call_done = nfs4_delegreturn_done, |
| 4394 | .rpc_release = nfs4_delegreturn_release, |
| 4395 | }; |
| 4396 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4397 | 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] | 4398 | { |
| 4399 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4400 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4401 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4402 | struct rpc_message msg = { |
| 4403 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4404 | .rpc_cred = cred, |
| 4405 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4406 | struct rpc_task_setup task_setup_data = { |
| 4407 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4408 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4409 | .callback_ops = &nfs4_delegreturn_ops, |
| 4410 | .flags = RPC_TASK_ASYNC, |
| 4411 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4412 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4413 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4414 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4415 | if (data == NULL) |
| 4416 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4417 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4418 | data->args.fhandle = &data->fh; |
| 4419 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4420 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4421 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4422 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4423 | data->res.fattr = &data->fattr; |
| 4424 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4425 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4426 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4427 | data->rpc_status = 0; |
| 4428 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4429 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4430 | msg.rpc_argp = &data->args; |
| 4431 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4432 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4433 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4434 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4435 | if (!issync) |
| 4436 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4437 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4438 | if (status != 0) |
| 4439 | goto out; |
| 4440 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4441 | if (status == 0) |
| 4442 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4443 | else |
| 4444 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4445 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4446 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4447 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4450 | 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] | 4451 | { |
| 4452 | struct nfs_server *server = NFS_SERVER(inode); |
| 4453 | struct nfs4_exception exception = { }; |
| 4454 | int err; |
| 4455 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4456 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | switch (err) { |
| 4458 | case -NFS4ERR_STALE_STATEID: |
| 4459 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | case 0: |
| 4461 | return 0; |
| 4462 | } |
| 4463 | err = nfs4_handle_exception(server, err, &exception); |
| 4464 | } while (exception.retry); |
| 4465 | return err; |
| 4466 | } |
| 4467 | |
| 4468 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4469 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4470 | |
| 4471 | /* |
| 4472 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4473 | */ |
| 4474 | static unsigned long |
| 4475 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4476 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4477 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | timeout <<= 1; |
| 4479 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4480 | return NFS4_LOCK_MAXTIMEOUT; |
| 4481 | return timeout; |
| 4482 | } |
| 4483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4485 | { |
| 4486 | struct inode *inode = state->inode; |
| 4487 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4488 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4489 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4491 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4493 | struct nfs_lockt_res res = { |
| 4494 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | }; |
| 4496 | struct rpc_message msg = { |
| 4497 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4498 | .rpc_argp = &arg, |
| 4499 | .rpc_resp = &res, |
| 4500 | .rpc_cred = state->owner->so_cred, |
| 4501 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | struct nfs4_lock_state *lsp; |
| 4503 | int status; |
| 4504 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4505 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4506 | status = nfs4_set_lock_state(state, request); |
| 4507 | if (status != 0) |
| 4508 | goto out; |
| 4509 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4510 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4511 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4512 | 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] | 4513 | switch (status) { |
| 4514 | case 0: |
| 4515 | request->fl_type = F_UNLCK; |
| 4516 | break; |
| 4517 | case -NFS4ERR_DENIED: |
| 4518 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4520 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4521 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | return status; |
| 4523 | } |
| 4524 | |
| 4525 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4526 | { |
| 4527 | struct nfs4_exception exception = { }; |
| 4528 | int err; |
| 4529 | |
| 4530 | do { |
| 4531 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4532 | _nfs4_proc_getlk(state, cmd, request), |
| 4533 | &exception); |
| 4534 | } while (exception.retry); |
| 4535 | return err; |
| 4536 | } |
| 4537 | |
| 4538 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4539 | { |
| 4540 | int res = 0; |
| 4541 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4542 | case FL_POSIX: |
| 4543 | res = posix_lock_file_wait(file, fl); |
| 4544 | break; |
| 4545 | case FL_FLOCK: |
| 4546 | res = flock_lock_file_wait(file, fl); |
| 4547 | break; |
| 4548 | default: |
| 4549 | BUG(); |
| 4550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | return res; |
| 4552 | } |
| 4553 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4554 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4555 | struct nfs_locku_args arg; |
| 4556 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4557 | struct nfs4_lock_state *lsp; |
| 4558 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4559 | struct file_lock fl; |
| 4560 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4561 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4562 | }; |
| 4563 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4564 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4565 | struct nfs_open_context *ctx, |
| 4566 | struct nfs4_lock_state *lsp, |
| 4567 | struct nfs_seqid *seqid) |
| 4568 | { |
| 4569 | struct nfs4_unlockdata *p; |
| 4570 | struct inode *inode = lsp->ls_state->inode; |
| 4571 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4572 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4573 | if (p == NULL) |
| 4574 | return NULL; |
| 4575 | p->arg.fh = NFS_FH(inode); |
| 4576 | p->arg.fl = &p->fl; |
| 4577 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4578 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4579 | p->arg.stateid = &lsp->ls_stateid; |
| 4580 | p->lsp = lsp; |
| 4581 | atomic_inc(&lsp->ls_count); |
| 4582 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4583 | p->ctx = get_nfs_open_context(ctx); |
| 4584 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4585 | p->server = NFS_SERVER(inode); |
| 4586 | return p; |
| 4587 | } |
| 4588 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4589 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4590 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4591 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4592 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4593 | nfs4_put_lock_state(calldata->lsp); |
| 4594 | put_nfs_open_context(calldata->ctx); |
| 4595 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4596 | } |
| 4597 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4598 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4599 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4600 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4601 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4602 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4603 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4604 | switch (task->tk_status) { |
| 4605 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4606 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4607 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4608 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4609 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4610 | case -NFS4ERR_BAD_STATEID: |
| 4611 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4612 | case -NFS4ERR_STALE_STATEID: |
| 4613 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4614 | break; |
| 4615 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4616 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4617 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4618 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4619 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4620 | } |
| 4621 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4622 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4623 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4624 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4626 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4627 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4628 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4629 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4630 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4631 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4632 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4633 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4634 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4635 | &calldata->res.seq_res, |
| 4636 | task) != 0) |
| 4637 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4638 | return; |
| 4639 | out_no_action: |
| 4640 | task->tk_action = NULL; |
| 4641 | out_wait: |
| 4642 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | } |
| 4644 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4645 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4646 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4647 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4648 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4649 | }; |
| 4650 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4651 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4652 | struct nfs_open_context *ctx, |
| 4653 | struct nfs4_lock_state *lsp, |
| 4654 | struct nfs_seqid *seqid) |
| 4655 | { |
| 4656 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4657 | struct rpc_message msg = { |
| 4658 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4659 | .rpc_cred = ctx->cred, |
| 4660 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4661 | struct rpc_task_setup task_setup_data = { |
| 4662 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4663 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4664 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4665 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4666 | .flags = RPC_TASK_ASYNC, |
| 4667 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4668 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4669 | /* Ensure this is an unlock - when canceling a lock, the |
| 4670 | * canceled lock is passed in, and it won't be an unlock. |
| 4671 | */ |
| 4672 | fl->fl_type = F_UNLCK; |
| 4673 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4674 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4675 | if (data == NULL) { |
| 4676 | nfs_free_seqid(seqid); |
| 4677 | return ERR_PTR(-ENOMEM); |
| 4678 | } |
| 4679 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4680 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4681 | msg.rpc_argp = &data->arg; |
| 4682 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4683 | task_setup_data.callback_data = data; |
| 4684 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4688 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4689 | struct inode *inode = state->inode; |
| 4690 | struct nfs4_state_owner *sp = state->owner; |
| 4691 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4692 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4693 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4694 | struct rpc_task *task; |
| 4695 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4696 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4698 | status = nfs4_set_lock_state(state, request); |
| 4699 | /* Unlock _before_ we do the RPC call */ |
| 4700 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4701 | /* Exclude nfs_delegation_claim_locks() */ |
| 4702 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4703 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4704 | down_read(&nfsi->rwsem); |
| 4705 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4706 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4707 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4708 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4709 | } |
| 4710 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4711 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4712 | if (status != 0) |
| 4713 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4714 | /* Is this a delegated lock? */ |
| 4715 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4716 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4717 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4718 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4719 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4720 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4721 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4722 | 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] | 4723 | status = PTR_ERR(task); |
| 4724 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4725 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4726 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4727 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4728 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4729 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4730 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | } |
| 4732 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4733 | struct nfs4_lockdata { |
| 4734 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4735 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4736 | struct nfs4_lock_state *lsp; |
| 4737 | struct nfs_open_context *ctx; |
| 4738 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4739 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4740 | int rpc_status; |
| 4741 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4742 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4743 | }; |
| 4744 | |
| 4745 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4746 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4747 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4748 | { |
| 4749 | struct nfs4_lockdata *p; |
| 4750 | struct inode *inode = lsp->ls_state->inode; |
| 4751 | struct nfs_server *server = NFS_SERVER(inode); |
| 4752 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4753 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4754 | if (p == NULL) |
| 4755 | return NULL; |
| 4756 | |
| 4757 | p->arg.fh = NFS_FH(inode); |
| 4758 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4759 | 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] | 4760 | if (p->arg.open_seqid == NULL) |
| 4761 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4762 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4763 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4764 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4765 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4766 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4767 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4768 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4769 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4770 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4771 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4772 | atomic_inc(&lsp->ls_count); |
| 4773 | p->ctx = get_nfs_open_context(ctx); |
| 4774 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4775 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4776 | out_free_seqid: |
| 4777 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4778 | out_free: |
| 4779 | kfree(p); |
| 4780 | return NULL; |
| 4781 | } |
| 4782 | |
| 4783 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4784 | { |
| 4785 | struct nfs4_lockdata *data = calldata; |
| 4786 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4788 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4789 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4790 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4791 | /* Do we need to do an open_to_lock_owner? */ |
| 4792 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4793 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4794 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4795 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4796 | data->arg.open_stateid = &state->stateid; |
| 4797 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4798 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4799 | } else |
| 4800 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4801 | if (!nfs4_valid_open_stateid(state)) { |
| 4802 | data->rpc_status = -EBADF; |
| 4803 | task->tk_action = NULL; |
| 4804 | goto out_release_open_seqid; |
| 4805 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4806 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4807 | if (nfs4_setup_sequence(data->server, |
| 4808 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4809 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4810 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4811 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4812 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4813 | nfs_release_seqid(data->arg.open_seqid); |
| 4814 | out_release_lock_seqid: |
| 4815 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4816 | out_wait: |
| 4817 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4818 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4819 | } |
| 4820 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4821 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4822 | { |
| 4823 | struct nfs4_lockdata *data = calldata; |
| 4824 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4825 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4826 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4827 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4828 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4829 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4830 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4831 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4832 | if (data->rpc_status == 0) |
| 4833 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4834 | else |
| 4835 | goto out; |
| 4836 | } |
| 4837 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4838 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4839 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4840 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4841 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4842 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4843 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | static void nfs4_lock_release(void *calldata) |
| 4847 | { |
| 4848 | struct nfs4_lockdata *data = calldata; |
| 4849 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4850 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4851 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4852 | if (data->cancelled != 0) { |
| 4853 | struct rpc_task *task; |
| 4854 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4855 | data->arg.lock_seqid); |
| 4856 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4857 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4858 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4859 | } else |
| 4860 | nfs_free_seqid(data->arg.lock_seqid); |
| 4861 | nfs4_put_lock_state(data->lsp); |
| 4862 | put_nfs_open_context(data->ctx); |
| 4863 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4864 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4868 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4869 | .rpc_call_done = nfs4_lock_done, |
| 4870 | .rpc_release = nfs4_lock_release, |
| 4871 | }; |
| 4872 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4873 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4874 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4875 | switch (error) { |
| 4876 | case -NFS4ERR_ADMIN_REVOKED: |
| 4877 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4878 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4879 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4880 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4881 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4882 | break; |
| 4883 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4884 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4885 | case -NFS4ERR_EXPIRED: |
| 4886 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4887 | }; |
| 4888 | } |
| 4889 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4890 | 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] | 4891 | { |
| 4892 | struct nfs4_lockdata *data; |
| 4893 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4894 | struct rpc_message msg = { |
| 4895 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4896 | .rpc_cred = state->owner->so_cred, |
| 4897 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4898 | struct rpc_task_setup task_setup_data = { |
| 4899 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4900 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4901 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4902 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4903 | .flags = RPC_TASK_ASYNC, |
| 4904 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4905 | int ret; |
| 4906 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4907 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4908 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4909 | fl->fl_u.nfs4_fl.owner, |
| 4910 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4911 | if (data == NULL) |
| 4912 | return -ENOMEM; |
| 4913 | if (IS_SETLKW(cmd)) |
| 4914 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4915 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4916 | msg.rpc_argp = &data->arg; |
| 4917 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4918 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4919 | if (recovery_type > NFS_LOCK_NEW) { |
| 4920 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4921 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4922 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4923 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4924 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4925 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4926 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4927 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4928 | if (ret == 0) { |
| 4929 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4930 | if (ret) |
| 4931 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4932 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4933 | } else |
| 4934 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4935 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4936 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4937 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4941 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4942 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4943 | struct nfs4_exception exception = { |
| 4944 | .inode = state->inode, |
| 4945 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4946 | int err; |
| 4947 | |
| 4948 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4949 | /* Cache the lock if possible... */ |
| 4950 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4951 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4952 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4953 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4954 | break; |
| 4955 | nfs4_handle_exception(server, err, &exception); |
| 4956 | } while (exception.retry); |
| 4957 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4961 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4962 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4963 | struct nfs4_exception exception = { |
| 4964 | .inode = state->inode, |
| 4965 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4966 | int err; |
| 4967 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4968 | err = nfs4_set_lock_state(state, request); |
| 4969 | if (err != 0) |
| 4970 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4971 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4972 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4973 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4974 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4975 | switch (err) { |
| 4976 | default: |
| 4977 | goto out; |
| 4978 | case -NFS4ERR_GRACE: |
| 4979 | case -NFS4ERR_DELAY: |
| 4980 | nfs4_handle_exception(server, err, &exception); |
| 4981 | err = 0; |
| 4982 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4983 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4984 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4985 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | } |
| 4987 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4988 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4989 | /** |
| 4990 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4991 | * |
| 4992 | * @state: NFSv4 state for an inode |
| 4993 | * |
| 4994 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4995 | * Otherwise a negative NFS4ERR value is returned. |
| 4996 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4997 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4998 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4999 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5000 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5001 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5002 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5003 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5004 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5005 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 5006 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5007 | /* Free the stateid unless the server |
| 5008 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5009 | if (status != -NFS4ERR_BAD_STATEID) |
| 5010 | nfs41_free_stateid(server, |
| 5011 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5012 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5013 | ret = status; |
| 5014 | } |
| 5015 | } |
| 5016 | }; |
| 5017 | |
| 5018 | return ret; |
| 5019 | } |
| 5020 | |
| 5021 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5022 | { |
| 5023 | int status = NFS_OK; |
| 5024 | |
| 5025 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5026 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5027 | if (status != NFS_OK) |
| 5028 | status = nfs4_lock_expired(state, request); |
| 5029 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5030 | } |
| 5031 | #endif |
| 5032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5034 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5035 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5036 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5037 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5038 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5039 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5041 | if ((fl_flags & FL_POSIX) && |
| 5042 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5043 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5044 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5045 | status = nfs4_set_lock_state(state, request); |
| 5046 | if (status != 0) |
| 5047 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5048 | request->fl_flags |= FL_ACCESS; |
| 5049 | status = do_vfs_lock(request->fl_file, request); |
| 5050 | if (status < 0) |
| 5051 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5052 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5053 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5054 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5055 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5056 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5057 | status = do_vfs_lock(request->fl_file, request); |
| 5058 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5059 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5060 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5061 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5062 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5063 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5064 | goto out; |
| 5065 | down_read(&nfsi->rwsem); |
| 5066 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5067 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5068 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5069 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5070 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5071 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5072 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5073 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5074 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5075 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5076 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5077 | out: |
| 5078 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | return status; |
| 5080 | } |
| 5081 | |
| 5082 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5083 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5084 | struct nfs4_exception exception = { |
| 5085 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5086 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5087 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | int err; |
| 5089 | |
| 5090 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5091 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5092 | if (err == -NFS4ERR_DENIED) |
| 5093 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5094 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5095 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | } while (exception.retry); |
| 5097 | return err; |
| 5098 | } |
| 5099 | |
| 5100 | static int |
| 5101 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5102 | { |
| 5103 | struct nfs_open_context *ctx; |
| 5104 | struct nfs4_state *state; |
| 5105 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5106 | int status; |
| 5107 | |
| 5108 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5109 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | state = ctx->state; |
| 5111 | |
| 5112 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5113 | return -EINVAL; |
| 5114 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5115 | if (IS_GETLK(cmd)) { |
| 5116 | if (state != NULL) |
| 5117 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5118 | return 0; |
| 5119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | |
| 5121 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5122 | return -EINVAL; |
| 5123 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5124 | if (request->fl_type == F_UNLCK) { |
| 5125 | if (state != NULL) |
| 5126 | return nfs4_proc_unlck(state, cmd, request); |
| 5127 | return 0; |
| 5128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5130 | if (state == NULL) |
| 5131 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5132 | /* |
| 5133 | * Don't rely on the VFS having checked the file open mode, |
| 5134 | * since it won't do this for flock() locks. |
| 5135 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5136 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5137 | case F_RDLCK: |
| 5138 | if (!(filp->f_mode & FMODE_READ)) |
| 5139 | return -EBADF; |
| 5140 | break; |
| 5141 | case F_WRLCK: |
| 5142 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5143 | return -EBADF; |
| 5144 | } |
| 5145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | do { |
| 5147 | status = nfs4_proc_setlk(state, cmd, request); |
| 5148 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5149 | break; |
| 5150 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5151 | status = -ERESTARTSYS; |
| 5152 | if (signalled()) |
| 5153 | break; |
| 5154 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | return status; |
| 5156 | } |
| 5157 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5158 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5159 | { |
| 5160 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5161 | struct nfs4_exception exception = { }; |
| 5162 | int err; |
| 5163 | |
| 5164 | err = nfs4_set_lock_state(state, fl); |
| 5165 | if (err != 0) |
| 5166 | goto out; |
| 5167 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5168 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5169 | switch (err) { |
| 5170 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5171 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5172 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5173 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5174 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5175 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5176 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5177 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5178 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 5179 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5180 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5181 | err = -EAGAIN; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5182 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5183 | case -NFS4ERR_BADSESSION: |
| 5184 | case -NFS4ERR_BADSLOT: |
| 5185 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5186 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5187 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5188 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5189 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5190 | err = -EAGAIN; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5191 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5192 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5193 | case -NFS4ERR_ADMIN_REVOKED: |
| 5194 | case -NFS4ERR_BAD_STATEID: |
| 5195 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5196 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5197 | err = 0; |
| 5198 | goto out; |
| 5199 | case -ENOMEM: |
| 5200 | case -NFS4ERR_DENIED: |
| 5201 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5202 | err = 0; |
| 5203 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5204 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5205 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5206 | err = nfs4_handle_exception(server, err, &exception); |
| 5207 | } while (exception.retry); |
| 5208 | out: |
| 5209 | return err; |
| 5210 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5211 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5212 | struct nfs_release_lockowner_data { |
| 5213 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5214 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5215 | struct nfs_release_lockowner_args args; |
| 5216 | }; |
| 5217 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5218 | static void nfs4_release_lockowner_release(void *calldata) |
| 5219 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5220 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5221 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5222 | kfree(calldata); |
| 5223 | } |
| 5224 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5225 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5226 | .rpc_release = nfs4_release_lockowner_release, |
| 5227 | }; |
| 5228 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5229 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5230 | { |
| 5231 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5232 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5233 | struct rpc_message msg = { |
| 5234 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5235 | }; |
| 5236 | |
| 5237 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5238 | return -EINVAL; |
| 5239 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5240 | if (!data) |
| 5241 | return -ENOMEM; |
| 5242 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5243 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5244 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5245 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5246 | data->args.lock_owner.s_dev = server->s_dev; |
| 5247 | msg.rpc_argp = &data->args; |
| 5248 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5249 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5250 | } |
| 5251 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5252 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5253 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5254 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5255 | const void *buf, size_t buflen, |
| 5256 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5257 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5258 | if (strcmp(key, "") != 0) |
| 5259 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5260 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5261 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5262 | } |
| 5263 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5264 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5265 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5266 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5267 | if (strcmp(key, "") != 0) |
| 5268 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5269 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5270 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5271 | } |
| 5272 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5273 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5274 | size_t list_len, const char *name, |
| 5275 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5276 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5277 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5278 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5279 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5280 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5281 | |
| 5282 | if (list && len <= list_len) |
| 5283 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5284 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5287 | /* |
| 5288 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5289 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5290 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5291 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5292 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5293 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5294 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5295 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5296 | return; |
| 5297 | |
| 5298 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5299 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5300 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5301 | fattr->nlink = 2; |
| 5302 | } |
| 5303 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5304 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5305 | const struct qstr *name, |
| 5306 | struct nfs4_fs_locations *fs_locations, |
| 5307 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5308 | { |
| 5309 | struct nfs_server *server = NFS_SERVER(dir); |
| 5310 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5311 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5312 | }; |
| 5313 | struct nfs4_fs_locations_arg args = { |
| 5314 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5315 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5316 | .page = page, |
| 5317 | .bitmask = bitmask, |
| 5318 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5319 | struct nfs4_fs_locations_res res = { |
| 5320 | .fs_locations = fs_locations, |
| 5321 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5322 | struct rpc_message msg = { |
| 5323 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5324 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5325 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5326 | }; |
| 5327 | int status; |
| 5328 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5329 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5330 | |
| 5331 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5332 | * is not supported */ |
| 5333 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5334 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5335 | else |
| 5336 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5337 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5338 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5339 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5340 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5341 | 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] | 5342 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5343 | return status; |
| 5344 | } |
| 5345 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5346 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5347 | const struct qstr *name, |
| 5348 | struct nfs4_fs_locations *fs_locations, |
| 5349 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5350 | { |
| 5351 | struct nfs4_exception exception = { }; |
| 5352 | int err; |
| 5353 | do { |
| 5354 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5355 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5356 | &exception); |
| 5357 | } while (exception.retry); |
| 5358 | return err; |
| 5359 | } |
| 5360 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5361 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5362 | { |
| 5363 | int status; |
| 5364 | struct nfs4_secinfo_arg args = { |
| 5365 | .dir_fh = NFS_FH(dir), |
| 5366 | .name = name, |
| 5367 | }; |
| 5368 | struct nfs4_secinfo_res res = { |
| 5369 | .flavors = flavors, |
| 5370 | }; |
| 5371 | struct rpc_message msg = { |
| 5372 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5373 | .rpc_argp = &args, |
| 5374 | .rpc_resp = &res, |
| 5375 | }; |
| 5376 | |
| 5377 | dprintk("NFS call secinfo %s\n", name->name); |
| 5378 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5379 | dprintk("NFS reply secinfo: %d\n", status); |
| 5380 | return status; |
| 5381 | } |
| 5382 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5383 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5384 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5385 | { |
| 5386 | struct nfs4_exception exception = { }; |
| 5387 | int err; |
| 5388 | do { |
| 5389 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5390 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5391 | &exception); |
| 5392 | } while (exception.retry); |
| 5393 | return err; |
| 5394 | } |
| 5395 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5396 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5397 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5398 | * Check the exchange flags returned by the server for invalid flags, having |
| 5399 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5400 | * DS flags set. |
| 5401 | */ |
| 5402 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5403 | { |
| 5404 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5405 | goto out_inval; |
| 5406 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5407 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5408 | goto out_inval; |
| 5409 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5410 | goto out_inval; |
| 5411 | return NFS_OK; |
| 5412 | out_inval: |
| 5413 | return -NFS4ERR_INVAL; |
| 5414 | } |
| 5415 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5416 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5417 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5418 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5419 | { |
| 5420 | if (a->server_scope_sz == b->server_scope_sz && |
| 5421 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5422 | return true; |
| 5423 | |
| 5424 | return false; |
| 5425 | } |
| 5426 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5427 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5428 | * nfs4_proc_bind_conn_to_session() |
| 5429 | * |
| 5430 | * The 4.1 client currently uses the same TCP connection for the |
| 5431 | * fore and backchannel. |
| 5432 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5433 | 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] | 5434 | { |
| 5435 | int status; |
| 5436 | struct nfs41_bind_conn_to_session_res res; |
| 5437 | struct rpc_message msg = { |
| 5438 | .rpc_proc = |
| 5439 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5440 | .rpc_argp = clp, |
| 5441 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5442 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5443 | }; |
| 5444 | |
| 5445 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5446 | |
| 5447 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5448 | if (unlikely(res.session == NULL)) { |
| 5449 | status = -ENOMEM; |
| 5450 | goto out; |
| 5451 | } |
| 5452 | |
| 5453 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5454 | if (status == 0) { |
| 5455 | if (memcmp(res.session->sess_id.data, |
| 5456 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5457 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5458 | status = -EIO; |
| 5459 | goto out_session; |
| 5460 | } |
| 5461 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5462 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5463 | __func__); |
| 5464 | status = -EIO; |
| 5465 | goto out_session; |
| 5466 | } |
| 5467 | if (res.use_conn_in_rdma_mode) { |
| 5468 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5469 | __func__); |
| 5470 | status = -EIO; |
| 5471 | goto out_session; |
| 5472 | } |
| 5473 | } |
| 5474 | out_session: |
| 5475 | kfree(res.session); |
| 5476 | out: |
| 5477 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5478 | return status; |
| 5479 | } |
| 5480 | |
| 5481 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5482 | * nfs4_proc_exchange_id() |
| 5483 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5484 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5485 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5486 | * Since the clientid has expired, all compounds using sessions |
| 5487 | * associated with the stale clientid will be returning |
| 5488 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5489 | * be in some phase of session reset. |
| 5490 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5491 | 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] | 5492 | { |
| 5493 | nfs4_verifier verifier; |
| 5494 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5495 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5496 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5497 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5498 | }; |
| 5499 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5500 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5501 | }; |
| 5502 | int status; |
| 5503 | struct rpc_message msg = { |
| 5504 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5505 | .rpc_argp = &args, |
| 5506 | .rpc_resp = &res, |
| 5507 | .rpc_cred = cred, |
| 5508 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5509 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5510 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5511 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5512 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5513 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5514 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5515 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5516 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5517 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5518 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5519 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5520 | status = -ENOMEM; |
| 5521 | goto out; |
| 5522 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5523 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5524 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5525 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5526 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5527 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5528 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5529 | } |
| 5530 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5531 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5532 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5533 | status = -ENOMEM; |
| 5534 | goto out_server_scope; |
| 5535 | } |
| 5536 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5537 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5538 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5539 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5540 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5541 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5542 | clp->cl_clientid = res.clientid; |
| 5543 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5544 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5545 | clp->cl_seqid = res.seqid; |
| 5546 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5547 | kfree(clp->cl_serverowner); |
| 5548 | clp->cl_serverowner = res.server_owner; |
| 5549 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5550 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5551 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5552 | kfree(clp->cl_implid); |
| 5553 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5554 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5555 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5556 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5557 | res.server_scope)) { |
| 5558 | dprintk("%s: server_scope mismatch detected\n", |
| 5559 | __func__); |
| 5560 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5561 | kfree(clp->cl_serverscope); |
| 5562 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5563 | } |
| 5564 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5565 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5566 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5567 | goto out; |
| 5568 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5569 | } else |
| 5570 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5571 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5572 | out_server_owner: |
| 5573 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5574 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5575 | kfree(res.server_scope); |
| 5576 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5577 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5578 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5579 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5580 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5581 | clp->cl_implid->date.seconds, |
| 5582 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5583 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5584 | return status; |
| 5585 | } |
| 5586 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5587 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5588 | struct rpc_cred *cred) |
| 5589 | { |
| 5590 | struct rpc_message msg = { |
| 5591 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5592 | .rpc_argp = clp, |
| 5593 | .rpc_cred = cred, |
| 5594 | }; |
| 5595 | int status; |
| 5596 | |
| 5597 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5598 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5599 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5600 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5601 | return status; |
| 5602 | } |
| 5603 | |
| 5604 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5605 | struct rpc_cred *cred) |
| 5606 | { |
| 5607 | unsigned int loop; |
| 5608 | int ret; |
| 5609 | |
| 5610 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5611 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5612 | switch (ret) { |
| 5613 | case -NFS4ERR_DELAY: |
| 5614 | case -NFS4ERR_CLIENTID_BUSY: |
| 5615 | ssleep(1); |
| 5616 | break; |
| 5617 | default: |
| 5618 | return ret; |
| 5619 | } |
| 5620 | } |
| 5621 | return 0; |
| 5622 | } |
| 5623 | |
| 5624 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5625 | { |
| 5626 | struct rpc_cred *cred; |
| 5627 | int ret = 0; |
| 5628 | |
| 5629 | if (clp->cl_mvops->minor_version < 1) |
| 5630 | goto out; |
| 5631 | if (clp->cl_exchange_flags == 0) |
| 5632 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5633 | if (clp->cl_preserve_clid) |
| 5634 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5635 | cred = nfs4_get_exchange_id_cred(clp); |
| 5636 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5637 | if (cred) |
| 5638 | put_rpccred(cred); |
| 5639 | switch (ret) { |
| 5640 | case 0: |
| 5641 | case -NFS4ERR_STALE_CLIENTID: |
| 5642 | clp->cl_exchange_flags = 0; |
| 5643 | } |
| 5644 | out: |
| 5645 | return ret; |
| 5646 | } |
| 5647 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5648 | struct nfs4_get_lease_time_data { |
| 5649 | struct nfs4_get_lease_time_args *args; |
| 5650 | struct nfs4_get_lease_time_res *res; |
| 5651 | struct nfs_client *clp; |
| 5652 | }; |
| 5653 | |
| 5654 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5655 | void *calldata) |
| 5656 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5657 | struct nfs4_get_lease_time_data *data = |
| 5658 | (struct nfs4_get_lease_time_data *)calldata; |
| 5659 | |
| 5660 | dprintk("--> %s\n", __func__); |
| 5661 | /* just setup sequence, do not trigger session recovery |
| 5662 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5663 | nfs41_setup_sequence(data->clp->cl_session, |
| 5664 | &data->args->la_seq_args, |
| 5665 | &data->res->lr_seq_res, |
| 5666 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5667 | dprintk("<-- %s\n", __func__); |
| 5668 | } |
| 5669 | |
| 5670 | /* |
| 5671 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5672 | * from sequence operation or clientid errors. |
| 5673 | */ |
| 5674 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5675 | { |
| 5676 | struct nfs4_get_lease_time_data *data = |
| 5677 | (struct nfs4_get_lease_time_data *)calldata; |
| 5678 | |
| 5679 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5680 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5681 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5682 | switch (task->tk_status) { |
| 5683 | case -NFS4ERR_DELAY: |
| 5684 | case -NFS4ERR_GRACE: |
| 5685 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5686 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5687 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5688 | /* fall through */ |
| 5689 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5690 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5691 | return; |
| 5692 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5693 | dprintk("<-- %s\n", __func__); |
| 5694 | } |
| 5695 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5696 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5697 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5698 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5699 | }; |
| 5700 | |
| 5701 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5702 | { |
| 5703 | struct rpc_task *task; |
| 5704 | struct nfs4_get_lease_time_args args; |
| 5705 | struct nfs4_get_lease_time_res res = { |
| 5706 | .lr_fsinfo = fsinfo, |
| 5707 | }; |
| 5708 | struct nfs4_get_lease_time_data data = { |
| 5709 | .args = &args, |
| 5710 | .res = &res, |
| 5711 | .clp = clp, |
| 5712 | }; |
| 5713 | struct rpc_message msg = { |
| 5714 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5715 | .rpc_argp = &args, |
| 5716 | .rpc_resp = &res, |
| 5717 | }; |
| 5718 | struct rpc_task_setup task_setup = { |
| 5719 | .rpc_client = clp->cl_rpcclient, |
| 5720 | .rpc_message = &msg, |
| 5721 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5722 | .callback_data = &data, |
| 5723 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5724 | }; |
| 5725 | int status; |
| 5726 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5727 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5728 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5729 | dprintk("--> %s\n", __func__); |
| 5730 | task = rpc_run_task(&task_setup); |
| 5731 | |
| 5732 | if (IS_ERR(task)) |
| 5733 | status = PTR_ERR(task); |
| 5734 | else { |
| 5735 | status = task->tk_status; |
| 5736 | rpc_put_task(task); |
| 5737 | } |
| 5738 | dprintk("<-- %s return %d\n", __func__, status); |
| 5739 | |
| 5740 | return status; |
| 5741 | } |
| 5742 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5743 | /* |
| 5744 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5745 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5746 | * use them. |
| 5747 | * |
| 5748 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5749 | * always set csa_cachethis to FALSE because the current implementation |
| 5750 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5751 | */ |
| 5752 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5753 | { |
| 5754 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5755 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5756 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5757 | |
| 5758 | if (mxrqst_sz == 0) |
| 5759 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5760 | if (mxresp_sz == 0) |
| 5761 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5762 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5763 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5764 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5765 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5766 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5767 | |
| 5768 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5769 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5770 | __func__, |
| 5771 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5772 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5773 | |
| 5774 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5775 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5776 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5777 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5778 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5779 | args->bc_attrs.max_reqs = 1; |
| 5780 | |
| 5781 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5782 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5783 | __func__, |
| 5784 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5785 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5786 | args->bc_attrs.max_reqs); |
| 5787 | } |
| 5788 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5789 | 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] | 5790 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5791 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5792 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5793 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5794 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5795 | return -EINVAL; |
| 5796 | /* |
| 5797 | * Our requested max_ops is the minimum we need; we're not |
| 5798 | * prepared to break up compounds into smaller pieces than that. |
| 5799 | * So, no point even trying to continue if the server won't |
| 5800 | * cooperate: |
| 5801 | */ |
| 5802 | if (rcvd->max_ops < sent->max_ops) |
| 5803 | return -EINVAL; |
| 5804 | if (rcvd->max_reqs == 0) |
| 5805 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5806 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5807 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5808 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5809 | } |
| 5810 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5811 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5812 | { |
| 5813 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5814 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5815 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5816 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5817 | return -EINVAL; |
| 5818 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5819 | return -EINVAL; |
| 5820 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5821 | return -EINVAL; |
| 5822 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5823 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5824 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5825 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5826 | return -EINVAL; |
| 5827 | return 0; |
| 5828 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5829 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5830 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5831 | struct nfs4_session *session) |
| 5832 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5833 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5834 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5835 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5836 | if (ret) |
| 5837 | return ret; |
| 5838 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5839 | } |
| 5840 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5841 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5842 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5843 | { |
| 5844 | struct nfs4_session *session = clp->cl_session; |
| 5845 | struct nfs41_create_session_args args = { |
| 5846 | .client = clp, |
| 5847 | .cb_program = NFS4_CALLBACK, |
| 5848 | }; |
| 5849 | struct nfs41_create_session_res res = { |
| 5850 | .client = clp, |
| 5851 | }; |
| 5852 | struct rpc_message msg = { |
| 5853 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5854 | .rpc_argp = &args, |
| 5855 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5856 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5857 | }; |
| 5858 | int status; |
| 5859 | |
| 5860 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5861 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5862 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5863 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5864 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5865 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5866 | /* Verify the session's negotiated channel_attrs values */ |
| 5867 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5868 | /* Increment the clientid slot sequence id */ |
| 5869 | clp->cl_seqid++; |
| 5870 | } |
| 5871 | |
| 5872 | return status; |
| 5873 | } |
| 5874 | |
| 5875 | /* |
| 5876 | * Issues a CREATE_SESSION operation to the server. |
| 5877 | * It is the responsibility of the caller to verify the session is |
| 5878 | * expired before calling this routine. |
| 5879 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5880 | 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] | 5881 | { |
| 5882 | int status; |
| 5883 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5884 | struct nfs4_session *session = clp->cl_session; |
| 5885 | |
| 5886 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5887 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5888 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5889 | if (status) |
| 5890 | goto out; |
| 5891 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5892 | /* Init or reset the session slot tables */ |
| 5893 | status = nfs4_setup_session_slot_tables(session); |
| 5894 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5895 | if (status) |
| 5896 | goto out; |
| 5897 | |
| 5898 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5899 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5900 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5901 | out: |
| 5902 | dprintk("<-- %s\n", __func__); |
| 5903 | return status; |
| 5904 | } |
| 5905 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5906 | /* |
| 5907 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5908 | * The caller must serialize access to this routine. |
| 5909 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5910 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5911 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5912 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5913 | struct rpc_message msg = { |
| 5914 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5915 | .rpc_argp = session, |
| 5916 | .rpc_cred = cred, |
| 5917 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5918 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5919 | |
| 5920 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5921 | |
| 5922 | /* session is still being setup */ |
| 5923 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5924 | return status; |
| 5925 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5926 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5927 | |
| 5928 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5929 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5930 | "Session has been destroyed regardless...\n", status); |
| 5931 | |
| 5932 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5933 | return status; |
| 5934 | } |
| 5935 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5936 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5937 | * Renew the cl_session lease. |
| 5938 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5939 | struct nfs4_sequence_data { |
| 5940 | struct nfs_client *clp; |
| 5941 | struct nfs4_sequence_args args; |
| 5942 | struct nfs4_sequence_res res; |
| 5943 | }; |
| 5944 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5945 | static void nfs41_sequence_release(void *data) |
| 5946 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5947 | struct nfs4_sequence_data *calldata = data; |
| 5948 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5949 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5950 | if (atomic_read(&clp->cl_count) > 1) |
| 5951 | nfs4_schedule_state_renewal(clp); |
| 5952 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5953 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5954 | } |
| 5955 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5956 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5957 | { |
| 5958 | switch(task->tk_status) { |
| 5959 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5960 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5961 | return -EAGAIN; |
| 5962 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5963 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5964 | } |
| 5965 | return 0; |
| 5966 | } |
| 5967 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5968 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5969 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5970 | struct nfs4_sequence_data *calldata = data; |
| 5971 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5972 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5973 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5974 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5975 | |
| 5976 | if (task->tk_status < 0) { |
| 5977 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5978 | if (atomic_read(&clp->cl_count) == 1) |
| 5979 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5980 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5981 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5982 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5983 | return; |
| 5984 | } |
| 5985 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5986 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5987 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5988 | dprintk("<-- %s\n", __func__); |
| 5989 | } |
| 5990 | |
| 5991 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5992 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5993 | struct nfs4_sequence_data *calldata = data; |
| 5994 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5995 | struct nfs4_sequence_args *args; |
| 5996 | struct nfs4_sequence_res *res; |
| 5997 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5998 | args = task->tk_msg.rpc_argp; |
| 5999 | res = task->tk_msg.rpc_resp; |
| 6000 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6001 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6005 | .rpc_call_done = nfs41_sequence_call_done, |
| 6006 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6007 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6008 | }; |
| 6009 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6010 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6011 | struct rpc_cred *cred, |
| 6012 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6013 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6014 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6015 | struct rpc_message msg = { |
| 6016 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6017 | .rpc_cred = cred, |
| 6018 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6019 | struct rpc_task_setup task_setup_data = { |
| 6020 | .rpc_client = clp->cl_rpcclient, |
| 6021 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6022 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6023 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6024 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6025 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6026 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6027 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6028 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6029 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6030 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6031 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6032 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6033 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6034 | if (is_privileged) |
| 6035 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6036 | msg.rpc_argp = &calldata->args; |
| 6037 | msg.rpc_resp = &calldata->res; |
| 6038 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6039 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6040 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6041 | return rpc_run_task(&task_setup_data); |
| 6042 | } |
| 6043 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6044 | 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] | 6045 | { |
| 6046 | struct rpc_task *task; |
| 6047 | int ret = 0; |
| 6048 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6049 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6050 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6051 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6052 | if (IS_ERR(task)) |
| 6053 | ret = PTR_ERR(task); |
| 6054 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6055 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6056 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6057 | return ret; |
| 6058 | } |
| 6059 | |
| 6060 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6061 | { |
| 6062 | struct rpc_task *task; |
| 6063 | int ret; |
| 6064 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6065 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6066 | if (IS_ERR(task)) { |
| 6067 | ret = PTR_ERR(task); |
| 6068 | goto out; |
| 6069 | } |
| 6070 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6071 | if (!ret) { |
| 6072 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6073 | |
| 6074 | if (task->tk_status == 0) |
| 6075 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6076 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6077 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6078 | rpc_put_task(task); |
| 6079 | out: |
| 6080 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6081 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6082 | } |
| 6083 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6084 | struct nfs4_reclaim_complete_data { |
| 6085 | struct nfs_client *clp; |
| 6086 | struct nfs41_reclaim_complete_args arg; |
| 6087 | struct nfs41_reclaim_complete_res res; |
| 6088 | }; |
| 6089 | |
| 6090 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6091 | { |
| 6092 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6093 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6094 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6095 | &calldata->arg.seq_args, |
| 6096 | &calldata->res.seq_res, |
| 6097 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6098 | } |
| 6099 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6100 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6101 | { |
| 6102 | switch(task->tk_status) { |
| 6103 | case 0: |
| 6104 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6105 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6106 | break; |
| 6107 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6108 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6109 | /* fall through */ |
| 6110 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6111 | return -EAGAIN; |
| 6112 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6113 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6114 | } |
| 6115 | return 0; |
| 6116 | } |
| 6117 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6118 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6119 | { |
| 6120 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6121 | struct nfs_client *clp = calldata->clp; |
| 6122 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6123 | |
| 6124 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6125 | if (!nfs41_sequence_done(task, res)) |
| 6126 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6127 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6128 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6129 | rpc_restart_call_prepare(task); |
| 6130 | return; |
| 6131 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6132 | dprintk("<-- %s\n", __func__); |
| 6133 | } |
| 6134 | |
| 6135 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6136 | { |
| 6137 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6138 | |
| 6139 | kfree(calldata); |
| 6140 | } |
| 6141 | |
| 6142 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6143 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6144 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6145 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6146 | }; |
| 6147 | |
| 6148 | /* |
| 6149 | * Issue a global reclaim complete. |
| 6150 | */ |
| 6151 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6152 | { |
| 6153 | struct nfs4_reclaim_complete_data *calldata; |
| 6154 | struct rpc_task *task; |
| 6155 | struct rpc_message msg = { |
| 6156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6157 | }; |
| 6158 | struct rpc_task_setup task_setup_data = { |
| 6159 | .rpc_client = clp->cl_rpcclient, |
| 6160 | .rpc_message = &msg, |
| 6161 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6162 | .flags = RPC_TASK_ASYNC, |
| 6163 | }; |
| 6164 | int status = -ENOMEM; |
| 6165 | |
| 6166 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6167 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6168 | if (calldata == NULL) |
| 6169 | goto out; |
| 6170 | calldata->clp = clp; |
| 6171 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6172 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6173 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6174 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6175 | msg.rpc_argp = &calldata->arg; |
| 6176 | msg.rpc_resp = &calldata->res; |
| 6177 | task_setup_data.callback_data = calldata; |
| 6178 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6179 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6180 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6181 | goto out; |
| 6182 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6183 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6184 | if (status == 0) |
| 6185 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6186 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6187 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6188 | out: |
| 6189 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6190 | return status; |
| 6191 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6192 | |
| 6193 | static void |
| 6194 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6195 | { |
| 6196 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6197 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6198 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6199 | |
| 6200 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6201 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6202 | * right now covering the LAYOUTGET we are about to send. |
| 6203 | * However, that is not so catastrophic, and there seems |
| 6204 | * to be no way to prevent it completely. |
| 6205 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6206 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6207 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6208 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6209 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6210 | NFS_I(lgp->args.inode)->layout, |
| 6211 | lgp->args.ctx->state)) { |
| 6212 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6213 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6214 | } |
| 6215 | |
| 6216 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6217 | { |
| 6218 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6219 | struct inode *inode = lgp->args.inode; |
| 6220 | struct nfs_server *server = NFS_SERVER(inode); |
| 6221 | struct pnfs_layout_hdr *lo; |
| 6222 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6223 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6224 | |
| 6225 | dprintk("--> %s\n", __func__); |
| 6226 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6227 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6228 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6229 | |
| 6230 | switch (task->tk_status) { |
| 6231 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6232 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6233 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6234 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6235 | timeo = rpc_get_timeout(task->tk_client); |
| 6236 | giveup = lgp->args.timestamp + timeo; |
| 6237 | if (time_after(giveup, jiffies)) |
| 6238 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6239 | break; |
| 6240 | case -NFS4ERR_EXPIRED: |
| 6241 | case -NFS4ERR_BAD_STATEID: |
| 6242 | spin_lock(&inode->i_lock); |
| 6243 | lo = NFS_I(inode)->layout; |
| 6244 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6245 | spin_unlock(&inode->i_lock); |
| 6246 | /* If the open stateid was bad, then recover it. */ |
| 6247 | state = lgp->args.ctx->state; |
| 6248 | } else { |
| 6249 | LIST_HEAD(head); |
| 6250 | |
| 6251 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6252 | spin_unlock(&inode->i_lock); |
| 6253 | /* Mark the bad layout state as invalid, then |
| 6254 | * retry using the open stateid. */ |
| 6255 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6256 | } |
| 6257 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6258 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6259 | rpc_restart_call_prepare(task); |
| 6260 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6261 | dprintk("<-- %s\n", __func__); |
| 6262 | } |
| 6263 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6264 | static size_t max_response_pages(struct nfs_server *server) |
| 6265 | { |
| 6266 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6267 | return nfs_page_array_len(0, max_resp_sz); |
| 6268 | } |
| 6269 | |
| 6270 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6271 | { |
| 6272 | int i; |
| 6273 | |
| 6274 | if (!pages) |
| 6275 | return; |
| 6276 | |
| 6277 | for (i = 0; i < size; i++) { |
| 6278 | if (!pages[i]) |
| 6279 | break; |
| 6280 | __free_page(pages[i]); |
| 6281 | } |
| 6282 | kfree(pages); |
| 6283 | } |
| 6284 | |
| 6285 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6286 | { |
| 6287 | struct page **pages; |
| 6288 | int i; |
| 6289 | |
| 6290 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6291 | if (!pages) { |
| 6292 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6293 | return NULL; |
| 6294 | } |
| 6295 | |
| 6296 | for (i = 0; i < size; i++) { |
| 6297 | pages[i] = alloc_page(gfp_flags); |
| 6298 | if (!pages[i]) { |
| 6299 | dprintk("%s: failed to allocate page\n", __func__); |
| 6300 | nfs4_free_pages(pages, size); |
| 6301 | return NULL; |
| 6302 | } |
| 6303 | } |
| 6304 | |
| 6305 | return pages; |
| 6306 | } |
| 6307 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6308 | static void nfs4_layoutget_release(void *calldata) |
| 6309 | { |
| 6310 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6311 | struct inode *inode = lgp->args.inode; |
| 6312 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6313 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6314 | |
| 6315 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6316 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6317 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6318 | put_nfs_open_context(lgp->args.ctx); |
| 6319 | kfree(calldata); |
| 6320 | dprintk("<-- %s\n", __func__); |
| 6321 | } |
| 6322 | |
| 6323 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6324 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6325 | .rpc_call_done = nfs4_layoutget_done, |
| 6326 | .rpc_release = nfs4_layoutget_release, |
| 6327 | }; |
| 6328 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6329 | struct pnfs_layout_segment * |
| 6330 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6331 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6332 | struct inode *inode = lgp->args.inode; |
| 6333 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6334 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6335 | struct rpc_task *task; |
| 6336 | struct rpc_message msg = { |
| 6337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6338 | .rpc_argp = &lgp->args, |
| 6339 | .rpc_resp = &lgp->res, |
| 6340 | }; |
| 6341 | struct rpc_task_setup task_setup_data = { |
| 6342 | .rpc_client = server->client, |
| 6343 | .rpc_message = &msg, |
| 6344 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6345 | .callback_data = lgp, |
| 6346 | .flags = RPC_TASK_ASYNC, |
| 6347 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6348 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6349 | int status = 0; |
| 6350 | |
| 6351 | dprintk("--> %s\n", __func__); |
| 6352 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6353 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6354 | if (!lgp->args.layout.pages) { |
| 6355 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6356 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6357 | } |
| 6358 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6359 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6360 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6361 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6362 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6363 | 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] | 6364 | |
| 6365 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6366 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6367 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6368 | task = rpc_run_task(&task_setup_data); |
| 6369 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6370 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6371 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6372 | if (status == 0) |
| 6373 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6374 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6375 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6376 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6377 | rpc_put_task(task); |
| 6378 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6379 | if (status) |
| 6380 | return ERR_PTR(status); |
| 6381 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6382 | } |
| 6383 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6384 | static void |
| 6385 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6386 | { |
| 6387 | struct nfs4_layoutreturn *lrp = calldata; |
| 6388 | |
| 6389 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6390 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6391 | &lrp->args.seq_args, |
| 6392 | &lrp->res.seq_res, |
| 6393 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6394 | } |
| 6395 | |
| 6396 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6397 | { |
| 6398 | struct nfs4_layoutreturn *lrp = calldata; |
| 6399 | struct nfs_server *server; |
| 6400 | |
| 6401 | dprintk("--> %s\n", __func__); |
| 6402 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6403 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6404 | return; |
| 6405 | |
| 6406 | server = NFS_SERVER(lrp->args.inode); |
| 6407 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6408 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6409 | return; |
| 6410 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6411 | dprintk("<-- %s\n", __func__); |
| 6412 | } |
| 6413 | |
| 6414 | static void nfs4_layoutreturn_release(void *calldata) |
| 6415 | { |
| 6416 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6417 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6418 | |
| 6419 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6420 | spin_lock(&lo->plh_inode->i_lock); |
| 6421 | if (lrp->res.lrs_present) |
| 6422 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6423 | lo->plh_block_lgets--; |
| 6424 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6425 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6426 | kfree(calldata); |
| 6427 | dprintk("<-- %s\n", __func__); |
| 6428 | } |
| 6429 | |
| 6430 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6431 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6432 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6433 | .rpc_release = nfs4_layoutreturn_release, |
| 6434 | }; |
| 6435 | |
| 6436 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6437 | { |
| 6438 | struct rpc_task *task; |
| 6439 | struct rpc_message msg = { |
| 6440 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6441 | .rpc_argp = &lrp->args, |
| 6442 | .rpc_resp = &lrp->res, |
| 6443 | }; |
| 6444 | struct rpc_task_setup task_setup_data = { |
| 6445 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6446 | .rpc_message = &msg, |
| 6447 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6448 | .callback_data = lrp, |
| 6449 | }; |
| 6450 | int status; |
| 6451 | |
| 6452 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6453 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6454 | task = rpc_run_task(&task_setup_data); |
| 6455 | if (IS_ERR(task)) |
| 6456 | return PTR_ERR(task); |
| 6457 | status = task->tk_status; |
| 6458 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6459 | rpc_put_task(task); |
| 6460 | return status; |
| 6461 | } |
| 6462 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6463 | /* |
| 6464 | * Retrieve the list of Data Server devices from the MDS. |
| 6465 | */ |
| 6466 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6467 | const struct nfs_fh *fh, |
| 6468 | struct pnfs_devicelist *devlist) |
| 6469 | { |
| 6470 | struct nfs4_getdevicelist_args args = { |
| 6471 | .fh = fh, |
| 6472 | .layoutclass = server->pnfs_curr_ld->id, |
| 6473 | }; |
| 6474 | struct nfs4_getdevicelist_res res = { |
| 6475 | .devlist = devlist, |
| 6476 | }; |
| 6477 | struct rpc_message msg = { |
| 6478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6479 | .rpc_argp = &args, |
| 6480 | .rpc_resp = &res, |
| 6481 | }; |
| 6482 | int status; |
| 6483 | |
| 6484 | dprintk("--> %s\n", __func__); |
| 6485 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6486 | &res.seq_res, 0); |
| 6487 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6488 | return status; |
| 6489 | } |
| 6490 | |
| 6491 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6492 | const struct nfs_fh *fh, |
| 6493 | struct pnfs_devicelist *devlist) |
| 6494 | { |
| 6495 | struct nfs4_exception exception = { }; |
| 6496 | int err; |
| 6497 | |
| 6498 | do { |
| 6499 | err = nfs4_handle_exception(server, |
| 6500 | _nfs4_getdevicelist(server, fh, devlist), |
| 6501 | &exception); |
| 6502 | } while (exception.retry); |
| 6503 | |
| 6504 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6505 | err, devlist->num_devs); |
| 6506 | |
| 6507 | return err; |
| 6508 | } |
| 6509 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6510 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6511 | static int |
| 6512 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6513 | { |
| 6514 | struct nfs4_getdeviceinfo_args args = { |
| 6515 | .pdev = pdev, |
| 6516 | }; |
| 6517 | struct nfs4_getdeviceinfo_res res = { |
| 6518 | .pdev = pdev, |
| 6519 | }; |
| 6520 | struct rpc_message msg = { |
| 6521 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6522 | .rpc_argp = &args, |
| 6523 | .rpc_resp = &res, |
| 6524 | }; |
| 6525 | int status; |
| 6526 | |
| 6527 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6528 | 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] | 6529 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6530 | |
| 6531 | return status; |
| 6532 | } |
| 6533 | |
| 6534 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6535 | { |
| 6536 | struct nfs4_exception exception = { }; |
| 6537 | int err; |
| 6538 | |
| 6539 | do { |
| 6540 | err = nfs4_handle_exception(server, |
| 6541 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6542 | &exception); |
| 6543 | } while (exception.retry); |
| 6544 | return err; |
| 6545 | } |
| 6546 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6547 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6548 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6549 | { |
| 6550 | struct nfs4_layoutcommit_data *data = calldata; |
| 6551 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6552 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6553 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6554 | nfs41_setup_sequence(session, |
| 6555 | &data->args.seq_args, |
| 6556 | &data->res.seq_res, |
| 6557 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | static void |
| 6561 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6562 | { |
| 6563 | struct nfs4_layoutcommit_data *data = calldata; |
| 6564 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6565 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6566 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6567 | return; |
| 6568 | |
| 6569 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6570 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6571 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6572 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6573 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6574 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6575 | break; |
| 6576 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6577 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6578 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6579 | break; |
| 6580 | default: |
| 6581 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6582 | rpc_restart_call_prepare(task); |
| 6583 | return; |
| 6584 | } |
| 6585 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | static void nfs4_layoutcommit_release(void *calldata) |
| 6589 | { |
| 6590 | struct nfs4_layoutcommit_data *data = calldata; |
| 6591 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6592 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6593 | put_rpccred(data->cred); |
| 6594 | kfree(data); |
| 6595 | } |
| 6596 | |
| 6597 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6598 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6599 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6600 | .rpc_release = nfs4_layoutcommit_release, |
| 6601 | }; |
| 6602 | |
| 6603 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6604 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6605 | { |
| 6606 | struct rpc_message msg = { |
| 6607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6608 | .rpc_argp = &data->args, |
| 6609 | .rpc_resp = &data->res, |
| 6610 | .rpc_cred = data->cred, |
| 6611 | }; |
| 6612 | struct rpc_task_setup task_setup_data = { |
| 6613 | .task = &data->task, |
| 6614 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6615 | .rpc_message = &msg, |
| 6616 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6617 | .callback_data = data, |
| 6618 | .flags = RPC_TASK_ASYNC, |
| 6619 | }; |
| 6620 | struct rpc_task *task; |
| 6621 | int status = 0; |
| 6622 | |
| 6623 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6624 | "lbw: %llu inode %lu\n", |
| 6625 | data->task.tk_pid, sync, |
| 6626 | data->args.lastbytewritten, |
| 6627 | data->args.inode->i_ino); |
| 6628 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6629 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6630 | task = rpc_run_task(&task_setup_data); |
| 6631 | if (IS_ERR(task)) |
| 6632 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6633 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6634 | goto out; |
| 6635 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6636 | if (status != 0) |
| 6637 | goto out; |
| 6638 | status = task->tk_status; |
| 6639 | out: |
| 6640 | dprintk("%s: status %d\n", __func__, status); |
| 6641 | rpc_put_task(task); |
| 6642 | return status; |
| 6643 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6644 | |
| 6645 | static int |
| 6646 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6647 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6648 | { |
| 6649 | struct nfs41_secinfo_no_name_args args = { |
| 6650 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6651 | }; |
| 6652 | struct nfs4_secinfo_res res = { |
| 6653 | .flavors = flavors, |
| 6654 | }; |
| 6655 | struct rpc_message msg = { |
| 6656 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6657 | .rpc_argp = &args, |
| 6658 | .rpc_resp = &res, |
| 6659 | }; |
| 6660 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6661 | } |
| 6662 | |
| 6663 | static int |
| 6664 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6665 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6666 | { |
| 6667 | struct nfs4_exception exception = { }; |
| 6668 | int err; |
| 6669 | do { |
| 6670 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6671 | switch (err) { |
| 6672 | case 0: |
| 6673 | case -NFS4ERR_WRONGSEC: |
| 6674 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6675 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6676 | default: |
| 6677 | err = nfs4_handle_exception(server, err, &exception); |
| 6678 | } |
| 6679 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6680 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6681 | return err; |
| 6682 | } |
| 6683 | |
| 6684 | static int |
| 6685 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6686 | struct nfs_fsinfo *info) |
| 6687 | { |
| 6688 | int err; |
| 6689 | struct page *page; |
| 6690 | rpc_authflavor_t flavor; |
| 6691 | struct nfs4_secinfo_flavors *flavors; |
| 6692 | |
| 6693 | page = alloc_page(GFP_KERNEL); |
| 6694 | if (!page) { |
| 6695 | err = -ENOMEM; |
| 6696 | goto out; |
| 6697 | } |
| 6698 | |
| 6699 | flavors = page_address(page); |
| 6700 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6701 | |
| 6702 | /* |
| 6703 | * Fall back on "guess and check" method if |
| 6704 | * the server doesn't support SECINFO_NO_NAME |
| 6705 | */ |
| 6706 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6707 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6708 | goto out_freepage; |
| 6709 | } |
| 6710 | if (err) |
| 6711 | goto out_freepage; |
| 6712 | |
| 6713 | flavor = nfs_find_best_sec(flavors); |
| 6714 | if (err == 0) |
| 6715 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6716 | |
| 6717 | out_freepage: |
| 6718 | put_page(page); |
| 6719 | if (err == -EACCES) |
| 6720 | return -EPERM; |
| 6721 | out: |
| 6722 | return err; |
| 6723 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6724 | |
| 6725 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6726 | { |
| 6727 | int status; |
| 6728 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6729 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6730 | }; |
| 6731 | struct nfs41_test_stateid_res res; |
| 6732 | struct rpc_message msg = { |
| 6733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6734 | .rpc_argp = &args, |
| 6735 | .rpc_resp = &res, |
| 6736 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6737 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6738 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6739 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6740 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6741 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6742 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6743 | if (status != NFS_OK) { |
| 6744 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6745 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6746 | } |
| 6747 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6748 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6749 | } |
| 6750 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6751 | /** |
| 6752 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6753 | * |
| 6754 | * @server: server / transport on which to perform the operation |
| 6755 | * @stateid: state ID to test |
| 6756 | * |
| 6757 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6758 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6759 | * failed or the state ID is not currently valid. |
| 6760 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6761 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6762 | { |
| 6763 | struct nfs4_exception exception = { }; |
| 6764 | int err; |
| 6765 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6766 | err = _nfs41_test_stateid(server, stateid); |
| 6767 | if (err != -NFS4ERR_DELAY) |
| 6768 | break; |
| 6769 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6770 | } while (exception.retry); |
| 6771 | return err; |
| 6772 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6773 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6774 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6775 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6776 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6777 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6778 | }; |
| 6779 | struct nfs41_free_stateid_res res; |
| 6780 | struct rpc_message msg = { |
| 6781 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6782 | .rpc_argp = &args, |
| 6783 | .rpc_resp = &res, |
| 6784 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6785 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6786 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6787 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6788 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6789 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6790 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6791 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6792 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6793 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6794 | } |
| 6795 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6796 | /** |
| 6797 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6798 | * |
| 6799 | * @server: server / transport on which to perform the operation |
| 6800 | * @stateid: state ID to release |
| 6801 | * |
| 6802 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6803 | * negative NFS4ERR value is returned. |
| 6804 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6805 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6806 | { |
| 6807 | struct nfs4_exception exception = { }; |
| 6808 | int err; |
| 6809 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6810 | err = _nfs4_free_stateid(server, stateid); |
| 6811 | if (err != -NFS4ERR_DELAY) |
| 6812 | break; |
| 6813 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6814 | } while (exception.retry); |
| 6815 | return err; |
| 6816 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6817 | |
| 6818 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6819 | const nfs4_stateid *s2) |
| 6820 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6821 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6822 | return false; |
| 6823 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6824 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6825 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6826 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6827 | return true; |
| 6828 | |
| 6829 | return false; |
| 6830 | } |
| 6831 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6832 | #endif /* CONFIG_NFS_V4_1 */ |
| 6833 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6834 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6835 | const nfs4_stateid *s2) |
| 6836 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6837 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6838 | } |
| 6839 | |
| 6840 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6841 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6842 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6843 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6844 | .recover_open = nfs4_open_reclaim, |
| 6845 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6846 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6847 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6848 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6849 | }; |
| 6850 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6851 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6852 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6853 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6854 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6855 | .recover_open = nfs4_open_reclaim, |
| 6856 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6857 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6858 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6859 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6860 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6861 | }; |
| 6862 | #endif /* CONFIG_NFS_V4_1 */ |
| 6863 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6864 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6865 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6866 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6867 | .recover_open = nfs4_open_expired, |
| 6868 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6869 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6870 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6871 | }; |
| 6872 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6873 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6874 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6875 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6876 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6877 | .recover_open = nfs41_open_expired, |
| 6878 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6879 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6880 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6881 | }; |
| 6882 | #endif /* CONFIG_NFS_V4_1 */ |
| 6883 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6884 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6885 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6886 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6887 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6888 | }; |
| 6889 | |
| 6890 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6891 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6892 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6893 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6894 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6895 | }; |
| 6896 | #endif |
| 6897 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6898 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6899 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6900 | .init_caps = NFS_CAP_READDIRPLUS |
| 6901 | | NFS_CAP_ATOMIC_OPEN |
| 6902 | | NFS_CAP_CHANGE_ATTR |
| 6903 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6904 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6905 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6906 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6907 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6908 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6909 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6910 | }; |
| 6911 | |
| 6912 | #if defined(CONFIG_NFS_V4_1) |
| 6913 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6914 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6915 | .init_caps = NFS_CAP_READDIRPLUS |
| 6916 | | NFS_CAP_ATOMIC_OPEN |
| 6917 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 6918 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 6919 | | NFS_CAP_STATEID_NFSV41 |
| 6920 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6921 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6922 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6923 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6924 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6925 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6926 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6927 | }; |
| 6928 | #endif |
| 6929 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6930 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6931 | [0] = &nfs_v4_0_minor_ops, |
| 6932 | #if defined(CONFIG_NFS_V4_1) |
| 6933 | [1] = &nfs_v4_1_minor_ops, |
| 6934 | #endif |
| 6935 | }; |
| 6936 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6937 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6938 | .create = nfs_create, |
| 6939 | .lookup = nfs_lookup, |
| 6940 | .atomic_open = nfs_atomic_open, |
| 6941 | .link = nfs_link, |
| 6942 | .unlink = nfs_unlink, |
| 6943 | .symlink = nfs_symlink, |
| 6944 | .mkdir = nfs_mkdir, |
| 6945 | .rmdir = nfs_rmdir, |
| 6946 | .mknod = nfs_mknod, |
| 6947 | .rename = nfs_rename, |
| 6948 | .permission = nfs_permission, |
| 6949 | .getattr = nfs_getattr, |
| 6950 | .setattr = nfs_setattr, |
| 6951 | .getxattr = generic_getxattr, |
| 6952 | .setxattr = generic_setxattr, |
| 6953 | .listxattr = generic_listxattr, |
| 6954 | .removexattr = generic_removexattr, |
| 6955 | }; |
| 6956 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6957 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6958 | .permission = nfs_permission, |
| 6959 | .getattr = nfs_getattr, |
| 6960 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6961 | .getxattr = generic_getxattr, |
| 6962 | .setxattr = generic_setxattr, |
| 6963 | .listxattr = generic_listxattr, |
| 6964 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6965 | }; |
| 6966 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6967 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6968 | .version = 4, /* protocol version */ |
| 6969 | .dentry_ops = &nfs4_dentry_operations, |
| 6970 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6971 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6972 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6973 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6974 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6975 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6976 | .getattr = nfs4_proc_getattr, |
| 6977 | .setattr = nfs4_proc_setattr, |
| 6978 | .lookup = nfs4_proc_lookup, |
| 6979 | .access = nfs4_proc_access, |
| 6980 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6981 | .create = nfs4_proc_create, |
| 6982 | .remove = nfs4_proc_remove, |
| 6983 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6984 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6985 | .unlink_done = nfs4_proc_unlink_done, |
| 6986 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6987 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6988 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6989 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6990 | .link = nfs4_proc_link, |
| 6991 | .symlink = nfs4_proc_symlink, |
| 6992 | .mkdir = nfs4_proc_mkdir, |
| 6993 | .rmdir = nfs4_proc_remove, |
| 6994 | .readdir = nfs4_proc_readdir, |
| 6995 | .mknod = nfs4_proc_mknod, |
| 6996 | .statfs = nfs4_proc_statfs, |
| 6997 | .fsinfo = nfs4_proc_fsinfo, |
| 6998 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6999 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7000 | .decode_dirent = nfs4_decode_dirent, |
| 7001 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7002 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7003 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7004 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7005 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7006 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7007 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7008 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7009 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7010 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7011 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7012 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7013 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7014 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7015 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7016 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7017 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7018 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7019 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7020 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7021 | .create_server = nfs4_create_server, |
| 7022 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7023 | }; |
| 7024 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7025 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7026 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7027 | .list = nfs4_xattr_list_nfs4_acl, |
| 7028 | .get = nfs4_xattr_get_nfs4_acl, |
| 7029 | .set = nfs4_xattr_set_nfs4_acl, |
| 7030 | }; |
| 7031 | |
| 7032 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7033 | &nfs4_xattr_nfs4_acl_handler, |
| 7034 | NULL |
| 7035 | }; |
| 7036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7037 | /* |
| 7038 | * Local variables: |
| 7039 | * c-basic-offset: 8 |
| 7040 | * End: |
| 7041 | */ |