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 | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 110 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 112 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 113 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 115 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* |
| 119 | * This is our standard bitmap for GETATTR requests. |
| 120 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 121 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | FATTR4_WORD0_TYPE |
| 123 | | FATTR4_WORD0_CHANGE |
| 124 | | FATTR4_WORD0_SIZE |
| 125 | | FATTR4_WORD0_FSID |
| 126 | | FATTR4_WORD0_FILEID, |
| 127 | FATTR4_WORD1_MODE |
| 128 | | FATTR4_WORD1_NUMLINKS |
| 129 | | FATTR4_WORD1_OWNER |
| 130 | | FATTR4_WORD1_OWNER_GROUP |
| 131 | | FATTR4_WORD1_RAWDEV |
| 132 | | FATTR4_WORD1_SPACE_USED |
| 133 | | FATTR4_WORD1_TIME_ACCESS |
| 134 | | FATTR4_WORD1_TIME_METADATA |
| 135 | | FATTR4_WORD1_TIME_MODIFY |
| 136 | }; |
| 137 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 138 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 139 | FATTR4_WORD0_TYPE |
| 140 | | FATTR4_WORD0_CHANGE |
| 141 | | FATTR4_WORD0_SIZE |
| 142 | | FATTR4_WORD0_FSID |
| 143 | | FATTR4_WORD0_FILEID, |
| 144 | FATTR4_WORD1_MODE |
| 145 | | FATTR4_WORD1_NUMLINKS |
| 146 | | FATTR4_WORD1_OWNER |
| 147 | | FATTR4_WORD1_OWNER_GROUP |
| 148 | | FATTR4_WORD1_RAWDEV |
| 149 | | FATTR4_WORD1_SPACE_USED |
| 150 | | FATTR4_WORD1_TIME_ACCESS |
| 151 | | FATTR4_WORD1_TIME_METADATA |
| 152 | | FATTR4_WORD1_TIME_MODIFY, |
| 153 | FATTR4_WORD2_MDSTHRESHOLD |
| 154 | }; |
| 155 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 156 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 157 | FATTR4_WORD0_TYPE |
| 158 | | FATTR4_WORD0_CHANGE |
| 159 | | FATTR4_WORD0_FILEID, |
| 160 | }; |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | const u32 nfs4_statfs_bitmap[2] = { |
| 163 | FATTR4_WORD0_FILES_AVAIL |
| 164 | | FATTR4_WORD0_FILES_FREE |
| 165 | | FATTR4_WORD0_FILES_TOTAL, |
| 166 | FATTR4_WORD1_SPACE_AVAIL |
| 167 | | FATTR4_WORD1_SPACE_FREE |
| 168 | | FATTR4_WORD1_SPACE_TOTAL |
| 169 | }; |
| 170 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 171 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | FATTR4_WORD0_MAXLINK |
| 173 | | FATTR4_WORD0_MAXNAME, |
| 174 | 0 |
| 175 | }; |
| 176 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 177 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | | FATTR4_WORD0_MAXREAD |
| 179 | | FATTR4_WORD0_MAXWRITE |
| 180 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 181 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 182 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 183 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 186 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 187 | FATTR4_WORD0_TYPE |
| 188 | | FATTR4_WORD0_CHANGE |
| 189 | | FATTR4_WORD0_SIZE |
| 190 | | FATTR4_WORD0_FSID |
| 191 | | FATTR4_WORD0_FILEID |
| 192 | | FATTR4_WORD0_FS_LOCATIONS, |
| 193 | FATTR4_WORD1_MODE |
| 194 | | FATTR4_WORD1_NUMLINKS |
| 195 | | FATTR4_WORD1_OWNER |
| 196 | | FATTR4_WORD1_OWNER_GROUP |
| 197 | | FATTR4_WORD1_RAWDEV |
| 198 | | FATTR4_WORD1_SPACE_USED |
| 199 | | FATTR4_WORD1_TIME_ACCESS |
| 200 | | FATTR4_WORD1_TIME_METADATA |
| 201 | | FATTR4_WORD1_TIME_MODIFY |
| 202 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 203 | }; |
| 204 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 205 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | struct nfs4_readdir_arg *readdir) |
| 207 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 208 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 211 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | readdir->cookie = 0; |
| 217 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 218 | if (cookie == 2) |
| 219 | return; |
| 220 | |
| 221 | /* |
| 222 | * NFSv4 servers do not return entries for '.' and '..' |
| 223 | * Therefore, we fake these entries here. We let '.' |
| 224 | * have cookie 0 and '..' have cookie 1. Note that |
| 225 | * when talking to the server, we always send cookie 0 |
| 226 | * instead of 1 or 2. |
| 227 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 228 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | if (cookie == 0) { |
| 231 | *p++ = xdr_one; /* next */ |
| 232 | *p++ = xdr_zero; /* cookie, first word */ |
| 233 | *p++ = xdr_one; /* cookie, second word */ |
| 234 | *p++ = xdr_one; /* entry len */ |
| 235 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 236 | p++; |
| 237 | *p++ = xdr_one; /* bitmap length */ |
| 238 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 239 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 240 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | *p++ = xdr_one; /* next */ |
| 244 | *p++ = xdr_zero; /* cookie, first word */ |
| 245 | *p++ = xdr_two; /* cookie, second word */ |
| 246 | *p++ = xdr_two; /* entry len */ |
| 247 | memcpy(p, "..\0\0", 4); /* entry */ |
| 248 | p++; |
| 249 | *p++ = xdr_one; /* bitmap length */ |
| 250 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 251 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 252 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | readdir->pgbase = (char *)p - (char *)start; |
| 255 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 256 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 259 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 260 | { |
| 261 | int res = 0; |
| 262 | |
| 263 | might_sleep(); |
| 264 | |
| 265 | if (*timeout <= 0) |
| 266 | *timeout = NFS4_POLL_RETRY_MIN; |
| 267 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 268 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 269 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 270 | if (fatal_signal_pending(current)) |
| 271 | res = -ERESTARTSYS; |
| 272 | *timeout <<= 1; |
| 273 | return res; |
| 274 | } |
| 275 | |
| 276 | /* This is the error handling routine for processes that are allowed |
| 277 | * to sleep. |
| 278 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 279 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 280 | { |
| 281 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 282 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 283 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 284 | int ret = errorcode; |
| 285 | |
| 286 | exception->retry = 0; |
| 287 | switch(errorcode) { |
| 288 | case 0: |
| 289 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 290 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 291 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 292 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 293 | exception->retry = 1; |
| 294 | return 0; |
| 295 | } |
| 296 | if (state == NULL) |
| 297 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 298 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 299 | if (ret < 0) |
| 300 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 301 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 302 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 303 | case -NFS4ERR_ADMIN_REVOKED: |
| 304 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 305 | if (state == NULL) |
| 306 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 307 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 308 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 309 | if (ret < 0) |
| 310 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 311 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 312 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 313 | if (state != NULL) { |
| 314 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 315 | if (ret < 0) |
| 316 | break; |
| 317 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 318 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 319 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 320 | nfs4_schedule_lease_recovery(clp); |
| 321 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 322 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 323 | case -NFS4ERR_BADSESSION: |
| 324 | case -NFS4ERR_BADSLOT: |
| 325 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 326 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 327 | case -NFS4ERR_DEADSESSION: |
| 328 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 329 | case -NFS4ERR_SEQ_MISORDERED: |
| 330 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 331 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 332 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 333 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 334 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 335 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 336 | if (exception->timeout > HZ) { |
| 337 | /* We have retried a decent amount, time to |
| 338 | * fail |
| 339 | */ |
| 340 | ret = -EBUSY; |
| 341 | break; |
| 342 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 343 | case -NFS4ERR_GRACE: |
| 344 | case -NFS4ERR_DELAY: |
| 345 | ret = nfs4_delay(server->client, &exception->timeout); |
| 346 | if (ret != 0) |
| 347 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 348 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 349 | case -NFS4ERR_OLD_STATEID: |
| 350 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 351 | break; |
| 352 | case -NFS4ERR_BADOWNER: |
| 353 | /* The following works around a Linux server bug! */ |
| 354 | case -NFS4ERR_BADNAME: |
| 355 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 356 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 357 | exception->retry = 1; |
| 358 | printk(KERN_WARNING "NFS: v4 server %s " |
| 359 | "does not accept raw " |
| 360 | "uid/gids. " |
| 361 | "Reenabling the idmapper.\n", |
| 362 | server->nfs_client->cl_hostname); |
| 363 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 364 | } |
| 365 | /* We failed to handle the error */ |
| 366 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 367 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 368 | ret = nfs4_wait_clnt_recover(clp); |
| 369 | if (ret == 0) |
| 370 | exception->retry = 1; |
| 371 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 375 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | spin_lock(&clp->cl_lock); |
| 378 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 379 | clp->cl_last_renewal = timestamp; |
| 380 | spin_unlock(&clp->cl_lock); |
| 381 | } |
| 382 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 383 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 384 | { |
| 385 | do_renew_lease(server->nfs_client, timestamp); |
| 386 | } |
| 387 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 388 | #if defined(CONFIG_NFS_V4_1) |
| 389 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 390 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 391 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 392 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 393 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 394 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 395 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 396 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 397 | /* just wake up the next guy waiting since |
| 398 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 399 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 400 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 401 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 402 | tbl = res->sr_slot->table; |
| 403 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 404 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 405 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 406 | /* Be nice to the server: try to ensure that the last transmitted |
| 407 | * value for highest_user_slotid <= target_highest_slotid |
| 408 | */ |
| 409 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 410 | send_new_highest_used_slotid = true; |
| 411 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 412 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 413 | send_new_highest_used_slotid = false; |
| 414 | goto out_unlock; |
| 415 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 416 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 417 | |
| 418 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 419 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 420 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 421 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 422 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 423 | if (send_new_highest_used_slotid) |
| 424 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 425 | } |
| 426 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 427 | static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 428 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 429 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 430 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 431 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 432 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 433 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 434 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 435 | /* don't increment the sequence number if the task wasn't sent */ |
| 436 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 437 | goto out; |
| 438 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 439 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 440 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 441 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 442 | if (slot->interrupted) { |
| 443 | slot->interrupted = 0; |
| 444 | interrupted = true; |
| 445 | } |
| 446 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 447 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 448 | switch (res->sr_status) { |
| 449 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 450 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 451 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 452 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 453 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 454 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 455 | if (res->sr_status_flags != 0) |
| 456 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 457 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 458 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 459 | case 1: |
| 460 | /* |
| 461 | * sr_status remains 1 if an RPC level error occurred. |
| 462 | * The server may or may not have processed the sequence |
| 463 | * operation.. |
| 464 | * Mark the slot as having hosted an interrupted RPC call. |
| 465 | */ |
| 466 | slot->interrupted = 1; |
| 467 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | case -NFS4ERR_DELAY: |
| 469 | /* The server detected a resend of the RPC call and |
| 470 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 471 | * of RFC5661. |
| 472 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 473 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 474 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 475 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 476 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 477 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 478 | case -NFS4ERR_BADSLOT: |
| 479 | /* |
| 480 | * The slot id we used was probably retired. Try again |
| 481 | * using a different slot id. |
| 482 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 483 | goto retry_nowait; |
| 484 | case -NFS4ERR_SEQ_MISORDERED: |
| 485 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 486 | * Was the last operation on this sequence interrupted? |
| 487 | * If so, retry after bumping the sequence number. |
| 488 | */ |
| 489 | if (interrupted) { |
| 490 | ++slot->seq_nr; |
| 491 | goto retry_nowait; |
| 492 | } |
| 493 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 494 | * Could this slot have been previously retired? |
| 495 | * If so, then the server may be expecting seq_nr = 1! |
| 496 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 497 | if (slot->seq_nr != 1) { |
| 498 | slot->seq_nr = 1; |
| 499 | goto retry_nowait; |
| 500 | } |
| 501 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 502 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 503 | ++slot->seq_nr; |
| 504 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 505 | default: |
| 506 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 507 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 508 | } |
| 509 | out: |
| 510 | /* The session may be reset by one of the error handlers. */ |
| 511 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 512 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 513 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 514 | retry_nowait: |
| 515 | if (rpc_restart_call_prepare(task)) { |
| 516 | task->tk_status = 0; |
| 517 | ret = 0; |
| 518 | } |
| 519 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 520 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 521 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 522 | goto out; |
| 523 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 524 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 525 | } |
| 526 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 527 | static int nfs4_sequence_done(struct rpc_task *task, |
| 528 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 529 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 530 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 531 | return 1; |
| 532 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 535 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 536 | struct nfs4_sequence_res *res, int cache_reply) |
| 537 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 538 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 539 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 540 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 541 | if (cache_reply) |
| 542 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 543 | res->sr_slot = NULL; |
| 544 | } |
| 545 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 546 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 547 | { |
| 548 | args->sa_privileged = 1; |
| 549 | } |
| 550 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 551 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 552 | struct nfs4_sequence_args *args, |
| 553 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 554 | struct rpc_task *task) |
| 555 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 556 | struct nfs4_slot *slot; |
| 557 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 558 | |
| 559 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 560 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 561 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 562 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 563 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 564 | tbl = &session->fc_slot_table; |
| 565 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 566 | task->tk_timeout = 0; |
| 567 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 568 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 569 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 570 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 571 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 572 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 573 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 574 | } |
| 575 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 576 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 577 | if (IS_ERR(slot)) { |
| 578 | /* If out of memory, try again in 1/4 second */ |
| 579 | if (slot == ERR_PTR(-ENOMEM)) |
| 580 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 581 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 582 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 583 | } |
| 584 | spin_unlock(&tbl->slot_tbl_lock); |
| 585 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 586 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 587 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 588 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 589 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 590 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 591 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 592 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 593 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 594 | /* |
| 595 | * sr_status is only set in decode_sequence, and so will remain |
| 596 | * set to 1 if an rpc level failure occurs. |
| 597 | */ |
| 598 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 599 | out_success: |
| 600 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 602 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 603 | /* Privileged tasks are queued with top priority */ |
| 604 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 605 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 606 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 607 | else |
| 608 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 609 | spin_unlock(&tbl->slot_tbl_lock); |
| 610 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 611 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 612 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 614 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | struct nfs4_sequence_args *args, |
| 616 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | struct rpc_task *task) |
| 618 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 619 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 620 | int ret = 0; |
| 621 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 622 | if (session == NULL) { |
| 623 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 625 | } |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 626 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 627 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 628 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 629 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 630 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 631 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | out: |
| 633 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 634 | return ret; |
| 635 | } |
| 636 | |
| 637 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 638 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 639 | struct nfs4_sequence_args *seq_args; |
| 640 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 641 | }; |
| 642 | |
| 643 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 644 | { |
| 645 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 646 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 647 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 648 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 649 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 650 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 651 | } |
| 652 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 653 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 654 | { |
| 655 | struct nfs41_call_sync_data *data = calldata; |
| 656 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 657 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 660 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 662 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | }; |
| 664 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 665 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 666 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | struct rpc_message *msg, |
| 668 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 669 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 670 | { |
| 671 | int ret; |
| 672 | struct rpc_task *task; |
| 673 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 674 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 675 | .seq_args = args, |
| 676 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | }; |
| 678 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 679 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | .rpc_message = msg, |
| 681 | .callback_ops = &nfs41_call_sync_ops, |
| 682 | .callback_data = &data |
| 683 | }; |
| 684 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 685 | task = rpc_run_task(&task_setup); |
| 686 | if (IS_ERR(task)) |
| 687 | ret = PTR_ERR(task); |
| 688 | else { |
| 689 | ret = task->tk_status; |
| 690 | rpc_put_task(task); |
| 691 | } |
| 692 | return ret; |
| 693 | } |
| 694 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 695 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 696 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 697 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 698 | struct nfs4_sequence_res *res, int cache_reply) |
| 699 | { |
| 700 | } |
| 701 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 702 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 703 | { |
| 704 | } |
| 705 | |
| 706 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 707 | static int nfs4_sequence_done(struct rpc_task *task, |
| 708 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 709 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 710 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 711 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 712 | #endif /* CONFIG_NFS_V4_1 */ |
| 713 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 714 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 715 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 716 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 717 | struct rpc_message *msg, |
| 718 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 719 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 720 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 721 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 724 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 725 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 726 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 727 | struct rpc_message *msg, |
| 728 | struct nfs4_sequence_args *args, |
| 729 | struct nfs4_sequence_res *res, |
| 730 | int cache_reply) |
| 731 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 732 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 733 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 734 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 735 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 736 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 737 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 739 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 741 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 742 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 743 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 744 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 745 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 746 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 747 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 750 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 751 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 752 | struct nfs_openargs o_arg; |
| 753 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 754 | struct nfs_open_confirmargs c_arg; |
| 755 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 756 | struct nfs4_string owner_name; |
| 757 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 760 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 762 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 764 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 765 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 766 | int rpc_status; |
| 767 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 768 | }; |
| 769 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 770 | |
| 771 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 772 | { |
| 773 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 774 | p->o_res.seqid = p->o_arg.seqid; |
| 775 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 776 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 777 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 778 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 779 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 780 | } |
| 781 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 782 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 783 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 784 | const struct iattr *attrs, |
| 785 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 786 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 787 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 788 | struct inode *dir = parent->d_inode; |
| 789 | struct nfs_server *server = NFS_SERVER(dir); |
| 790 | struct nfs4_opendata *p; |
| 791 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 792 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 793 | if (p == NULL) |
| 794 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 795 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | if (p->o_arg.seqid == NULL) |
| 797 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 798 | nfs_sb_active(dentry->d_sb); |
| 799 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 800 | p->dir = parent; |
| 801 | p->owner = sp; |
| 802 | atomic_inc(&sp->so_count); |
| 803 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 804 | p->o_arg.open_flags = flags; |
| 805 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 806 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 807 | * will return permission denied for all bits until close */ |
| 808 | if (!(flags & O_EXCL)) { |
| 809 | /* ask server to check for all possible rights as results |
| 810 | * are cached */ |
| 811 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 812 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 813 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 814 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 815 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 816 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 817 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | p->o_arg.server = server; |
| 819 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 820 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 822 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 823 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 824 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | p->o_arg.u.attrs = &p->attrs; |
| 826 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 827 | |
| 828 | verf[0] = jiffies; |
| 829 | verf[1] = current->pid; |
| 830 | memcpy(p->o_arg.u.verifier.data, verf, |
| 831 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 833 | p->c_arg.fh = &p->o_res.fh; |
| 834 | p->c_arg.stateid = &p->o_res.stateid; |
| 835 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 836 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 837 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 838 | return p; |
| 839 | err_free: |
| 840 | kfree(p); |
| 841 | err: |
| 842 | dput(parent); |
| 843 | return NULL; |
| 844 | } |
| 845 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 846 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 847 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 848 | struct nfs4_opendata *p = container_of(kref, |
| 849 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 850 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 851 | |
| 852 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 853 | if (p->state != NULL) |
| 854 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 855 | nfs4_put_state_owner(p->owner); |
| 856 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 857 | dput(p->dentry); |
| 858 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 859 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 860 | kfree(p); |
| 861 | } |
| 862 | |
| 863 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 864 | { |
| 865 | if (p != NULL) |
| 866 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 867 | } |
| 868 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 869 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 870 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 871 | int ret; |
| 872 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 873 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 874 | return ret; |
| 875 | } |
| 876 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 877 | 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] | 878 | { |
| 879 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 880 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 881 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 882 | goto out; |
| 883 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 884 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 885 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 886 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 887 | break; |
| 888 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 889 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 890 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 891 | break; |
| 892 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 893 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 894 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 895 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 896 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 897 | return ret; |
| 898 | } |
| 899 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 901 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 902 | if (delegation == NULL) |
| 903 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 904 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 905 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 906 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 907 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 908 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 909 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 910 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 911 | return 1; |
| 912 | } |
| 913 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 914 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 915 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 916 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 917 | case FMODE_WRITE: |
| 918 | state->n_wronly++; |
| 919 | break; |
| 920 | case FMODE_READ: |
| 921 | state->n_rdonly++; |
| 922 | break; |
| 923 | case FMODE_READ|FMODE_WRITE: |
| 924 | state->n_rdwr++; |
| 925 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 926 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 929 | 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] | 930 | { |
| 931 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 932 | nfs4_stateid_copy(&state->stateid, stateid); |
| 933 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 934 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 935 | case FMODE_READ: |
| 936 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 937 | break; |
| 938 | case FMODE_WRITE: |
| 939 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 940 | break; |
| 941 | case FMODE_READ|FMODE_WRITE: |
| 942 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 943 | } |
| 944 | } |
| 945 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | 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] | 947 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 948 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 949 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 950 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 951 | } |
| 952 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 953 | 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] | 954 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 955 | /* |
| 956 | * Protect the call to nfs4_state_set_mode_locked and |
| 957 | * serialise the stateid update |
| 958 | */ |
| 959 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 960 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 961 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 962 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 963 | } |
| 964 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 965 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 966 | write_sequnlock(&state->seqlock); |
| 967 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 968 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 969 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 972 | 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] | 973 | { |
| 974 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 975 | struct nfs_delegation *deleg_cur; |
| 976 | int ret = 0; |
| 977 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 979 | |
| 980 | rcu_read_lock(); |
| 981 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 982 | if (deleg_cur == NULL) |
| 983 | goto no_delegation; |
| 984 | |
| 985 | spin_lock(&deleg_cur->lock); |
| 986 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 987 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 988 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 989 | goto no_delegation_unlock; |
| 990 | |
| 991 | if (delegation == NULL) |
| 992 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 993 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 994 | goto no_delegation_unlock; |
| 995 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 996 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 997 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 998 | ret = 1; |
| 999 | no_delegation_unlock: |
| 1000 | spin_unlock(&deleg_cur->lock); |
| 1001 | no_delegation: |
| 1002 | rcu_read_unlock(); |
| 1003 | |
| 1004 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1006 | ret = 1; |
| 1007 | } |
| 1008 | |
| 1009 | return ret; |
| 1010 | } |
| 1011 | |
| 1012 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1014 | { |
| 1015 | struct nfs_delegation *delegation; |
| 1016 | |
| 1017 | rcu_read_lock(); |
| 1018 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1019 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1020 | rcu_read_unlock(); |
| 1021 | return; |
| 1022 | } |
| 1023 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1024 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | } |
| 1026 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1027 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1028 | { |
| 1029 | struct nfs4_state *state = opendata->state; |
| 1030 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1031 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1032 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1033 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1034 | nfs4_stateid stateid; |
| 1035 | int ret = -EAGAIN; |
| 1036 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1037 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1038 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1039 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | if (can_open_cached(state, fmode, open_mode)) { |
| 1041 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1042 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1043 | goto out_return_state; |
| 1044 | } |
| 1045 | spin_unlock(&state->owner->so_lock); |
| 1046 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1047 | rcu_read_lock(); |
| 1048 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1049 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1050 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1051 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1052 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1053 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1054 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1055 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1056 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1057 | if (ret != 0) |
| 1058 | goto out; |
| 1059 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1060 | |
| 1061 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1062 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1063 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1064 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1065 | out: |
| 1066 | return ERR_PTR(ret); |
| 1067 | out_return_state: |
| 1068 | atomic_inc(&state->count); |
| 1069 | return state; |
| 1070 | } |
| 1071 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1072 | static void |
| 1073 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1074 | { |
| 1075 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1076 | struct nfs_delegation *delegation; |
| 1077 | int delegation_flags = 0; |
| 1078 | |
| 1079 | rcu_read_lock(); |
| 1080 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1081 | if (delegation) |
| 1082 | delegation_flags = delegation->flags; |
| 1083 | rcu_read_unlock(); |
| 1084 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1085 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1086 | "returning a delegation for " |
| 1087 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1088 | clp->cl_hostname); |
| 1089 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1090 | nfs_inode_set_delegation(state->inode, |
| 1091 | data->owner->so_cred, |
| 1092 | &data->o_res); |
| 1093 | else |
| 1094 | nfs_inode_reclaim_delegation(state->inode, |
| 1095 | data->owner->so_cred, |
| 1096 | &data->o_res); |
| 1097 | } |
| 1098 | |
| 1099 | /* |
| 1100 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1101 | * and update the nfs4_state. |
| 1102 | */ |
| 1103 | static struct nfs4_state * |
| 1104 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1105 | { |
| 1106 | struct inode *inode = data->state->inode; |
| 1107 | struct nfs4_state *state = data->state; |
| 1108 | int ret; |
| 1109 | |
| 1110 | if (!data->rpc_done) { |
| 1111 | ret = data->rpc_status; |
| 1112 | goto err; |
| 1113 | } |
| 1114 | |
| 1115 | ret = -ESTALE; |
| 1116 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1117 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1118 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1119 | goto err; |
| 1120 | |
| 1121 | ret = -ENOMEM; |
| 1122 | state = nfs4_get_open_state(inode, data->owner); |
| 1123 | if (state == NULL) |
| 1124 | goto err; |
| 1125 | |
| 1126 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1127 | if (ret) |
| 1128 | goto err; |
| 1129 | |
| 1130 | if (data->o_res.delegation_type != 0) |
| 1131 | nfs4_opendata_check_deleg(data, state); |
| 1132 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1133 | data->o_arg.fmode); |
| 1134 | |
| 1135 | return state; |
| 1136 | err: |
| 1137 | return ERR_PTR(ret); |
| 1138 | |
| 1139 | } |
| 1140 | |
| 1141 | static struct nfs4_state * |
| 1142 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1143 | { |
| 1144 | struct inode *inode; |
| 1145 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1146 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1147 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1148 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1149 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1150 | goto out; |
| 1151 | } |
| 1152 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1153 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1154 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1155 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1156 | 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] | 1157 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1158 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1159 | goto err; |
| 1160 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1161 | state = nfs4_get_open_state(inode, data->owner); |
| 1162 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1163 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1164 | if (data->o_res.delegation_type != 0) |
| 1165 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1166 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1167 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1168 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1169 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1170 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1171 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1172 | err_put_inode: |
| 1173 | iput(inode); |
| 1174 | err: |
| 1175 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1178 | static struct nfs4_state * |
| 1179 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1180 | { |
| 1181 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1182 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1183 | return _nfs4_opendata_to_nfs4_state(data); |
| 1184 | } |
| 1185 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1186 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1187 | { |
| 1188 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1189 | struct nfs_open_context *ctx; |
| 1190 | |
| 1191 | spin_lock(&state->inode->i_lock); |
| 1192 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1193 | if (ctx->state != state) |
| 1194 | continue; |
| 1195 | get_nfs_open_context(ctx); |
| 1196 | spin_unlock(&state->inode->i_lock); |
| 1197 | return ctx; |
| 1198 | } |
| 1199 | spin_unlock(&state->inode->i_lock); |
| 1200 | return ERR_PTR(-ENOENT); |
| 1201 | } |
| 1202 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1203 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1204 | { |
| 1205 | struct nfs4_opendata *opendata; |
| 1206 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1207 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1208 | if (opendata == NULL) |
| 1209 | return ERR_PTR(-ENOMEM); |
| 1210 | opendata->state = state; |
| 1211 | atomic_inc(&state->count); |
| 1212 | return opendata; |
| 1213 | } |
| 1214 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1215 | 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] | 1216 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1217 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | int ret; |
| 1219 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1220 | opendata->o_arg.open_flags = 0; |
| 1221 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1222 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1223 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1224 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1225 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1226 | if (ret != 0) |
| 1227 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1228 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1229 | if (IS_ERR(newstate)) |
| 1230 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1231 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1232 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1237 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1238 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1239 | int ret; |
| 1240 | |
| 1241 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1242 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1243 | smp_rmb(); |
| 1244 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1245 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1246 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1247 | if (ret != 0) |
| 1248 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1249 | if (newstate != state) |
| 1250 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1251 | } |
| 1252 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1253 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1254 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1255 | if (ret != 0) |
| 1256 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1257 | if (newstate != state) |
| 1258 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1259 | } |
| 1260 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1261 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1262 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1263 | if (ret != 0) |
| 1264 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1265 | if (newstate != state) |
| 1266 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1267 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1268 | /* |
| 1269 | * We may have performed cached opens for all three recoveries. |
| 1270 | * Check if we need to update the current stateid. |
| 1271 | */ |
| 1272 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1273 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1274 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1275 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1276 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1277 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1278 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1279 | return 0; |
| 1280 | } |
| 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | /* |
| 1283 | * OPEN_RECLAIM: |
| 1284 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1286 | 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] | 1287 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1288 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1289 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1290 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | int status; |
| 1292 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1293 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1294 | if (IS_ERR(opendata)) |
| 1295 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1296 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1297 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1298 | rcu_read_lock(); |
| 1299 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1300 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1301 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1302 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1303 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1304 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1305 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | return status; |
| 1307 | } |
| 1308 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1309 | 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] | 1310 | { |
| 1311 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1312 | struct nfs4_exception exception = { }; |
| 1313 | int err; |
| 1314 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1315 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1316 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1317 | break; |
| 1318 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | } while (exception.retry); |
| 1320 | return err; |
| 1321 | } |
| 1322 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1323 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1324 | { |
| 1325 | struct nfs_open_context *ctx; |
| 1326 | int ret; |
| 1327 | |
| 1328 | ctx = nfs4_state_find_open_context(state); |
| 1329 | if (IS_ERR(ctx)) |
| 1330 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1331 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1332 | put_nfs_open_context(ctx); |
| 1333 | return ret; |
| 1334 | } |
| 1335 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1336 | 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] | 1337 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1338 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1339 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1341 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1342 | if (IS_ERR(opendata)) |
| 1343 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1344 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1345 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1346 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1347 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1348 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1351 | 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] | 1352 | { |
| 1353 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1354 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | int err; |
| 1356 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1357 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | switch (err) { |
| 1359 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1360 | case -ENOENT: |
| 1361 | case -ESTALE: |
| 1362 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1363 | case -NFS4ERR_BADSESSION: |
| 1364 | case -NFS4ERR_BADSLOT: |
| 1365 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1366 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1367 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1368 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1369 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1370 | err = -EAGAIN; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1371 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | case -NFS4ERR_STALE_CLIENTID: |
| 1373 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1374 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | case -NFS4ERR_EXPIRED: |
| 1376 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1377 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1378 | err = -EAGAIN; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1379 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1380 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1381 | case -NFS4ERR_ADMIN_REVOKED: |
| 1382 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1383 | nfs_inode_find_state_and_recover(state->inode, |
| 1384 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1385 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1386 | case -ENOMEM: |
| 1387 | err = 0; |
| 1388 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1390 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | err = nfs4_handle_exception(server, err, &exception); |
| 1392 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1393 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | return err; |
| 1395 | } |
| 1396 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1397 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1398 | { |
| 1399 | struct nfs4_opendata *data = calldata; |
| 1400 | |
| 1401 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1402 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1403 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1404 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1405 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1406 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1407 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static void nfs4_open_confirm_release(void *calldata) |
| 1411 | { |
| 1412 | struct nfs4_opendata *data = calldata; |
| 1413 | struct nfs4_state *state = NULL; |
| 1414 | |
| 1415 | /* If this request hasn't been cancelled, do nothing */ |
| 1416 | if (data->cancelled == 0) |
| 1417 | goto out_free; |
| 1418 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1419 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1420 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1421 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1422 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1423 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1424 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1425 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1429 | .rpc_call_done = nfs4_open_confirm_done, |
| 1430 | .rpc_release = nfs4_open_confirm_release, |
| 1431 | }; |
| 1432 | |
| 1433 | /* |
| 1434 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1435 | */ |
| 1436 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1437 | { |
| 1438 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1439 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1440 | struct rpc_message msg = { |
| 1441 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1442 | .rpc_argp = &data->c_arg, |
| 1443 | .rpc_resp = &data->c_res, |
| 1444 | .rpc_cred = data->owner->so_cred, |
| 1445 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1446 | struct rpc_task_setup task_setup_data = { |
| 1447 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1448 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1449 | .callback_ops = &nfs4_open_confirm_ops, |
| 1450 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1451 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1452 | .flags = RPC_TASK_ASYNC, |
| 1453 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | int status; |
| 1455 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1456 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1457 | data->rpc_done = 0; |
| 1458 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1459 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1460 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1461 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1462 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1463 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1464 | if (status != 0) { |
| 1465 | data->cancelled = 1; |
| 1466 | smp_wmb(); |
| 1467 | } else |
| 1468 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1469 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | return status; |
| 1471 | } |
| 1472 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1473 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | struct nfs4_opendata *data = calldata; |
| 1476 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1477 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1478 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1479 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1480 | /* |
| 1481 | * Check if we still need to send an OPEN call, or if we can use |
| 1482 | * a delegation instead. |
| 1483 | */ |
| 1484 | if (data->state != NULL) { |
| 1485 | struct nfs_delegation *delegation; |
| 1486 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1487 | 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] | 1488 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1489 | rcu_read_lock(); |
| 1490 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1491 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1492 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1493 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1494 | rcu_read_unlock(); |
| 1495 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1496 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1497 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1498 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1499 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1500 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1501 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1502 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1503 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1504 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1505 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1506 | &data->o_res.seq_res, |
| 1507 | task) != 0) |
| 1508 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1509 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1510 | unlock_no_action: |
| 1511 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1512 | out_no_action: |
| 1513 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1514 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1515 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1518 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1519 | { |
| 1520 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1522 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1523 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1524 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1525 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1526 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1527 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1528 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1529 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1530 | case S_IFREG: |
| 1531 | break; |
| 1532 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1534 | break; |
| 1535 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1536 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1537 | break; |
| 1538 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1539 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1540 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1541 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1542 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1543 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1544 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1545 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1546 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1547 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1548 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1549 | static void nfs4_open_release(void *calldata) |
| 1550 | { |
| 1551 | struct nfs4_opendata *data = calldata; |
| 1552 | struct nfs4_state *state = NULL; |
| 1553 | |
| 1554 | /* If this request hasn't been cancelled, do nothing */ |
| 1555 | if (data->cancelled == 0) |
| 1556 | goto out_free; |
| 1557 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1558 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1559 | goto out_free; |
| 1560 | /* In case we need an open_confirm, no cleanup! */ |
| 1561 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1562 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1563 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1564 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1565 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1566 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1567 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1571 | .rpc_call_prepare = nfs4_open_prepare, |
| 1572 | .rpc_call_done = nfs4_open_done, |
| 1573 | .rpc_release = nfs4_open_release, |
| 1574 | }; |
| 1575 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1576 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1577 | { |
| 1578 | struct inode *dir = data->dir->d_inode; |
| 1579 | struct nfs_server *server = NFS_SERVER(dir); |
| 1580 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1581 | struct nfs_openres *o_res = &data->o_res; |
| 1582 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1583 | struct rpc_message msg = { |
| 1584 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1585 | .rpc_argp = o_arg, |
| 1586 | .rpc_resp = o_res, |
| 1587 | .rpc_cred = data->owner->so_cred, |
| 1588 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1589 | struct rpc_task_setup task_setup_data = { |
| 1590 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1591 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1592 | .callback_ops = &nfs4_open_ops, |
| 1593 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1594 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1595 | .flags = RPC_TASK_ASYNC, |
| 1596 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1597 | int status; |
| 1598 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1599 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1600 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1601 | data->rpc_done = 0; |
| 1602 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1603 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1604 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1605 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1606 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1607 | if (IS_ERR(task)) |
| 1608 | return PTR_ERR(task); |
| 1609 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1610 | if (status != 0) { |
| 1611 | data->cancelled = 1; |
| 1612 | smp_wmb(); |
| 1613 | } else |
| 1614 | status = data->rpc_status; |
| 1615 | rpc_put_task(task); |
| 1616 | |
| 1617 | return status; |
| 1618 | } |
| 1619 | |
| 1620 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1621 | { |
| 1622 | struct inode *dir = data->dir->d_inode; |
| 1623 | struct nfs_openres *o_res = &data->o_res; |
| 1624 | int status; |
| 1625 | |
| 1626 | status = nfs4_run_open_task(data, 1); |
| 1627 | if (status != 0 || !data->rpc_done) |
| 1628 | return status; |
| 1629 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1630 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1631 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1632 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1633 | status = _nfs4_proc_open_confirm(data); |
| 1634 | if (status != 0) |
| 1635 | return status; |
| 1636 | } |
| 1637 | |
| 1638 | return status; |
| 1639 | } |
| 1640 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1641 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1642 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1643 | struct nfs4_state *state, fmode_t fmode, |
| 1644 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1645 | { |
| 1646 | struct nfs_access_entry cache; |
| 1647 | u32 mask; |
| 1648 | |
| 1649 | /* access call failed or for some reason the server doesn't |
| 1650 | * support any access modes -- defer access call until later */ |
| 1651 | if (opendata->o_res.access_supported == 0) |
| 1652 | return 0; |
| 1653 | |
| 1654 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1655 | /* 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] | 1656 | * write mode bits, but POSIX allows the creating process to write. |
| 1657 | * use openflags to check for exec, because fmode won't |
| 1658 | * always have FMODE_EXEC set when file open for exec. */ |
| 1659 | if (openflags & __FMODE_EXEC) { |
| 1660 | /* ONLY check for exec rights */ |
| 1661 | mask = MAY_EXEC; |
| 1662 | } else if (fmode & FMODE_READ) |
| 1663 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1664 | |
| 1665 | cache.cred = cred; |
| 1666 | cache.jiffies = jiffies; |
| 1667 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1668 | nfs_access_add_cache(state->inode, &cache); |
| 1669 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1670 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1671 | return 0; |
| 1672 | |
| 1673 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1674 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1675 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1678 | /* |
| 1679 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1680 | */ |
| 1681 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1682 | { |
| 1683 | struct inode *dir = data->dir->d_inode; |
| 1684 | struct nfs_server *server = NFS_SERVER(dir); |
| 1685 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1686 | struct nfs_openres *o_res = &data->o_res; |
| 1687 | int status; |
| 1688 | |
| 1689 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1690 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1691 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1692 | if (status != 0) { |
| 1693 | if (status == -NFS4ERR_BADNAME && |
| 1694 | !(o_arg->open_flags & O_CREAT)) |
| 1695 | return -ENOENT; |
| 1696 | return status; |
| 1697 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1698 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1699 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1700 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1701 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1702 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1703 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1704 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1706 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1708 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | } |
| 1710 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1711 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1712 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1715 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1716 | { |
| 1717 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1718 | } |
| 1719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | /* |
| 1721 | * OPEN_EXPIRED: |
| 1722 | * reclaim state on the server after a network partition. |
| 1723 | * Assumes caller holds the appropriate lock |
| 1724 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1725 | 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] | 1726 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1727 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1728 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1730 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1731 | if (IS_ERR(opendata)) |
| 1732 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1733 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1734 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1735 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1736 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1737 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1740 | 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] | 1741 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1742 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1743 | struct nfs4_exception exception = { }; |
| 1744 | int err; |
| 1745 | |
| 1746 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1747 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1748 | switch (err) { |
| 1749 | default: |
| 1750 | goto out; |
| 1751 | case -NFS4ERR_GRACE: |
| 1752 | case -NFS4ERR_DELAY: |
| 1753 | nfs4_handle_exception(server, err, &exception); |
| 1754 | err = 0; |
| 1755 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1756 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1757 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1758 | return err; |
| 1759 | } |
| 1760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1762 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1764 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1766 | ctx = nfs4_state_find_open_context(state); |
| 1767 | if (IS_ERR(ctx)) |
| 1768 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1769 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1770 | put_nfs_open_context(ctx); |
| 1771 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1774 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1775 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1776 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1777 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1778 | nfs4_stateid *stateid = &state->stateid; |
| 1779 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1780 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1781 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1782 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1783 | return; |
| 1784 | |
| 1785 | status = nfs41_test_stateid(server, stateid); |
| 1786 | if (status != NFS_OK) { |
| 1787 | /* Free the stateid unless the server explicitly |
| 1788 | * informs us the stateid is unrecognized. */ |
| 1789 | if (status != -NFS4ERR_BAD_STATEID) |
| 1790 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1791 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1792 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1793 | write_seqlock(&state->seqlock); |
| 1794 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1795 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1796 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1802 | * |
| 1803 | * @state: NFSv4 state for an inode |
| 1804 | * |
| 1805 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1806 | * Otherwise a negative NFS4ERR value is returned. |
| 1807 | */ |
| 1808 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1809 | { |
| 1810 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1811 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1812 | int status; |
| 1813 | |
| 1814 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1815 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1816 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1817 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1818 | return -NFS4ERR_BAD_STATEID; |
| 1819 | |
| 1820 | status = nfs41_test_stateid(server, stateid); |
| 1821 | if (status != NFS_OK) { |
| 1822 | /* Free the stateid unless the server explicitly |
| 1823 | * informs us the stateid is unrecognized. */ |
| 1824 | if (status != -NFS4ERR_BAD_STATEID) |
| 1825 | nfs41_free_stateid(server, stateid); |
| 1826 | |
| 1827 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1828 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1829 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1830 | } |
| 1831 | return status; |
| 1832 | } |
| 1833 | |
| 1834 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1835 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1836 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1837 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1838 | nfs41_clear_delegation_stateid(state); |
| 1839 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1840 | if (status != NFS_OK) |
| 1841 | status = nfs4_open_expired(sp, state); |
| 1842 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1843 | } |
| 1844 | #endif |
| 1845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1847 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1848 | * fields corresponding to attributes that were used to store the verifier. |
| 1849 | * Make sure we clobber those fields in the later setattr call |
| 1850 | */ |
| 1851 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1852 | { |
| 1853 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1854 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1855 | sattr->ia_valid |= ATTR_ATIME; |
| 1856 | |
| 1857 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1858 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1859 | sattr->ia_valid |= ATTR_MTIME; |
| 1860 | } |
| 1861 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1862 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1863 | fmode_t fmode, |
| 1864 | int flags, |
| 1865 | struct nfs4_state **res) |
| 1866 | { |
| 1867 | struct nfs4_state_owner *sp = opendata->owner; |
| 1868 | struct nfs_server *server = sp->so_server; |
| 1869 | struct nfs4_state *state; |
| 1870 | unsigned int seq; |
| 1871 | int ret; |
| 1872 | |
| 1873 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1874 | |
| 1875 | ret = _nfs4_proc_open(opendata); |
| 1876 | if (ret != 0) |
| 1877 | goto out; |
| 1878 | |
| 1879 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1880 | ret = PTR_ERR(state); |
| 1881 | if (IS_ERR(state)) |
| 1882 | goto out; |
| 1883 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1884 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1885 | |
| 1886 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 1887 | if (ret != 0) |
| 1888 | goto out; |
| 1889 | |
| 1890 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 1891 | nfs4_schedule_stateid_recovery(server, state); |
| 1892 | nfs4_wait_clnt_recover(server->nfs_client); |
| 1893 | } |
| 1894 | *res = state; |
| 1895 | out: |
| 1896 | return ret; |
| 1897 | } |
| 1898 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1899 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1900 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1902 | static int _nfs4_do_open(struct inode *dir, |
| 1903 | struct dentry *dentry, |
| 1904 | fmode_t fmode, |
| 1905 | int flags, |
| 1906 | struct iattr *sattr, |
| 1907 | struct rpc_cred *cred, |
| 1908 | struct nfs4_state **res, |
| 1909 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | { |
| 1911 | struct nfs4_state_owner *sp; |
| 1912 | struct nfs4_state *state = NULL; |
| 1913 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1914 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1915 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | |
| 1917 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1919 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1920 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1922 | goto out_err; |
| 1923 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1924 | status = nfs4_recover_expired_lease(server); |
| 1925 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1926 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1927 | if (dentry->d_inode != NULL) |
| 1928 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1929 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1930 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1931 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1932 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1934 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1935 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1936 | if (!opendata->f_attr.mdsthreshold) |
| 1937 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1938 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1939 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1940 | if (dentry->d_inode != NULL) |
| 1941 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1942 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1943 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1944 | if (status != 0) |
| 1945 | goto err_opendata_put; |
| 1946 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1947 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1948 | nfs4_exclusive_attrset(opendata, sattr); |
| 1949 | |
| 1950 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1951 | status = nfs4_do_setattr(state->inode, cred, |
| 1952 | opendata->o_res.f_attr, sattr, |
| 1953 | state); |
| 1954 | if (status == 0) |
| 1955 | nfs_setattr_update_inode(state->inode, sattr); |
| 1956 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1957 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1958 | |
| 1959 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1960 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1961 | else |
| 1962 | kfree(opendata->f_attr.mdsthreshold); |
| 1963 | opendata->f_attr.mdsthreshold = NULL; |
| 1964 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1965 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | *res = state; |
| 1968 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1969 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1970 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1971 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1972 | err_put_state_owner: |
| 1973 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | *res = NULL; |
| 1976 | return status; |
| 1977 | } |
| 1978 | |
| 1979 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1980 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1981 | struct dentry *dentry, |
| 1982 | fmode_t fmode, |
| 1983 | int flags, |
| 1984 | struct iattr *sattr, |
| 1985 | struct rpc_cred *cred, |
| 1986 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | { |
| 1988 | struct nfs4_exception exception = { }; |
| 1989 | struct nfs4_state *res; |
| 1990 | int status; |
| 1991 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1992 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1994 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1995 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | if (status == 0) |
| 1997 | break; |
| 1998 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1999 | * book-keeping w.r.t. state-changing operations |
| 2000 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2001 | * It is actually a sign of a bug on the client or on the server. |
| 2002 | * |
| 2003 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2004 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | * have unhashed the old state_owner for us, and that we can |
| 2006 | * therefore safely retry using a new one. We should still warn |
| 2007 | * the user though... |
| 2008 | */ |
| 2009 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2010 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2011 | " returned a bad sequence-id error!\n", |
| 2012 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | exception.retry = 1; |
| 2014 | continue; |
| 2015 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2016 | /* |
| 2017 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2018 | * state before it received the OPEN_CONFIRM. |
| 2019 | * Recover by retrying the request as per the discussion |
| 2020 | * on Page 181 of RFC3530. |
| 2021 | */ |
| 2022 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2023 | exception.retry = 1; |
| 2024 | continue; |
| 2025 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2026 | if (status == -EAGAIN) { |
| 2027 | /* We must have found a delegation */ |
| 2028 | exception.retry = 1; |
| 2029 | continue; |
| 2030 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2032 | status, &exception)); |
| 2033 | } while (exception.retry); |
| 2034 | return res; |
| 2035 | } |
| 2036 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2037 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2038 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2039 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2041 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2043 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | .iap = sattr, |
| 2045 | .server = server, |
| 2046 | .bitmask = server->attr_bitmask, |
| 2047 | }; |
| 2048 | struct nfs_setattrres res = { |
| 2049 | .fattr = fattr, |
| 2050 | .server = server, |
| 2051 | }; |
| 2052 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2053 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2054 | .rpc_argp = &arg, |
| 2055 | .rpc_resp = &res, |
| 2056 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2058 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2059 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2061 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2063 | if (state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2064 | struct nfs_lockowner lockowner = { |
| 2065 | .l_owner = current->files, |
| 2066 | .l_pid = current->tgid, |
| 2067 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2068 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2069 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2070 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2071 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2072 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2073 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2074 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2076 | 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] | 2077 | if (status == 0 && state != NULL) |
| 2078 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2079 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2082 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2083 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2084 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2086 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2087 | struct nfs4_exception exception = { |
| 2088 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2089 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2090 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | int err; |
| 2092 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2093 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2094 | switch (err) { |
| 2095 | case -NFS4ERR_OPENMODE: |
| 2096 | if (state && !(state->state & FMODE_WRITE)) { |
| 2097 | err = -EBADF; |
| 2098 | if (sattr->ia_valid & ATTR_OPEN) |
| 2099 | err = -EACCES; |
| 2100 | goto out; |
| 2101 | } |
| 2102 | } |
| 2103 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2105 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | return err; |
| 2107 | } |
| 2108 | |
| 2109 | struct nfs4_closedata { |
| 2110 | struct inode *inode; |
| 2111 | struct nfs4_state *state; |
| 2112 | struct nfs_closeargs arg; |
| 2113 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2114 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2115 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2116 | bool roc; |
| 2117 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | }; |
| 2119 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2120 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2121 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2122 | struct nfs4_closedata *calldata = data; |
| 2123 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2124 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2125 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2126 | if (calldata->roc) |
| 2127 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2128 | nfs4_put_open_state(calldata->state); |
| 2129 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2130 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2131 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2132 | kfree(calldata); |
| 2133 | } |
| 2134 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2135 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2136 | fmode_t fmode) |
| 2137 | { |
| 2138 | spin_lock(&state->owner->so_lock); |
| 2139 | if (!(fmode & FMODE_READ)) |
| 2140 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2141 | if (!(fmode & FMODE_WRITE)) |
| 2142 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2143 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2144 | spin_unlock(&state->owner->so_lock); |
| 2145 | } |
| 2146 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2147 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2149 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2152 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2153 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2154 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2155 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | /* hmm. we are done with the inode, and in the process of freeing |
| 2157 | * the state_owner. we keep this around to process errors |
| 2158 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | switch (task->tk_status) { |
| 2160 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2161 | if (calldata->roc) |
| 2162 | pnfs_roc_set_barrier(state->inode, |
| 2163 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2164 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2165 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2166 | nfs4_close_clear_stateid_flags(state, |
| 2167 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | break; |
| 2169 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2170 | case -NFS4ERR_OLD_STATEID: |
| 2171 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2173 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2174 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2176 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2177 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2179 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2180 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2181 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2184 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2186 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2187 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2188 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2189 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2190 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2191 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2192 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2193 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2194 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2195 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2196 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2197 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2198 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2199 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2200 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2201 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2202 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2203 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2204 | } |
| 2205 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2206 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2207 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2208 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2209 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2210 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2211 | if (!nfs4_valid_open_stateid(state)) |
| 2212 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2213 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2214 | |
| 2215 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2216 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2217 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2218 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2219 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2220 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2221 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2222 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2223 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2224 | goto out_wait; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2225 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2226 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2227 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2228 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2229 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2230 | &calldata->arg.seq_args, |
| 2231 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2232 | task) != 0) |
| 2233 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2234 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2235 | return; |
| 2236 | out_no_action: |
| 2237 | task->tk_action = NULL; |
| 2238 | out_wait: |
| 2239 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2242 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2243 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2244 | .rpc_call_done = nfs4_close_done, |
| 2245 | .rpc_release = nfs4_free_closedata, |
| 2246 | }; |
| 2247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | /* |
| 2249 | * It is possible for data to be read/written from a mem-mapped file |
| 2250 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2251 | * This means that we can't safely call nfsv4 close on a file until |
| 2252 | * the inode is cleared. This in turn means that we are not good |
| 2253 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2254 | * share state even when we are done with one of the three share |
| 2255 | * stateid's in the inode. |
| 2256 | * |
| 2257 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2258 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2259 | 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] | 2260 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2261 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2263 | struct nfs4_state_owner *sp = state->owner; |
| 2264 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2265 | struct rpc_message msg = { |
| 2266 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2267 | .rpc_cred = state->owner->so_cred, |
| 2268 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2269 | struct rpc_task_setup task_setup_data = { |
| 2270 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2271 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2272 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2273 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2274 | .flags = RPC_TASK_ASYNC, |
| 2275 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2276 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2278 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2280 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2281 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2282 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2284 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2285 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2287 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2288 | if (calldata->arg.seqid == NULL) |
| 2289 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2290 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2291 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2292 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2293 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2294 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2295 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2296 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2297 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2298 | msg.rpc_argp = &calldata->arg; |
| 2299 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2300 | task_setup_data.callback_data = calldata; |
| 2301 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2302 | if (IS_ERR(task)) |
| 2303 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2304 | status = 0; |
| 2305 | if (wait) |
| 2306 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2307 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2308 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2309 | out_free_calldata: |
| 2310 | kfree(calldata); |
| 2311 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2312 | nfs4_put_open_state(state); |
| 2313 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2314 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2317 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2318 | 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] | 2319 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | struct nfs4_state *state; |
| 2321 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2322 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2323 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2324 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2325 | if (IS_ERR(state)) |
| 2326 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2327 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2328 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2331 | 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] | 2332 | { |
| 2333 | if (ctx->state == NULL) |
| 2334 | return; |
| 2335 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2336 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2337 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2338 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | |
| 2341 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2342 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2343 | struct nfs4_server_caps_arg args = { |
| 2344 | .fhandle = fhandle, |
| 2345 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | struct nfs4_server_caps_res res = {}; |
| 2347 | struct rpc_message msg = { |
| 2348 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2349 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | .rpc_resp = &res, |
| 2351 | }; |
| 2352 | int status; |
| 2353 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2354 | 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] | 2355 | if (status == 0) { |
| 2356 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2357 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2358 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2359 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2360 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2361 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2363 | server->caps |= NFS_CAP_ACLS; |
| 2364 | if (res.has_links != 0) |
| 2365 | server->caps |= NFS_CAP_HARDLINKS; |
| 2366 | if (res.has_symlinks != 0) |
| 2367 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2368 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2369 | server->caps |= NFS_CAP_FILEID; |
| 2370 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2371 | server->caps |= NFS_CAP_MODE; |
| 2372 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2373 | server->caps |= NFS_CAP_NLINK; |
| 2374 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2375 | server->caps |= NFS_CAP_OWNER; |
| 2376 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2377 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2378 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2379 | server->caps |= NFS_CAP_ATIME; |
| 2380 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2381 | server->caps |= NFS_CAP_CTIME; |
| 2382 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2383 | server->caps |= NFS_CAP_MTIME; |
| 2384 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2385 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2386 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2387 | 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] | 2388 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2389 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | return status; |
| 2393 | } |
| 2394 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2395 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | { |
| 2397 | struct nfs4_exception exception = { }; |
| 2398 | int err; |
| 2399 | do { |
| 2400 | err = nfs4_handle_exception(server, |
| 2401 | _nfs4_server_capabilities(server, fhandle), |
| 2402 | &exception); |
| 2403 | } while (exception.retry); |
| 2404 | return err; |
| 2405 | } |
| 2406 | |
| 2407 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2408 | struct nfs_fsinfo *info) |
| 2409 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | struct nfs4_lookup_root_arg args = { |
| 2411 | .bitmask = nfs4_fattr_bitmap, |
| 2412 | }; |
| 2413 | struct nfs4_lookup_res res = { |
| 2414 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2415 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | .fh = fhandle, |
| 2417 | }; |
| 2418 | struct rpc_message msg = { |
| 2419 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2420 | .rpc_argp = &args, |
| 2421 | .rpc_resp = &res, |
| 2422 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2423 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2424 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2425 | 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] | 2426 | } |
| 2427 | |
| 2428 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2429 | struct nfs_fsinfo *info) |
| 2430 | { |
| 2431 | struct nfs4_exception exception = { }; |
| 2432 | int err; |
| 2433 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2434 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2435 | switch (err) { |
| 2436 | case 0: |
| 2437 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2438 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2439 | default: |
| 2440 | err = nfs4_handle_exception(server, err, &exception); |
| 2441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2443 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | return err; |
| 2445 | } |
| 2446 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2447 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2448 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2449 | { |
| 2450 | struct rpc_auth *auth; |
| 2451 | int ret; |
| 2452 | |
| 2453 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2454 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2455 | ret = -EIO; |
| 2456 | goto out; |
| 2457 | } |
| 2458 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2459 | out: |
| 2460 | return ret; |
| 2461 | } |
| 2462 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2463 | 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] | 2464 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2466 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2467 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2469 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2470 | if (len < 0) |
| 2471 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2472 | |
| 2473 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2474 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2475 | * thus has already been tried. */ |
| 2476 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2477 | continue; |
| 2478 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2479 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2480 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2481 | continue; |
| 2482 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2483 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2484 | /* |
| 2485 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2486 | * to access the mount. It could also mean that we tried to mount |
| 2487 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2488 | * existing mount programs don't handle -EACCES very well so it should |
| 2489 | * be mapped to -EPERM instead. |
| 2490 | */ |
| 2491 | if (status == -EACCES) |
| 2492 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2493 | return status; |
| 2494 | } |
| 2495 | |
| 2496 | /* |
| 2497 | * get the file handle for the "/" directory on the server |
| 2498 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2499 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2500 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2501 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2502 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2503 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2504 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2505 | /* |
| 2506 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2507 | * by nfs4_map_errors() as this function exits. |
| 2508 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2509 | status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | if (status == 0) |
| 2511 | status = nfs4_server_capabilities(server, fhandle); |
| 2512 | if (status == 0) |
| 2513 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2514 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2517 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2518 | struct nfs_fsinfo *info) |
| 2519 | { |
| 2520 | int error; |
| 2521 | struct nfs_fattr *fattr = info->fattr; |
| 2522 | |
| 2523 | error = nfs4_server_capabilities(server, mntfh); |
| 2524 | if (error < 0) { |
| 2525 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2526 | return error; |
| 2527 | } |
| 2528 | |
| 2529 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2530 | if (error < 0) { |
| 2531 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2532 | return error; |
| 2533 | } |
| 2534 | |
| 2535 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2536 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2537 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2538 | |
| 2539 | return error; |
| 2540 | } |
| 2541 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2542 | /* |
| 2543 | * Get locations and (maybe) other attributes of a referral. |
| 2544 | * Note that we'll actually follow the referral later when |
| 2545 | * we detect fsid mismatch in inode revalidation |
| 2546 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2547 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2548 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2549 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2550 | { |
| 2551 | int status = -ENOMEM; |
| 2552 | struct page *page = NULL; |
| 2553 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2554 | |
| 2555 | page = alloc_page(GFP_KERNEL); |
| 2556 | if (page == NULL) |
| 2557 | goto out; |
| 2558 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2559 | if (locations == NULL) |
| 2560 | goto out; |
| 2561 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2562 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2563 | if (status != 0) |
| 2564 | goto out; |
| 2565 | /* Make sure server returned a different fsid for the referral */ |
| 2566 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2567 | dprintk("%s: server did not return a different fsid for" |
| 2568 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2569 | status = -EIO; |
| 2570 | goto out; |
| 2571 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2572 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2573 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2574 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2575 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2576 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2577 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2578 | out: |
| 2579 | if (page) |
| 2580 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2581 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2582 | return status; |
| 2583 | } |
| 2584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2586 | { |
| 2587 | struct nfs4_getattr_arg args = { |
| 2588 | .fh = fhandle, |
| 2589 | .bitmask = server->attr_bitmask, |
| 2590 | }; |
| 2591 | struct nfs4_getattr_res res = { |
| 2592 | .fattr = fattr, |
| 2593 | .server = server, |
| 2594 | }; |
| 2595 | struct rpc_message msg = { |
| 2596 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2597 | .rpc_argp = &args, |
| 2598 | .rpc_resp = &res, |
| 2599 | }; |
| 2600 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2601 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2602 | 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] | 2603 | } |
| 2604 | |
| 2605 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2606 | { |
| 2607 | struct nfs4_exception exception = { }; |
| 2608 | int err; |
| 2609 | do { |
| 2610 | err = nfs4_handle_exception(server, |
| 2611 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2612 | &exception); |
| 2613 | } while (exception.retry); |
| 2614 | return err; |
| 2615 | } |
| 2616 | |
| 2617 | /* |
| 2618 | * The file is not closed if it is opened due to the a request to change |
| 2619 | * the size of the file. The open call will not be needed once the |
| 2620 | * VFS layer lookup-intents are implemented. |
| 2621 | * |
| 2622 | * Close is called when the inode is destroyed. |
| 2623 | * If we haven't opened the file for O_WRONLY, we |
| 2624 | * need to in the size_change case to obtain a stateid. |
| 2625 | * |
| 2626 | * Got race? |
| 2627 | * Because OPEN is always done by name in nfsv4, it is |
| 2628 | * possible that we opened a different file by the same |
| 2629 | * name. We can recognize this race condition, but we |
| 2630 | * can't do anything about it besides returning an error. |
| 2631 | * |
| 2632 | * This will be fixed with VFS changes (lookup-intent). |
| 2633 | */ |
| 2634 | static int |
| 2635 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2636 | struct iattr *sattr) |
| 2637 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2638 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2639 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2640 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | int status; |
| 2642 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2643 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2644 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2645 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2646 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2648 | /* Deal with open(O_TRUNC) */ |
| 2649 | if (sattr->ia_valid & ATTR_OPEN) |
| 2650 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2651 | |
| 2652 | /* Optimization: if the end result is no change, don't RPC */ |
| 2653 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2654 | return 0; |
| 2655 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2656 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2657 | if (sattr->ia_valid & ATTR_FILE) { |
| 2658 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2659 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2660 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2661 | if (ctx) { |
| 2662 | cred = ctx->cred; |
| 2663 | state = ctx->state; |
| 2664 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2668 | if (status == 0) |
| 2669 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | return status; |
| 2671 | } |
| 2672 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2673 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2674 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2675 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2676 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2677 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2678 | int status; |
| 2679 | struct nfs4_lookup_arg args = { |
| 2680 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2681 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2682 | .name = name, |
| 2683 | }; |
| 2684 | struct nfs4_lookup_res res = { |
| 2685 | .server = server, |
| 2686 | .fattr = fattr, |
| 2687 | .fh = fhandle, |
| 2688 | }; |
| 2689 | struct rpc_message msg = { |
| 2690 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2691 | .rpc_argp = &args, |
| 2692 | .rpc_resp = &res, |
| 2693 | }; |
| 2694 | |
| 2695 | nfs_fattr_init(fattr); |
| 2696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2698 | 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] | 2699 | dprintk("NFS reply lookup: %d\n", status); |
| 2700 | return status; |
| 2701 | } |
| 2702 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2703 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2704 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2705 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2706 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2707 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2708 | fattr->nlink = 2; |
| 2709 | } |
| 2710 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2711 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2712 | struct qstr *name, struct nfs_fh *fhandle, |
| 2713 | struct nfs_fattr *fattr) |
| 2714 | { |
| 2715 | struct nfs4_exception exception = { }; |
| 2716 | struct rpc_clnt *client = *clnt; |
| 2717 | int err; |
| 2718 | do { |
| 2719 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2720 | switch (err) { |
| 2721 | case -NFS4ERR_BADNAME: |
| 2722 | err = -ENOENT; |
| 2723 | goto out; |
| 2724 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2725 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2726 | goto out; |
| 2727 | case -NFS4ERR_WRONGSEC: |
| 2728 | err = -EPERM; |
| 2729 | if (client != *clnt) |
| 2730 | goto out; |
| 2731 | |
| 2732 | client = nfs4_create_sec_client(client, dir, name); |
| 2733 | if (IS_ERR(client)) |
| 2734 | return PTR_ERR(client); |
| 2735 | |
| 2736 | exception.retry = 1; |
| 2737 | break; |
| 2738 | default: |
| 2739 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2740 | } |
| 2741 | } while (exception.retry); |
| 2742 | |
| 2743 | out: |
| 2744 | if (err == 0) |
| 2745 | *clnt = client; |
| 2746 | else if (client != *clnt) |
| 2747 | rpc_shutdown_client(client); |
| 2748 | |
| 2749 | return err; |
| 2750 | } |
| 2751 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2752 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2753 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2755 | int status; |
| 2756 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2757 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2758 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2759 | if (client != NFS_CLIENT(dir)) { |
| 2760 | rpc_shutdown_client(client); |
| 2761 | nfs_fixup_secinfo_attributes(fattr); |
| 2762 | } |
| 2763 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2766 | struct rpc_clnt * |
| 2767 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2768 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2769 | { |
| 2770 | int status; |
| 2771 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2772 | |
| 2773 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2774 | if (status < 0) { |
| 2775 | rpc_shutdown_client(client); |
| 2776 | return ERR_PTR(status); |
| 2777 | } |
| 2778 | return client; |
| 2779 | } |
| 2780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2782 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2783 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | struct nfs4_accessargs args = { |
| 2785 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2786 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2788 | struct nfs4_accessres res = { |
| 2789 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2790 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | struct rpc_message msg = { |
| 2792 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2793 | .rpc_argp = &args, |
| 2794 | .rpc_resp = &res, |
| 2795 | .rpc_cred = entry->cred, |
| 2796 | }; |
| 2797 | int mode = entry->mask; |
| 2798 | int status; |
| 2799 | |
| 2800 | /* |
| 2801 | * Determine which access bits we want to ask for... |
| 2802 | */ |
| 2803 | if (mode & MAY_READ) |
| 2804 | args.access |= NFS4_ACCESS_READ; |
| 2805 | if (S_ISDIR(inode->i_mode)) { |
| 2806 | if (mode & MAY_WRITE) |
| 2807 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2808 | if (mode & MAY_EXEC) |
| 2809 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2810 | } else { |
| 2811 | if (mode & MAY_WRITE) |
| 2812 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2813 | if (mode & MAY_EXEC) |
| 2814 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2815 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2816 | |
| 2817 | res.fattr = nfs_alloc_fattr(); |
| 2818 | if (res.fattr == NULL) |
| 2819 | return -ENOMEM; |
| 2820 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2821 | 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] | 2822 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2823 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2824 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2826 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | return status; |
| 2828 | } |
| 2829 | |
| 2830 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2831 | { |
| 2832 | struct nfs4_exception exception = { }; |
| 2833 | int err; |
| 2834 | do { |
| 2835 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2836 | _nfs4_proc_access(inode, entry), |
| 2837 | &exception); |
| 2838 | } while (exception.retry); |
| 2839 | return err; |
| 2840 | } |
| 2841 | |
| 2842 | /* |
| 2843 | * TODO: For the time being, we don't try to get any attributes |
| 2844 | * along with any of the zero-copy operations READ, READDIR, |
| 2845 | * READLINK, WRITE. |
| 2846 | * |
| 2847 | * In the case of the first three, we want to put the GETATTR |
| 2848 | * after the read-type operation -- this is because it is hard |
| 2849 | * to predict the length of a GETATTR response in v4, and thus |
| 2850 | * align the READ data correctly. This means that the GETATTR |
| 2851 | * may end up partially falling into the page cache, and we should |
| 2852 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2853 | * To do this efficiently, we need to know the total length |
| 2854 | * of data received, which doesn't seem to be available outside |
| 2855 | * of the RPC layer. |
| 2856 | * |
| 2857 | * In the case of WRITE, we also want to put the GETATTR after |
| 2858 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2859 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | * |
| 2861 | * Both of these changes to the XDR layer would in fact be quite |
| 2862 | * minor, but I decided to leave them for a subsequent patch. |
| 2863 | */ |
| 2864 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2865 | unsigned int pgbase, unsigned int pglen) |
| 2866 | { |
| 2867 | struct nfs4_readlink args = { |
| 2868 | .fh = NFS_FH(inode), |
| 2869 | .pgbase = pgbase, |
| 2870 | .pglen = pglen, |
| 2871 | .pages = &page, |
| 2872 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2873 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | struct rpc_message msg = { |
| 2875 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2876 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2877 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | }; |
| 2879 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2880 | 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] | 2881 | } |
| 2882 | |
| 2883 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2884 | unsigned int pgbase, unsigned int pglen) |
| 2885 | { |
| 2886 | struct nfs4_exception exception = { }; |
| 2887 | int err; |
| 2888 | do { |
| 2889 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2890 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2891 | &exception); |
| 2892 | } while (exception.retry); |
| 2893 | return err; |
| 2894 | } |
| 2895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2897 | * 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] | 2898 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | static int |
| 2900 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2901 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2903 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | int status = 0; |
| 2906 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2907 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2908 | if (IS_ERR(ctx)) |
| 2909 | return PTR_ERR(ctx); |
| 2910 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2911 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2912 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2913 | flags, sattr, ctx->cred, |
| 2914 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2915 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | if (IS_ERR(state)) { |
| 2917 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2918 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2920 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2921 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2922 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2924 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | return status; |
| 2926 | } |
| 2927 | |
| 2928 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2929 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2930 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2931 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2933 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2935 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2936 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2937 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2940 | .rpc_argp = &args, |
| 2941 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2943 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2944 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2945 | 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] | 2946 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2947 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | return status; |
| 2949 | } |
| 2950 | |
| 2951 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2952 | { |
| 2953 | struct nfs4_exception exception = { }; |
| 2954 | int err; |
| 2955 | do { |
| 2956 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2957 | _nfs4_proc_remove(dir, name), |
| 2958 | &exception); |
| 2959 | } while (exception.retry); |
| 2960 | return err; |
| 2961 | } |
| 2962 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2963 | 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] | 2964 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2965 | struct nfs_server *server = NFS_SERVER(dir); |
| 2966 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2967 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2969 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2971 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2974 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2975 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2976 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2977 | &data->args.seq_args, |
| 2978 | &data->res.seq_res, |
| 2979 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2982 | 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] | 2983 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2984 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2985 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2986 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2987 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2988 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2989 | return 0; |
| 2990 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2991 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2994 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2995 | { |
| 2996 | struct nfs_server *server = NFS_SERVER(dir); |
| 2997 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2998 | struct nfs_renameres *res = msg->rpc_resp; |
| 2999 | |
| 3000 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3001 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3002 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3003 | } |
| 3004 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3005 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3006 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3007 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3008 | &data->args.seq_args, |
| 3009 | &data->res.seq_res, |
| 3010 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3014 | struct inode *new_dir) |
| 3015 | { |
| 3016 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3017 | |
| 3018 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3019 | return 0; |
| 3020 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3021 | return 0; |
| 3022 | |
| 3023 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3024 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3025 | return 1; |
| 3026 | } |
| 3027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3029 | struct inode *new_dir, struct qstr *new_name) |
| 3030 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3031 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3032 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | .old_dir = NFS_FH(old_dir), |
| 3034 | .new_dir = NFS_FH(new_dir), |
| 3035 | .old_name = old_name, |
| 3036 | .new_name = new_name, |
| 3037 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3038 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3039 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3040 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | struct rpc_message msg = { |
| 3042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3043 | .rpc_argp = &arg, |
| 3044 | .rpc_resp = &res, |
| 3045 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3046 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3048 | 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] | 3049 | if (!status) { |
| 3050 | update_changeattr(old_dir, &res.old_cinfo); |
| 3051 | update_changeattr(new_dir, &res.new_cinfo); |
| 3052 | } |
| 3053 | return status; |
| 3054 | } |
| 3055 | |
| 3056 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3057 | struct inode *new_dir, struct qstr *new_name) |
| 3058 | { |
| 3059 | struct nfs4_exception exception = { }; |
| 3060 | int err; |
| 3061 | do { |
| 3062 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3063 | _nfs4_proc_rename(old_dir, old_name, |
| 3064 | new_dir, new_name), |
| 3065 | &exception); |
| 3066 | } while (exception.retry); |
| 3067 | return err; |
| 3068 | } |
| 3069 | |
| 3070 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3071 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3072 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | struct nfs4_link_arg arg = { |
| 3074 | .fh = NFS_FH(inode), |
| 3075 | .dir_fh = NFS_FH(dir), |
| 3076 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3077 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3079 | struct nfs4_link_res res = { |
| 3080 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3081 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | struct rpc_message msg = { |
| 3083 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3084 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3085 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3087 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3089 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3090 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3091 | goto out; |
| 3092 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3093 | 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] | 3094 | if (!status) { |
| 3095 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3096 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3097 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3098 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3099 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | return status; |
| 3101 | } |
| 3102 | |
| 3103 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3104 | { |
| 3105 | struct nfs4_exception exception = { }; |
| 3106 | int err; |
| 3107 | do { |
| 3108 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3109 | _nfs4_proc_link(inode, dir, name), |
| 3110 | &exception); |
| 3111 | } while (exception.retry); |
| 3112 | return err; |
| 3113 | } |
| 3114 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3115 | struct nfs4_createdata { |
| 3116 | struct rpc_message msg; |
| 3117 | struct nfs4_create_arg arg; |
| 3118 | struct nfs4_create_res res; |
| 3119 | struct nfs_fh fh; |
| 3120 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3121 | }; |
| 3122 | |
| 3123 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3124 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3125 | { |
| 3126 | struct nfs4_createdata *data; |
| 3127 | |
| 3128 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3129 | if (data != NULL) { |
| 3130 | struct nfs_server *server = NFS_SERVER(dir); |
| 3131 | |
| 3132 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3133 | data->msg.rpc_argp = &data->arg; |
| 3134 | data->msg.rpc_resp = &data->res; |
| 3135 | data->arg.dir_fh = NFS_FH(dir); |
| 3136 | data->arg.server = server; |
| 3137 | data->arg.name = name; |
| 3138 | data->arg.attrs = sattr; |
| 3139 | data->arg.ftype = ftype; |
| 3140 | data->arg.bitmask = server->attr_bitmask; |
| 3141 | data->res.server = server; |
| 3142 | data->res.fh = &data->fh; |
| 3143 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3144 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3145 | } |
| 3146 | return data; |
| 3147 | } |
| 3148 | |
| 3149 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3150 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3151 | 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] | 3152 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3153 | if (status == 0) { |
| 3154 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3155 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3156 | } |
| 3157 | return status; |
| 3158 | } |
| 3159 | |
| 3160 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3161 | { |
| 3162 | kfree(data); |
| 3163 | } |
| 3164 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3165 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3166 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3168 | struct nfs4_createdata *data; |
| 3169 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3171 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3172 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3173 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3174 | status = -ENOMEM; |
| 3175 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3176 | if (data == NULL) |
| 3177 | goto out; |
| 3178 | |
| 3179 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3180 | data->arg.u.symlink.pages = &page; |
| 3181 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3183 | status = nfs4_do_create(dir, dentry, data); |
| 3184 | |
| 3185 | nfs4_free_createdata(data); |
| 3186 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | return status; |
| 3188 | } |
| 3189 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3190 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3191 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | { |
| 3193 | struct nfs4_exception exception = { }; |
| 3194 | int err; |
| 3195 | do { |
| 3196 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3197 | _nfs4_proc_symlink(dir, dentry, page, |
| 3198 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | &exception); |
| 3200 | } while (exception.retry); |
| 3201 | return err; |
| 3202 | } |
| 3203 | |
| 3204 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3205 | struct iattr *sattr) |
| 3206 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3207 | struct nfs4_createdata *data; |
| 3208 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3210 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3211 | if (data == NULL) |
| 3212 | goto out; |
| 3213 | |
| 3214 | status = nfs4_do_create(dir, dentry, data); |
| 3215 | |
| 3216 | nfs4_free_createdata(data); |
| 3217 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | return status; |
| 3219 | } |
| 3220 | |
| 3221 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3222 | struct iattr *sattr) |
| 3223 | { |
| 3224 | struct nfs4_exception exception = { }; |
| 3225 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3226 | |
| 3227 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | do { |
| 3229 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3230 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3231 | &exception); |
| 3232 | } while (exception.retry); |
| 3233 | return err; |
| 3234 | } |
| 3235 | |
| 3236 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3237 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | { |
| 3239 | struct inode *dir = dentry->d_inode; |
| 3240 | struct nfs4_readdir_arg args = { |
| 3241 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3242 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | .pgbase = 0, |
| 3244 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3245 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3246 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | }; |
| 3248 | struct nfs4_readdir_res res; |
| 3249 | struct rpc_message msg = { |
| 3250 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3251 | .rpc_argp = &args, |
| 3252 | .rpc_resp = &res, |
| 3253 | .rpc_cred = cred, |
| 3254 | }; |
| 3255 | int status; |
| 3256 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3257 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3258 | dentry->d_parent->d_name.name, |
| 3259 | dentry->d_name.name, |
| 3260 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3261 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3263 | 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] | 3264 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3265 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3266 | status += args.pgbase; |
| 3267 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3268 | |
| 3269 | nfs_invalidate_atime(dir); |
| 3270 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3271 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | return status; |
| 3273 | } |
| 3274 | |
| 3275 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3276 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | { |
| 3278 | struct nfs4_exception exception = { }; |
| 3279 | int err; |
| 3280 | do { |
| 3281 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3282 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3283 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | &exception); |
| 3285 | } while (exception.retry); |
| 3286 | return err; |
| 3287 | } |
| 3288 | |
| 3289 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3290 | struct iattr *sattr, dev_t rdev) |
| 3291 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3292 | struct nfs4_createdata *data; |
| 3293 | int mode = sattr->ia_mode; |
| 3294 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3296 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3297 | if (data == NULL) |
| 3298 | goto out; |
| 3299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3301 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3303 | data->arg.ftype = NF4BLK; |
| 3304 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3305 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | } |
| 3307 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3308 | data->arg.ftype = NF4CHR; |
| 3309 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3310 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3311 | } else if (!S_ISSOCK(mode)) { |
| 3312 | status = -EINVAL; |
| 3313 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3316 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3317 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3318 | nfs4_free_createdata(data); |
| 3319 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | return status; |
| 3321 | } |
| 3322 | |
| 3323 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3324 | struct iattr *sattr, dev_t rdev) |
| 3325 | { |
| 3326 | struct nfs4_exception exception = { }; |
| 3327 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3328 | |
| 3329 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | do { |
| 3331 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3332 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3333 | &exception); |
| 3334 | } while (exception.retry); |
| 3335 | return err; |
| 3336 | } |
| 3337 | |
| 3338 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3339 | struct nfs_fsstat *fsstat) |
| 3340 | { |
| 3341 | struct nfs4_statfs_arg args = { |
| 3342 | .fh = fhandle, |
| 3343 | .bitmask = server->attr_bitmask, |
| 3344 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3345 | struct nfs4_statfs_res res = { |
| 3346 | .fsstat = fsstat, |
| 3347 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | struct rpc_message msg = { |
| 3349 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3350 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3351 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | }; |
| 3353 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3354 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3355 | 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] | 3356 | } |
| 3357 | |
| 3358 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3359 | { |
| 3360 | struct nfs4_exception exception = { }; |
| 3361 | int err; |
| 3362 | do { |
| 3363 | err = nfs4_handle_exception(server, |
| 3364 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3365 | &exception); |
| 3366 | } while (exception.retry); |
| 3367 | return err; |
| 3368 | } |
| 3369 | |
| 3370 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3371 | struct nfs_fsinfo *fsinfo) |
| 3372 | { |
| 3373 | struct nfs4_fsinfo_arg args = { |
| 3374 | .fh = fhandle, |
| 3375 | .bitmask = server->attr_bitmask, |
| 3376 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3377 | struct nfs4_fsinfo_res res = { |
| 3378 | .fsinfo = fsinfo, |
| 3379 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | struct rpc_message msg = { |
| 3381 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3382 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3383 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | }; |
| 3385 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3386 | 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] | 3387 | } |
| 3388 | |
| 3389 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3390 | { |
| 3391 | struct nfs4_exception exception = { }; |
| 3392 | int err; |
| 3393 | |
| 3394 | do { |
| 3395 | err = nfs4_handle_exception(server, |
| 3396 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3397 | &exception); |
| 3398 | } while (exception.retry); |
| 3399 | return err; |
| 3400 | } |
| 3401 | |
| 3402 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3403 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3404 | int error; |
| 3405 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3406 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3407 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3408 | if (error == 0) { |
| 3409 | /* block layout checks this! */ |
| 3410 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3411 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3412 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3413 | |
| 3414 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3418 | struct nfs_pathconf *pathconf) |
| 3419 | { |
| 3420 | struct nfs4_pathconf_arg args = { |
| 3421 | .fh = fhandle, |
| 3422 | .bitmask = server->attr_bitmask, |
| 3423 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3424 | struct nfs4_pathconf_res res = { |
| 3425 | .pathconf = pathconf, |
| 3426 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | struct rpc_message msg = { |
| 3428 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3429 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3430 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | }; |
| 3432 | |
| 3433 | /* None of the pathconf attributes are mandatory to implement */ |
| 3434 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3435 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3436 | return 0; |
| 3437 | } |
| 3438 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3439 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3440 | 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] | 3441 | } |
| 3442 | |
| 3443 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3444 | struct nfs_pathconf *pathconf) |
| 3445 | { |
| 3446 | struct nfs4_exception exception = { }; |
| 3447 | int err; |
| 3448 | |
| 3449 | do { |
| 3450 | err = nfs4_handle_exception(server, |
| 3451 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3452 | &exception); |
| 3453 | } while (exception.retry); |
| 3454 | return err; |
| 3455 | } |
| 3456 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame^] | 3457 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3458 | const struct nfs_open_context *ctx, |
| 3459 | const struct nfs_lock_context *l_ctx, |
| 3460 | fmode_t fmode) |
| 3461 | { |
| 3462 | const struct nfs_lockowner *lockowner = NULL; |
| 3463 | |
| 3464 | if (l_ctx != NULL) |
| 3465 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame^] | 3466 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3467 | } |
| 3468 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3469 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame^] | 3470 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3471 | const struct nfs_open_context *ctx, |
| 3472 | const struct nfs_lock_context *l_ctx, |
| 3473 | fmode_t fmode) |
| 3474 | { |
| 3475 | nfs4_stateid current_stateid; |
| 3476 | |
| 3477 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3478 | return false; |
| 3479 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3480 | } |
| 3481 | |
| 3482 | static bool nfs4_error_stateid_expired(int err) |
| 3483 | { |
| 3484 | switch (err) { |
| 3485 | case -NFS4ERR_DELEG_REVOKED: |
| 3486 | case -NFS4ERR_ADMIN_REVOKED: |
| 3487 | case -NFS4ERR_BAD_STATEID: |
| 3488 | case -NFS4ERR_STALE_STATEID: |
| 3489 | case -NFS4ERR_OLD_STATEID: |
| 3490 | case -NFS4ERR_OPENMODE: |
| 3491 | case -NFS4ERR_EXPIRED: |
| 3492 | return true; |
| 3493 | } |
| 3494 | return false; |
| 3495 | } |
| 3496 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3497 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3498 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3499 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3500 | } |
| 3501 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3502 | 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] | 3503 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3504 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3506 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3507 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3508 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3510 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3511 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3513 | renew_lease(server, data->timestamp); |
| 3514 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame^] | 3517 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3518 | struct nfs_readargs *args) |
| 3519 | { |
| 3520 | |
| 3521 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3522 | nfs4_stateid_is_current(&args->stateid, |
| 3523 | args->context, |
| 3524 | args->lock_context, |
| 3525 | FMODE_READ)) |
| 3526 | return false; |
| 3527 | rpc_restart_call_prepare(task); |
| 3528 | return true; |
| 3529 | } |
| 3530 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3531 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3532 | { |
| 3533 | |
| 3534 | dprintk("--> %s\n", __func__); |
| 3535 | |
| 3536 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3537 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame^] | 3538 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3539 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3540 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3541 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3542 | } |
| 3543 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3544 | 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] | 3545 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3547 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3548 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3549 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3552 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3553 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3554 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3555 | &data->args.seq_args, |
| 3556 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3557 | task)) |
| 3558 | return; |
| 3559 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3560 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3563 | 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] | 3564 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3565 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3567 | 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] | 3568 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3569 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3571 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3573 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3574 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3575 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame^] | 3578 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3579 | struct nfs_writeargs *args) |
| 3580 | { |
| 3581 | |
| 3582 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3583 | nfs4_stateid_is_current(&args->stateid, |
| 3584 | args->context, |
| 3585 | args->lock_context, |
| 3586 | FMODE_WRITE)) |
| 3587 | return false; |
| 3588 | rpc_restart_call_prepare(task); |
| 3589 | return true; |
| 3590 | } |
| 3591 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3592 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3593 | { |
| 3594 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3595 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame^] | 3596 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3597 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3598 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3599 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3602 | static |
| 3603 | bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3604 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3605 | const struct nfs_pgio_header *hdr = data->header; |
| 3606 | |
| 3607 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3608 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3609 | return false; |
| 3610 | /* Otherwise, request attributes if and only if we don't hold |
| 3611 | * a delegation |
| 3612 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3613 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3614 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3615 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3616 | static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3618 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3619 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3620 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3621 | data->args.bitmask = NULL; |
| 3622 | data->res.fattr = NULL; |
| 3623 | } else |
| 3624 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3625 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3626 | if (!data->write_done_cb) |
| 3627 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3628 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | data->timestamp = jiffies; |
| 3630 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3631 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3632 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | } |
| 3634 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3635 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3636 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3637 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3638 | &data->args.seq_args, |
| 3639 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3640 | task)) |
| 3641 | return; |
| 3642 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3643 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | } |
| 3645 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3646 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3647 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3648 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3649 | &data->args.seq_args, |
| 3650 | &data->res.seq_res, |
| 3651 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3654 | 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] | 3655 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3657 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3658 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3659 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3660 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3662 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3665 | 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] | 3666 | { |
| 3667 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3668 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3669 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3670 | } |
| 3671 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3672 | 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] | 3673 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3674 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3675 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3676 | if (data->commit_done_cb == NULL) |
| 3677 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3678 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3679 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3680 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | } |
| 3682 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3683 | struct nfs4_renewdata { |
| 3684 | struct nfs_client *client; |
| 3685 | unsigned long timestamp; |
| 3686 | }; |
| 3687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | /* |
| 3689 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3690 | * standalone procedure for queueing an asynchronous RENEW. |
| 3691 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3692 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3693 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3694 | struct nfs4_renewdata *data = calldata; |
| 3695 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3696 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3697 | if (atomic_read(&clp->cl_count) > 1) |
| 3698 | nfs4_schedule_state_renewal(clp); |
| 3699 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3700 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3701 | } |
| 3702 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3703 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3705 | struct nfs4_renewdata *data = calldata; |
| 3706 | struct nfs_client *clp = data->client; |
| 3707 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | |
| 3709 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3710 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3711 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3712 | return; |
| 3713 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3714 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3715 | return; |
| 3716 | } |
| 3717 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3719 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | } |
| 3721 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3722 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3723 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3724 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3725 | }; |
| 3726 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3727 | 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] | 3728 | { |
| 3729 | struct rpc_message msg = { |
| 3730 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3731 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3732 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3734 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3736 | if (renew_flags == 0) |
| 3737 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3738 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3739 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3740 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3741 | if (data == NULL) |
| 3742 | return -ENOMEM; |
| 3743 | data->client = clp; |
| 3744 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3746 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3749 | 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] | 3750 | { |
| 3751 | struct rpc_message msg = { |
| 3752 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3753 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3754 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | }; |
| 3756 | unsigned long now = jiffies; |
| 3757 | int status; |
| 3758 | |
| 3759 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3760 | if (status < 0) |
| 3761 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3762 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | return 0; |
| 3764 | } |
| 3765 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3766 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3767 | { |
| 3768 | return (server->caps & NFS_CAP_ACLS) |
| 3769 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3770 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3771 | } |
| 3772 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3773 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3774 | * 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] | 3775 | * the stack. |
| 3776 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3777 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3778 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3779 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3780 | struct page **pages, unsigned int *pgbase) |
| 3781 | { |
| 3782 | struct page *newpage, **spages; |
| 3783 | int rc = 0; |
| 3784 | size_t len; |
| 3785 | spages = pages; |
| 3786 | |
| 3787 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3788 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3789 | newpage = alloc_page(GFP_KERNEL); |
| 3790 | |
| 3791 | if (newpage == NULL) |
| 3792 | goto unwind; |
| 3793 | memcpy(page_address(newpage), buf, len); |
| 3794 | buf += len; |
| 3795 | buflen -= len; |
| 3796 | *pages++ = newpage; |
| 3797 | rc++; |
| 3798 | } while (buflen != 0); |
| 3799 | |
| 3800 | return rc; |
| 3801 | |
| 3802 | unwind: |
| 3803 | for(; rc > 0; rc--) |
| 3804 | __free_page(spages[rc-1]); |
| 3805 | return -ENOMEM; |
| 3806 | } |
| 3807 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3808 | struct nfs4_cached_acl { |
| 3809 | int cached; |
| 3810 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3811 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3812 | }; |
| 3813 | |
| 3814 | 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] | 3815 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3816 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3817 | |
| 3818 | spin_lock(&inode->i_lock); |
| 3819 | kfree(nfsi->nfs4_acl); |
| 3820 | nfsi->nfs4_acl = acl; |
| 3821 | spin_unlock(&inode->i_lock); |
| 3822 | } |
| 3823 | |
| 3824 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3825 | { |
| 3826 | nfs4_set_cached_acl(inode, NULL); |
| 3827 | } |
| 3828 | |
| 3829 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3830 | { |
| 3831 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3832 | struct nfs4_cached_acl *acl; |
| 3833 | int ret = -ENOENT; |
| 3834 | |
| 3835 | spin_lock(&inode->i_lock); |
| 3836 | acl = nfsi->nfs4_acl; |
| 3837 | if (acl == NULL) |
| 3838 | goto out; |
| 3839 | if (buf == NULL) /* user is just asking for length */ |
| 3840 | goto out_len; |
| 3841 | if (acl->cached == 0) |
| 3842 | goto out; |
| 3843 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3844 | if (acl->len > buflen) |
| 3845 | goto out; |
| 3846 | memcpy(buf, acl->data, acl->len); |
| 3847 | out_len: |
| 3848 | ret = acl->len; |
| 3849 | out: |
| 3850 | spin_unlock(&inode->i_lock); |
| 3851 | return ret; |
| 3852 | } |
| 3853 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3854 | 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] | 3855 | { |
| 3856 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3857 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3858 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3859 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3860 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3861 | if (acl == NULL) |
| 3862 | goto out; |
| 3863 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3864 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3865 | } else { |
| 3866 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3867 | if (acl == NULL) |
| 3868 | goto out; |
| 3869 | acl->cached = 0; |
| 3870 | } |
| 3871 | acl->len = acl_len; |
| 3872 | out: |
| 3873 | nfs4_set_cached_acl(inode, acl); |
| 3874 | } |
| 3875 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3876 | /* |
| 3877 | * The getxattr API returns the required buffer length when called with a |
| 3878 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3879 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3880 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3881 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3882 | * the cache. If not so, we throw away the page, and cache the required |
| 3883 | * length. The next getxattr call will then produce another round trip to |
| 3884 | * the server, this time with the input buf of the required size. |
| 3885 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3886 | 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] | 3887 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3888 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3889 | struct nfs_getaclargs args = { |
| 3890 | .fh = NFS_FH(inode), |
| 3891 | .acl_pages = pages, |
| 3892 | .acl_len = buflen, |
| 3893 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3894 | struct nfs_getaclres res = { |
| 3895 | .acl_len = buflen, |
| 3896 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3897 | struct rpc_message msg = { |
| 3898 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3899 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3900 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3901 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3902 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3903 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3904 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3905 | /* As long as we're doing a round trip to the server anyway, |
| 3906 | * let's be prepared for a page of acl data. */ |
| 3907 | if (npages == 0) |
| 3908 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3909 | if (npages > ARRAY_SIZE(pages)) |
| 3910 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3911 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3912 | for (i = 0; i < npages; i++) { |
| 3913 | pages[i] = alloc_page(GFP_KERNEL); |
| 3914 | if (!pages[i]) |
| 3915 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3916 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3917 | |
| 3918 | /* for decoding across pages */ |
| 3919 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3920 | if (!res.acl_scratch) |
| 3921 | goto out_free; |
| 3922 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3923 | args.acl_len = npages * PAGE_SIZE; |
| 3924 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3925 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3926 | 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] | 3927 | __func__, buf, buflen, npages, args.acl_len); |
| 3928 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3929 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3930 | if (ret) |
| 3931 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3932 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3933 | /* Handle the case where the passed-in buffer is too short */ |
| 3934 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3935 | /* Did the user only issue a request for the acl length? */ |
| 3936 | if (buf == NULL) |
| 3937 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3938 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3939 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3940 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3941 | 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] | 3942 | if (buf) { |
| 3943 | if (res.acl_len > buflen) { |
| 3944 | ret = -ERANGE; |
| 3945 | goto out_free; |
| 3946 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3947 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 3948 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3949 | out_ok: |
| 3950 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3951 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3952 | for (i = 0; i < npages; i++) |
| 3953 | if (pages[i]) |
| 3954 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3955 | if (res.acl_scratch) |
| 3956 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3957 | return ret; |
| 3958 | } |
| 3959 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3960 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3961 | { |
| 3962 | struct nfs4_exception exception = { }; |
| 3963 | ssize_t ret; |
| 3964 | do { |
| 3965 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3966 | if (ret >= 0) |
| 3967 | break; |
| 3968 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3969 | } while (exception.retry); |
| 3970 | return ret; |
| 3971 | } |
| 3972 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3973 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3974 | { |
| 3975 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3976 | int ret; |
| 3977 | |
| 3978 | if (!nfs4_server_supports_acls(server)) |
| 3979 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3980 | ret = nfs_revalidate_inode(server, inode); |
| 3981 | if (ret < 0) |
| 3982 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3983 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3984 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3985 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3986 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3987 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3988 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3989 | return ret; |
| 3990 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3991 | } |
| 3992 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3993 | 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] | 3994 | { |
| 3995 | struct nfs_server *server = NFS_SERVER(inode); |
| 3996 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3997 | struct nfs_setaclargs arg = { |
| 3998 | .fh = NFS_FH(inode), |
| 3999 | .acl_pages = pages, |
| 4000 | .acl_len = buflen, |
| 4001 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4002 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4003 | struct rpc_message msg = { |
| 4004 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4005 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4006 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4007 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4008 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4009 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4010 | |
| 4011 | if (!nfs4_server_supports_acls(server)) |
| 4012 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4013 | if (npages > ARRAY_SIZE(pages)) |
| 4014 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4015 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4016 | if (i < 0) |
| 4017 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4018 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4019 | 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] | 4020 | |
| 4021 | /* |
| 4022 | * Free each page after tx, so the only ref left is |
| 4023 | * held by the network stack |
| 4024 | */ |
| 4025 | for (; i > 0; i--) |
| 4026 | put_page(pages[i-1]); |
| 4027 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4028 | /* |
| 4029 | * Acl update can result in inode attribute update. |
| 4030 | * so mark the attribute cache invalid. |
| 4031 | */ |
| 4032 | spin_lock(&inode->i_lock); |
| 4033 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4034 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4035 | nfs_access_zap_cache(inode); |
| 4036 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4037 | return ret; |
| 4038 | } |
| 4039 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4040 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4041 | { |
| 4042 | struct nfs4_exception exception = { }; |
| 4043 | int err; |
| 4044 | do { |
| 4045 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4046 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4047 | &exception); |
| 4048 | } while (exception.retry); |
| 4049 | return err; |
| 4050 | } |
| 4051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4053 | 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] | 4054 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4055 | struct nfs_client *clp = server->nfs_client; |
| 4056 | |
| 4057 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | return 0; |
| 4059 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4060 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4061 | case -NFS4ERR_ADMIN_REVOKED: |
| 4062 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4063 | if (state == NULL) |
| 4064 | break; |
| 4065 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4066 | case -NFS4ERR_OPENMODE: |
| 4067 | if (state == NULL) |
| 4068 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4069 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4070 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4071 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4072 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4073 | if (state != NULL) { |
| 4074 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4075 | goto stateid_invalid; |
| 4076 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4078 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4079 | nfs4_schedule_lease_recovery(clp); |
| 4080 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4081 | #if defined(CONFIG_NFS_V4_1) |
| 4082 | case -NFS4ERR_BADSESSION: |
| 4083 | case -NFS4ERR_BADSLOT: |
| 4084 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4085 | case -NFS4ERR_DEADSESSION: |
| 4086 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4087 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4088 | case -NFS4ERR_SEQ_MISORDERED: |
| 4089 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4090 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4091 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4092 | task->tk_status = 0; |
| 4093 | return -EAGAIN; |
| 4094 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4096 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4097 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4099 | task->tk_status = 0; |
| 4100 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4101 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | case -NFS4ERR_OLD_STATEID: |
| 4103 | task->tk_status = 0; |
| 4104 | return -EAGAIN; |
| 4105 | } |
| 4106 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4107 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4108 | stateid_invalid: |
| 4109 | task->tk_status = -EIO; |
| 4110 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4111 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4112 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4113 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4114 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4115 | task->tk_status = 0; |
| 4116 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4119 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4120 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4121 | { |
| 4122 | __be32 verf[2]; |
| 4123 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4124 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4125 | /* An impossible timestamp guarantees this value |
| 4126 | * will never match a generated boot time. */ |
| 4127 | verf[0] = 0; |
| 4128 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4129 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4130 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4131 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4132 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4133 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4134 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4135 | } |
| 4136 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4137 | static unsigned int |
| 4138 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4139 | char *buf, size_t len) |
| 4140 | { |
| 4141 | unsigned int result; |
| 4142 | |
| 4143 | rcu_read_lock(); |
| 4144 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4145 | clp->cl_ipaddr, |
| 4146 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4147 | RPC_DISPLAY_ADDR), |
| 4148 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4149 | RPC_DISPLAY_PROTO)); |
| 4150 | rcu_read_unlock(); |
| 4151 | return result; |
| 4152 | } |
| 4153 | |
| 4154 | static unsigned int |
| 4155 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4156 | char *buf, size_t len) |
| 4157 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4158 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4159 | |
| 4160 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4161 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4162 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4163 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4164 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4165 | } |
| 4166 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4167 | /** |
| 4168 | * nfs4_proc_setclientid - Negotiate client ID |
| 4169 | * @clp: state data structure |
| 4170 | * @program: RPC program for NFSv4 callback service |
| 4171 | * @port: IP port number for NFS4 callback service |
| 4172 | * @cred: RPC credential to use for this call |
| 4173 | * @res: where to place the result |
| 4174 | * |
| 4175 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4176 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4177 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4178 | unsigned short port, struct rpc_cred *cred, |
| 4179 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | { |
| 4181 | nfs4_verifier sc_verifier; |
| 4182 | struct nfs4_setclientid setclientid = { |
| 4183 | .sc_verifier = &sc_verifier, |
| 4184 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4185 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | }; |
| 4187 | struct rpc_message msg = { |
| 4188 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4189 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4190 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4191 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4193 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4195 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4196 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4197 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4198 | setclientid.sc_name_len = |
| 4199 | nfs4_init_uniform_client_string(clp, |
| 4200 | setclientid.sc_name, |
| 4201 | sizeof(setclientid.sc_name)); |
| 4202 | else |
| 4203 | setclientid.sc_name_len = |
| 4204 | nfs4_init_nonuniform_client_string(clp, |
| 4205 | setclientid.sc_name, |
| 4206 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4207 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4208 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4209 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4210 | sizeof(setclientid.sc_netid), |
| 4211 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4212 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4213 | rcu_read_unlock(); |
| 4214 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4215 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4217 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4218 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4219 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4220 | setclientid.sc_name_len, setclientid.sc_name); |
| 4221 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4222 | dprintk("NFS reply setclientid: %d\n", status); |
| 4223 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | } |
| 4225 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4226 | /** |
| 4227 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4228 | * @clp: state data structure |
| 4229 | * @res: result of a previous SETCLIENTID |
| 4230 | * @cred: RPC credential to use for this call |
| 4231 | * |
| 4232 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4233 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4234 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4235 | struct nfs4_setclientid_res *arg, |
| 4236 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | { |
| 4238 | struct nfs_fsinfo fsinfo; |
| 4239 | struct rpc_message msg = { |
| 4240 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4241 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4243 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | }; |
| 4245 | unsigned long now; |
| 4246 | int status; |
| 4247 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4248 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4249 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4250 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4252 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | if (status == 0) { |
| 4254 | spin_lock(&clp->cl_lock); |
| 4255 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4256 | clp->cl_last_renewal = now; |
| 4257 | spin_unlock(&clp->cl_lock); |
| 4258 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4259 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | return status; |
| 4261 | } |
| 4262 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4263 | struct nfs4_delegreturndata { |
| 4264 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4265 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4266 | struct nfs_fh fh; |
| 4267 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4268 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4269 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4270 | int rpc_status; |
| 4271 | }; |
| 4272 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4273 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4274 | { |
| 4275 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4276 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4277 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4278 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4279 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4280 | switch (task->tk_status) { |
| 4281 | case -NFS4ERR_STALE_STATEID: |
| 4282 | case -NFS4ERR_EXPIRED: |
| 4283 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4284 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4285 | break; |
| 4286 | default: |
| 4287 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4288 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4289 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4290 | return; |
| 4291 | } |
| 4292 | } |
| 4293 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | static void nfs4_delegreturn_release(void *calldata) |
| 4297 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4298 | kfree(calldata); |
| 4299 | } |
| 4300 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4301 | #if defined(CONFIG_NFS_V4_1) |
| 4302 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4303 | { |
| 4304 | struct nfs4_delegreturndata *d_data; |
| 4305 | |
| 4306 | d_data = (struct nfs4_delegreturndata *)data; |
| 4307 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4308 | nfs4_setup_sequence(d_data->res.server, |
| 4309 | &d_data->args.seq_args, |
| 4310 | &d_data->res.seq_res, |
| 4311 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4312 | } |
| 4313 | #endif /* CONFIG_NFS_V4_1 */ |
| 4314 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4315 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4316 | #if defined(CONFIG_NFS_V4_1) |
| 4317 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4318 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4319 | .rpc_call_done = nfs4_delegreturn_done, |
| 4320 | .rpc_release = nfs4_delegreturn_release, |
| 4321 | }; |
| 4322 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4323 | 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] | 4324 | { |
| 4325 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4326 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4327 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4328 | struct rpc_message msg = { |
| 4329 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4330 | .rpc_cred = cred, |
| 4331 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4332 | struct rpc_task_setup task_setup_data = { |
| 4333 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4334 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4335 | .callback_ops = &nfs4_delegreturn_ops, |
| 4336 | .flags = RPC_TASK_ASYNC, |
| 4337 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4338 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4339 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4340 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4341 | if (data == NULL) |
| 4342 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4343 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4344 | data->args.fhandle = &data->fh; |
| 4345 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4346 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4347 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4348 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4349 | data->res.fattr = &data->fattr; |
| 4350 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4351 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4352 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4353 | data->rpc_status = 0; |
| 4354 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4355 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4356 | msg.rpc_argp = &data->args; |
| 4357 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4358 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4359 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4360 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4361 | if (!issync) |
| 4362 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4363 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4364 | if (status != 0) |
| 4365 | goto out; |
| 4366 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4367 | if (status == 0) |
| 4368 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4369 | else |
| 4370 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4371 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4372 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4373 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | } |
| 4375 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4376 | 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] | 4377 | { |
| 4378 | struct nfs_server *server = NFS_SERVER(inode); |
| 4379 | struct nfs4_exception exception = { }; |
| 4380 | int err; |
| 4381 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4382 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | switch (err) { |
| 4384 | case -NFS4ERR_STALE_STATEID: |
| 4385 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | case 0: |
| 4387 | return 0; |
| 4388 | } |
| 4389 | err = nfs4_handle_exception(server, err, &exception); |
| 4390 | } while (exception.retry); |
| 4391 | return err; |
| 4392 | } |
| 4393 | |
| 4394 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4395 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4396 | |
| 4397 | /* |
| 4398 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4399 | */ |
| 4400 | static unsigned long |
| 4401 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4402 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4403 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | timeout <<= 1; |
| 4405 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4406 | return NFS4_LOCK_MAXTIMEOUT; |
| 4407 | return timeout; |
| 4408 | } |
| 4409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4411 | { |
| 4412 | struct inode *inode = state->inode; |
| 4413 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4414 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4415 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4417 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4419 | struct nfs_lockt_res res = { |
| 4420 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | }; |
| 4422 | struct rpc_message msg = { |
| 4423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4424 | .rpc_argp = &arg, |
| 4425 | .rpc_resp = &res, |
| 4426 | .rpc_cred = state->owner->so_cred, |
| 4427 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | struct nfs4_lock_state *lsp; |
| 4429 | int status; |
| 4430 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4431 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4432 | status = nfs4_set_lock_state(state, request); |
| 4433 | if (status != 0) |
| 4434 | goto out; |
| 4435 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4436 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4437 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4438 | 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] | 4439 | switch (status) { |
| 4440 | case 0: |
| 4441 | request->fl_type = F_UNLCK; |
| 4442 | break; |
| 4443 | case -NFS4ERR_DENIED: |
| 4444 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4446 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4447 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | return status; |
| 4449 | } |
| 4450 | |
| 4451 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4452 | { |
| 4453 | struct nfs4_exception exception = { }; |
| 4454 | int err; |
| 4455 | |
| 4456 | do { |
| 4457 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4458 | _nfs4_proc_getlk(state, cmd, request), |
| 4459 | &exception); |
| 4460 | } while (exception.retry); |
| 4461 | return err; |
| 4462 | } |
| 4463 | |
| 4464 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4465 | { |
| 4466 | int res = 0; |
| 4467 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4468 | case FL_POSIX: |
| 4469 | res = posix_lock_file_wait(file, fl); |
| 4470 | break; |
| 4471 | case FL_FLOCK: |
| 4472 | res = flock_lock_file_wait(file, fl); |
| 4473 | break; |
| 4474 | default: |
| 4475 | BUG(); |
| 4476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | return res; |
| 4478 | } |
| 4479 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4480 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4481 | struct nfs_locku_args arg; |
| 4482 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4483 | struct nfs4_lock_state *lsp; |
| 4484 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4485 | struct file_lock fl; |
| 4486 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4487 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4488 | }; |
| 4489 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4490 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4491 | struct nfs_open_context *ctx, |
| 4492 | struct nfs4_lock_state *lsp, |
| 4493 | struct nfs_seqid *seqid) |
| 4494 | { |
| 4495 | struct nfs4_unlockdata *p; |
| 4496 | struct inode *inode = lsp->ls_state->inode; |
| 4497 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4498 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4499 | if (p == NULL) |
| 4500 | return NULL; |
| 4501 | p->arg.fh = NFS_FH(inode); |
| 4502 | p->arg.fl = &p->fl; |
| 4503 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4504 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4505 | p->arg.stateid = &lsp->ls_stateid; |
| 4506 | p->lsp = lsp; |
| 4507 | atomic_inc(&lsp->ls_count); |
| 4508 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4509 | p->ctx = get_nfs_open_context(ctx); |
| 4510 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4511 | p->server = NFS_SERVER(inode); |
| 4512 | return p; |
| 4513 | } |
| 4514 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4515 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4516 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4517 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4518 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4519 | nfs4_put_lock_state(calldata->lsp); |
| 4520 | put_nfs_open_context(calldata->ctx); |
| 4521 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4524 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4525 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4526 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4527 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4528 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4529 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4530 | switch (task->tk_status) { |
| 4531 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4532 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4533 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4534 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4535 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4536 | case -NFS4ERR_BAD_STATEID: |
| 4537 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4538 | case -NFS4ERR_STALE_STATEID: |
| 4539 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4540 | break; |
| 4541 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4542 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4543 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4544 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4545 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4546 | } |
| 4547 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4548 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4549 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4550 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4552 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4553 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4554 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4555 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4556 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4557 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4558 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4559 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4560 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4561 | &calldata->res.seq_res, |
| 4562 | task) != 0) |
| 4563 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4564 | return; |
| 4565 | out_no_action: |
| 4566 | task->tk_action = NULL; |
| 4567 | out_wait: |
| 4568 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4571 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4572 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4573 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4574 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4575 | }; |
| 4576 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4577 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4578 | struct nfs_open_context *ctx, |
| 4579 | struct nfs4_lock_state *lsp, |
| 4580 | struct nfs_seqid *seqid) |
| 4581 | { |
| 4582 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4583 | struct rpc_message msg = { |
| 4584 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4585 | .rpc_cred = ctx->cred, |
| 4586 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4587 | struct rpc_task_setup task_setup_data = { |
| 4588 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4589 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4590 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4591 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4592 | .flags = RPC_TASK_ASYNC, |
| 4593 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4594 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4595 | /* Ensure this is an unlock - when canceling a lock, the |
| 4596 | * canceled lock is passed in, and it won't be an unlock. |
| 4597 | */ |
| 4598 | fl->fl_type = F_UNLCK; |
| 4599 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4600 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4601 | if (data == NULL) { |
| 4602 | nfs_free_seqid(seqid); |
| 4603 | return ERR_PTR(-ENOMEM); |
| 4604 | } |
| 4605 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4606 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4607 | msg.rpc_argp = &data->arg; |
| 4608 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4609 | task_setup_data.callback_data = data; |
| 4610 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4611 | } |
| 4612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4614 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4615 | struct inode *inode = state->inode; |
| 4616 | struct nfs4_state_owner *sp = state->owner; |
| 4617 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4618 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4619 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4620 | struct rpc_task *task; |
| 4621 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4622 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4624 | status = nfs4_set_lock_state(state, request); |
| 4625 | /* Unlock _before_ we do the RPC call */ |
| 4626 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4627 | /* Exclude nfs_delegation_claim_locks() */ |
| 4628 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4629 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4630 | down_read(&nfsi->rwsem); |
| 4631 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4632 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4633 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4634 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4635 | } |
| 4636 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4637 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4638 | if (status != 0) |
| 4639 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4640 | /* Is this a delegated lock? */ |
| 4641 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4642 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4643 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4644 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4645 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4646 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4647 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4648 | 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] | 4649 | status = PTR_ERR(task); |
| 4650 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4651 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4652 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4653 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4654 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4655 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4656 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | } |
| 4658 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4659 | struct nfs4_lockdata { |
| 4660 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4661 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4662 | struct nfs4_lock_state *lsp; |
| 4663 | struct nfs_open_context *ctx; |
| 4664 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4665 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4666 | int rpc_status; |
| 4667 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4668 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4669 | }; |
| 4670 | |
| 4671 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4672 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4673 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4674 | { |
| 4675 | struct nfs4_lockdata *p; |
| 4676 | struct inode *inode = lsp->ls_state->inode; |
| 4677 | struct nfs_server *server = NFS_SERVER(inode); |
| 4678 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4679 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4680 | if (p == NULL) |
| 4681 | return NULL; |
| 4682 | |
| 4683 | p->arg.fh = NFS_FH(inode); |
| 4684 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4685 | 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] | 4686 | if (p->arg.open_seqid == NULL) |
| 4687 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4688 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4689 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4690 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4691 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4692 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4693 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4694 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4695 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4696 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4697 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4698 | atomic_inc(&lsp->ls_count); |
| 4699 | p->ctx = get_nfs_open_context(ctx); |
| 4700 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4701 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4702 | out_free_seqid: |
| 4703 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4704 | out_free: |
| 4705 | kfree(p); |
| 4706 | return NULL; |
| 4707 | } |
| 4708 | |
| 4709 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4710 | { |
| 4711 | struct nfs4_lockdata *data = calldata; |
| 4712 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4714 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4715 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4716 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4717 | /* Do we need to do an open_to_lock_owner? */ |
| 4718 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4719 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4720 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4721 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4722 | data->arg.open_stateid = &state->stateid; |
| 4723 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4724 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4725 | } else |
| 4726 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4727 | if (!nfs4_valid_open_stateid(state)) { |
| 4728 | data->rpc_status = -EBADF; |
| 4729 | task->tk_action = NULL; |
| 4730 | goto out_release_open_seqid; |
| 4731 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4732 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4733 | if (nfs4_setup_sequence(data->server, |
| 4734 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4735 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4736 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4737 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4738 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4739 | nfs_release_seqid(data->arg.open_seqid); |
| 4740 | out_release_lock_seqid: |
| 4741 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4742 | out_wait: |
| 4743 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4744 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4745 | } |
| 4746 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4747 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4748 | { |
| 4749 | struct nfs4_lockdata *data = calldata; |
| 4750 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4751 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4752 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4753 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4754 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4755 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4756 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4757 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4758 | if (data->rpc_status == 0) |
| 4759 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4760 | else |
| 4761 | goto out; |
| 4762 | } |
| 4763 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4764 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4765 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4766 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4767 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4768 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4769 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | static void nfs4_lock_release(void *calldata) |
| 4773 | { |
| 4774 | struct nfs4_lockdata *data = calldata; |
| 4775 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4776 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4777 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4778 | if (data->cancelled != 0) { |
| 4779 | struct rpc_task *task; |
| 4780 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4781 | data->arg.lock_seqid); |
| 4782 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4783 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4784 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4785 | } else |
| 4786 | nfs_free_seqid(data->arg.lock_seqid); |
| 4787 | nfs4_put_lock_state(data->lsp); |
| 4788 | put_nfs_open_context(data->ctx); |
| 4789 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4790 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4794 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4795 | .rpc_call_done = nfs4_lock_done, |
| 4796 | .rpc_release = nfs4_lock_release, |
| 4797 | }; |
| 4798 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4799 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4800 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4801 | switch (error) { |
| 4802 | case -NFS4ERR_ADMIN_REVOKED: |
| 4803 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4804 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4805 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4806 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4807 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4808 | break; |
| 4809 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4810 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4811 | case -NFS4ERR_EXPIRED: |
| 4812 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4813 | }; |
| 4814 | } |
| 4815 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4816 | 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] | 4817 | { |
| 4818 | struct nfs4_lockdata *data; |
| 4819 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4820 | struct rpc_message msg = { |
| 4821 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4822 | .rpc_cred = state->owner->so_cred, |
| 4823 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4824 | struct rpc_task_setup task_setup_data = { |
| 4825 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4826 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4827 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4828 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4829 | .flags = RPC_TASK_ASYNC, |
| 4830 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4831 | int ret; |
| 4832 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4833 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4834 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4835 | fl->fl_u.nfs4_fl.owner, |
| 4836 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4837 | if (data == NULL) |
| 4838 | return -ENOMEM; |
| 4839 | if (IS_SETLKW(cmd)) |
| 4840 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4841 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4842 | msg.rpc_argp = &data->arg; |
| 4843 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4844 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4845 | if (recovery_type > NFS_LOCK_NEW) { |
| 4846 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4847 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4848 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4849 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4850 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4851 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4852 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4853 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4854 | if (ret == 0) { |
| 4855 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4856 | if (ret) |
| 4857 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4858 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4859 | } else |
| 4860 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4861 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4862 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4863 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4867 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4868 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4869 | struct nfs4_exception exception = { |
| 4870 | .inode = state->inode, |
| 4871 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4872 | int err; |
| 4873 | |
| 4874 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4875 | /* Cache the lock if possible... */ |
| 4876 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4877 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4878 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4879 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4880 | break; |
| 4881 | nfs4_handle_exception(server, err, &exception); |
| 4882 | } while (exception.retry); |
| 4883 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4887 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4888 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4889 | struct nfs4_exception exception = { |
| 4890 | .inode = state->inode, |
| 4891 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4892 | int err; |
| 4893 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4894 | err = nfs4_set_lock_state(state, request); |
| 4895 | if (err != 0) |
| 4896 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4897 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4898 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4899 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4900 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4901 | switch (err) { |
| 4902 | default: |
| 4903 | goto out; |
| 4904 | case -NFS4ERR_GRACE: |
| 4905 | case -NFS4ERR_DELAY: |
| 4906 | nfs4_handle_exception(server, err, &exception); |
| 4907 | err = 0; |
| 4908 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4909 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4910 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4911 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | } |
| 4913 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4914 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4915 | /** |
| 4916 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4917 | * |
| 4918 | * @state: NFSv4 state for an inode |
| 4919 | * |
| 4920 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4921 | * Otherwise a negative NFS4ERR value is returned. |
| 4922 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4923 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4924 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4925 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4926 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4927 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4928 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4929 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4930 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4931 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4932 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4933 | /* Free the stateid unless the server |
| 4934 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4935 | if (status != -NFS4ERR_BAD_STATEID) |
| 4936 | nfs41_free_stateid(server, |
| 4937 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4938 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4939 | ret = status; |
| 4940 | } |
| 4941 | } |
| 4942 | }; |
| 4943 | |
| 4944 | return ret; |
| 4945 | } |
| 4946 | |
| 4947 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4948 | { |
| 4949 | int status = NFS_OK; |
| 4950 | |
| 4951 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4952 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4953 | if (status != NFS_OK) |
| 4954 | status = nfs4_lock_expired(state, request); |
| 4955 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4956 | } |
| 4957 | #endif |
| 4958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4960 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4961 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4962 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4963 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4964 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4965 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4966 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4967 | if ((fl_flags & FL_POSIX) && |
| 4968 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4969 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4970 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4971 | status = nfs4_set_lock_state(state, request); |
| 4972 | if (status != 0) |
| 4973 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4974 | request->fl_flags |= FL_ACCESS; |
| 4975 | status = do_vfs_lock(request->fl_file, request); |
| 4976 | if (status < 0) |
| 4977 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4978 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4979 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4980 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4981 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4982 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4983 | status = do_vfs_lock(request->fl_file, request); |
| 4984 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4985 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4986 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 4987 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4988 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4989 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4990 | goto out; |
| 4991 | down_read(&nfsi->rwsem); |
| 4992 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 4993 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4994 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4995 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4996 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4997 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4998 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4999 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5000 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5001 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5002 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5003 | out: |
| 5004 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | return status; |
| 5006 | } |
| 5007 | |
| 5008 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5009 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5010 | struct nfs4_exception exception = { |
| 5011 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5012 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5013 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | int err; |
| 5015 | |
| 5016 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5017 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5018 | if (err == -NFS4ERR_DENIED) |
| 5019 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5021 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | } while (exception.retry); |
| 5023 | return err; |
| 5024 | } |
| 5025 | |
| 5026 | static int |
| 5027 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5028 | { |
| 5029 | struct nfs_open_context *ctx; |
| 5030 | struct nfs4_state *state; |
| 5031 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5032 | int status; |
| 5033 | |
| 5034 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5035 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | state = ctx->state; |
| 5037 | |
| 5038 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5039 | return -EINVAL; |
| 5040 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5041 | if (IS_GETLK(cmd)) { |
| 5042 | if (state != NULL) |
| 5043 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5044 | return 0; |
| 5045 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | |
| 5047 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5048 | return -EINVAL; |
| 5049 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5050 | if (request->fl_type == F_UNLCK) { |
| 5051 | if (state != NULL) |
| 5052 | return nfs4_proc_unlck(state, cmd, request); |
| 5053 | return 0; |
| 5054 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5056 | if (state == NULL) |
| 5057 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5058 | /* |
| 5059 | * Don't rely on the VFS having checked the file open mode, |
| 5060 | * since it won't do this for flock() locks. |
| 5061 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5062 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5063 | case F_RDLCK: |
| 5064 | if (!(filp->f_mode & FMODE_READ)) |
| 5065 | return -EBADF; |
| 5066 | break; |
| 5067 | case F_WRLCK: |
| 5068 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5069 | return -EBADF; |
| 5070 | } |
| 5071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | do { |
| 5073 | status = nfs4_proc_setlk(state, cmd, request); |
| 5074 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5075 | break; |
| 5076 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5077 | status = -ERESTARTSYS; |
| 5078 | if (signalled()) |
| 5079 | break; |
| 5080 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | return status; |
| 5082 | } |
| 5083 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5084 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5085 | { |
| 5086 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5087 | struct nfs4_exception exception = { }; |
| 5088 | int err; |
| 5089 | |
| 5090 | err = nfs4_set_lock_state(state, fl); |
| 5091 | if (err != 0) |
| 5092 | goto out; |
| 5093 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5094 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5095 | switch (err) { |
| 5096 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5097 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5098 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5099 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5100 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5101 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5102 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5103 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5104 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 5105 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5106 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5107 | err = -EAGAIN; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5108 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5109 | case -NFS4ERR_BADSESSION: |
| 5110 | case -NFS4ERR_BADSLOT: |
| 5111 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5112 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5113 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5114 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5115 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5116 | err = -EAGAIN; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5117 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5118 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5119 | case -NFS4ERR_ADMIN_REVOKED: |
| 5120 | case -NFS4ERR_BAD_STATEID: |
| 5121 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5122 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5123 | err = 0; |
| 5124 | goto out; |
| 5125 | case -ENOMEM: |
| 5126 | case -NFS4ERR_DENIED: |
| 5127 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5128 | err = 0; |
| 5129 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5130 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5131 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5132 | err = nfs4_handle_exception(server, err, &exception); |
| 5133 | } while (exception.retry); |
| 5134 | out: |
| 5135 | return err; |
| 5136 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5137 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5138 | struct nfs_release_lockowner_data { |
| 5139 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5140 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5141 | struct nfs_release_lockowner_args args; |
| 5142 | }; |
| 5143 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5144 | static void nfs4_release_lockowner_release(void *calldata) |
| 5145 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5146 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5147 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5148 | kfree(calldata); |
| 5149 | } |
| 5150 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5151 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5152 | .rpc_release = nfs4_release_lockowner_release, |
| 5153 | }; |
| 5154 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5155 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5156 | { |
| 5157 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5158 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5159 | struct rpc_message msg = { |
| 5160 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5161 | }; |
| 5162 | |
| 5163 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5164 | return -EINVAL; |
| 5165 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5166 | if (!data) |
| 5167 | return -ENOMEM; |
| 5168 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5169 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5170 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5171 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5172 | data->args.lock_owner.s_dev = server->s_dev; |
| 5173 | msg.rpc_argp = &data->args; |
| 5174 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5175 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5176 | } |
| 5177 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5178 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5179 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5180 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5181 | const void *buf, size_t buflen, |
| 5182 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5183 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5184 | if (strcmp(key, "") != 0) |
| 5185 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5186 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5187 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5190 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5191 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5192 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5193 | if (strcmp(key, "") != 0) |
| 5194 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5195 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5196 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5197 | } |
| 5198 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5199 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5200 | size_t list_len, const char *name, |
| 5201 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5202 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5203 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5204 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5205 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5206 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5207 | |
| 5208 | if (list && len <= list_len) |
| 5209 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5210 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5211 | } |
| 5212 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5213 | /* |
| 5214 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5215 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5216 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5217 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5218 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5219 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5220 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5221 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5222 | return; |
| 5223 | |
| 5224 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5225 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5226 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5227 | fattr->nlink = 2; |
| 5228 | } |
| 5229 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5230 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5231 | const struct qstr *name, |
| 5232 | struct nfs4_fs_locations *fs_locations, |
| 5233 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5234 | { |
| 5235 | struct nfs_server *server = NFS_SERVER(dir); |
| 5236 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5237 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5238 | }; |
| 5239 | struct nfs4_fs_locations_arg args = { |
| 5240 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5241 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5242 | .page = page, |
| 5243 | .bitmask = bitmask, |
| 5244 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5245 | struct nfs4_fs_locations_res res = { |
| 5246 | .fs_locations = fs_locations, |
| 5247 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5248 | struct rpc_message msg = { |
| 5249 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5250 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5251 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5252 | }; |
| 5253 | int status; |
| 5254 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5255 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5256 | |
| 5257 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5258 | * is not supported */ |
| 5259 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5260 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5261 | else |
| 5262 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5263 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5264 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5265 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5266 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5267 | 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] | 5268 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5269 | return status; |
| 5270 | } |
| 5271 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5272 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5273 | const struct qstr *name, |
| 5274 | struct nfs4_fs_locations *fs_locations, |
| 5275 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5276 | { |
| 5277 | struct nfs4_exception exception = { }; |
| 5278 | int err; |
| 5279 | do { |
| 5280 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5281 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5282 | &exception); |
| 5283 | } while (exception.retry); |
| 5284 | return err; |
| 5285 | } |
| 5286 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5287 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5288 | { |
| 5289 | int status; |
| 5290 | struct nfs4_secinfo_arg args = { |
| 5291 | .dir_fh = NFS_FH(dir), |
| 5292 | .name = name, |
| 5293 | }; |
| 5294 | struct nfs4_secinfo_res res = { |
| 5295 | .flavors = flavors, |
| 5296 | }; |
| 5297 | struct rpc_message msg = { |
| 5298 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5299 | .rpc_argp = &args, |
| 5300 | .rpc_resp = &res, |
| 5301 | }; |
| 5302 | |
| 5303 | dprintk("NFS call secinfo %s\n", name->name); |
| 5304 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5305 | dprintk("NFS reply secinfo: %d\n", status); |
| 5306 | return status; |
| 5307 | } |
| 5308 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5309 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5310 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5311 | { |
| 5312 | struct nfs4_exception exception = { }; |
| 5313 | int err; |
| 5314 | do { |
| 5315 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5316 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5317 | &exception); |
| 5318 | } while (exception.retry); |
| 5319 | return err; |
| 5320 | } |
| 5321 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5322 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5323 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5324 | * Check the exchange flags returned by the server for invalid flags, having |
| 5325 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5326 | * DS flags set. |
| 5327 | */ |
| 5328 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5329 | { |
| 5330 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5331 | goto out_inval; |
| 5332 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5333 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5334 | goto out_inval; |
| 5335 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5336 | goto out_inval; |
| 5337 | return NFS_OK; |
| 5338 | out_inval: |
| 5339 | return -NFS4ERR_INVAL; |
| 5340 | } |
| 5341 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5342 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5343 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5344 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5345 | { |
| 5346 | if (a->server_scope_sz == b->server_scope_sz && |
| 5347 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5348 | return true; |
| 5349 | |
| 5350 | return false; |
| 5351 | } |
| 5352 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5353 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5354 | * nfs4_proc_bind_conn_to_session() |
| 5355 | * |
| 5356 | * The 4.1 client currently uses the same TCP connection for the |
| 5357 | * fore and backchannel. |
| 5358 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5359 | 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] | 5360 | { |
| 5361 | int status; |
| 5362 | struct nfs41_bind_conn_to_session_res res; |
| 5363 | struct rpc_message msg = { |
| 5364 | .rpc_proc = |
| 5365 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5366 | .rpc_argp = clp, |
| 5367 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5368 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5369 | }; |
| 5370 | |
| 5371 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5372 | |
| 5373 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5374 | if (unlikely(res.session == NULL)) { |
| 5375 | status = -ENOMEM; |
| 5376 | goto out; |
| 5377 | } |
| 5378 | |
| 5379 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5380 | if (status == 0) { |
| 5381 | if (memcmp(res.session->sess_id.data, |
| 5382 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5383 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5384 | status = -EIO; |
| 5385 | goto out_session; |
| 5386 | } |
| 5387 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5388 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5389 | __func__); |
| 5390 | status = -EIO; |
| 5391 | goto out_session; |
| 5392 | } |
| 5393 | if (res.use_conn_in_rdma_mode) { |
| 5394 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5395 | __func__); |
| 5396 | status = -EIO; |
| 5397 | goto out_session; |
| 5398 | } |
| 5399 | } |
| 5400 | out_session: |
| 5401 | kfree(res.session); |
| 5402 | out: |
| 5403 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5404 | return status; |
| 5405 | } |
| 5406 | |
| 5407 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5408 | * nfs4_proc_exchange_id() |
| 5409 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5410 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5411 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5412 | * Since the clientid has expired, all compounds using sessions |
| 5413 | * associated with the stale clientid will be returning |
| 5414 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5415 | * be in some phase of session reset. |
| 5416 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5417 | 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] | 5418 | { |
| 5419 | nfs4_verifier verifier; |
| 5420 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5421 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5422 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5423 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5424 | }; |
| 5425 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5426 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5427 | }; |
| 5428 | int status; |
| 5429 | struct rpc_message msg = { |
| 5430 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5431 | .rpc_argp = &args, |
| 5432 | .rpc_resp = &res, |
| 5433 | .rpc_cred = cred, |
| 5434 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5435 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5436 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5437 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5438 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5439 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5440 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5441 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5442 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5443 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5444 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5445 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5446 | status = -ENOMEM; |
| 5447 | goto out; |
| 5448 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5449 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5450 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5451 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5452 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5453 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5454 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5455 | } |
| 5456 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5457 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5458 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5459 | status = -ENOMEM; |
| 5460 | goto out_server_scope; |
| 5461 | } |
| 5462 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5463 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5464 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5465 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5466 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5467 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5468 | clp->cl_clientid = res.clientid; |
| 5469 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5470 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5471 | clp->cl_seqid = res.seqid; |
| 5472 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5473 | kfree(clp->cl_serverowner); |
| 5474 | clp->cl_serverowner = res.server_owner; |
| 5475 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5476 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5477 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5478 | kfree(clp->cl_implid); |
| 5479 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5480 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5481 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5482 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5483 | res.server_scope)) { |
| 5484 | dprintk("%s: server_scope mismatch detected\n", |
| 5485 | __func__); |
| 5486 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5487 | kfree(clp->cl_serverscope); |
| 5488 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5489 | } |
| 5490 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5491 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5492 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5493 | goto out; |
| 5494 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5495 | } else |
| 5496 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5497 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5498 | out_server_owner: |
| 5499 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5500 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5501 | kfree(res.server_scope); |
| 5502 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5503 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5504 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5505 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5506 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5507 | clp->cl_implid->date.seconds, |
| 5508 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5509 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5510 | return status; |
| 5511 | } |
| 5512 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5513 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5514 | struct rpc_cred *cred) |
| 5515 | { |
| 5516 | struct rpc_message msg = { |
| 5517 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5518 | .rpc_argp = clp, |
| 5519 | .rpc_cred = cred, |
| 5520 | }; |
| 5521 | int status; |
| 5522 | |
| 5523 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5524 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5525 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5526 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5527 | return status; |
| 5528 | } |
| 5529 | |
| 5530 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5531 | struct rpc_cred *cred) |
| 5532 | { |
| 5533 | unsigned int loop; |
| 5534 | int ret; |
| 5535 | |
| 5536 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5537 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5538 | switch (ret) { |
| 5539 | case -NFS4ERR_DELAY: |
| 5540 | case -NFS4ERR_CLIENTID_BUSY: |
| 5541 | ssleep(1); |
| 5542 | break; |
| 5543 | default: |
| 5544 | return ret; |
| 5545 | } |
| 5546 | } |
| 5547 | return 0; |
| 5548 | } |
| 5549 | |
| 5550 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5551 | { |
| 5552 | struct rpc_cred *cred; |
| 5553 | int ret = 0; |
| 5554 | |
| 5555 | if (clp->cl_mvops->minor_version < 1) |
| 5556 | goto out; |
| 5557 | if (clp->cl_exchange_flags == 0) |
| 5558 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5559 | if (clp->cl_preserve_clid) |
| 5560 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5561 | cred = nfs4_get_exchange_id_cred(clp); |
| 5562 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5563 | if (cred) |
| 5564 | put_rpccred(cred); |
| 5565 | switch (ret) { |
| 5566 | case 0: |
| 5567 | case -NFS4ERR_STALE_CLIENTID: |
| 5568 | clp->cl_exchange_flags = 0; |
| 5569 | } |
| 5570 | out: |
| 5571 | return ret; |
| 5572 | } |
| 5573 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5574 | struct nfs4_get_lease_time_data { |
| 5575 | struct nfs4_get_lease_time_args *args; |
| 5576 | struct nfs4_get_lease_time_res *res; |
| 5577 | struct nfs_client *clp; |
| 5578 | }; |
| 5579 | |
| 5580 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5581 | void *calldata) |
| 5582 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5583 | struct nfs4_get_lease_time_data *data = |
| 5584 | (struct nfs4_get_lease_time_data *)calldata; |
| 5585 | |
| 5586 | dprintk("--> %s\n", __func__); |
| 5587 | /* just setup sequence, do not trigger session recovery |
| 5588 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5589 | nfs41_setup_sequence(data->clp->cl_session, |
| 5590 | &data->args->la_seq_args, |
| 5591 | &data->res->lr_seq_res, |
| 5592 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5593 | dprintk("<-- %s\n", __func__); |
| 5594 | } |
| 5595 | |
| 5596 | /* |
| 5597 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5598 | * from sequence operation or clientid errors. |
| 5599 | */ |
| 5600 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5601 | { |
| 5602 | struct nfs4_get_lease_time_data *data = |
| 5603 | (struct nfs4_get_lease_time_data *)calldata; |
| 5604 | |
| 5605 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5606 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5607 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5608 | switch (task->tk_status) { |
| 5609 | case -NFS4ERR_DELAY: |
| 5610 | case -NFS4ERR_GRACE: |
| 5611 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5612 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5613 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5614 | /* fall through */ |
| 5615 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5616 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5617 | return; |
| 5618 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5619 | dprintk("<-- %s\n", __func__); |
| 5620 | } |
| 5621 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5622 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5623 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5624 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5625 | }; |
| 5626 | |
| 5627 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5628 | { |
| 5629 | struct rpc_task *task; |
| 5630 | struct nfs4_get_lease_time_args args; |
| 5631 | struct nfs4_get_lease_time_res res = { |
| 5632 | .lr_fsinfo = fsinfo, |
| 5633 | }; |
| 5634 | struct nfs4_get_lease_time_data data = { |
| 5635 | .args = &args, |
| 5636 | .res = &res, |
| 5637 | .clp = clp, |
| 5638 | }; |
| 5639 | struct rpc_message msg = { |
| 5640 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5641 | .rpc_argp = &args, |
| 5642 | .rpc_resp = &res, |
| 5643 | }; |
| 5644 | struct rpc_task_setup task_setup = { |
| 5645 | .rpc_client = clp->cl_rpcclient, |
| 5646 | .rpc_message = &msg, |
| 5647 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5648 | .callback_data = &data, |
| 5649 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5650 | }; |
| 5651 | int status; |
| 5652 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5653 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5654 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5655 | dprintk("--> %s\n", __func__); |
| 5656 | task = rpc_run_task(&task_setup); |
| 5657 | |
| 5658 | if (IS_ERR(task)) |
| 5659 | status = PTR_ERR(task); |
| 5660 | else { |
| 5661 | status = task->tk_status; |
| 5662 | rpc_put_task(task); |
| 5663 | } |
| 5664 | dprintk("<-- %s return %d\n", __func__, status); |
| 5665 | |
| 5666 | return status; |
| 5667 | } |
| 5668 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5669 | /* |
| 5670 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5671 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5672 | * use them. |
| 5673 | * |
| 5674 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5675 | * always set csa_cachethis to FALSE because the current implementation |
| 5676 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5677 | */ |
| 5678 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5679 | { |
| 5680 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5681 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5682 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5683 | |
| 5684 | if (mxrqst_sz == 0) |
| 5685 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5686 | if (mxresp_sz == 0) |
| 5687 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5688 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5689 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5690 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5691 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5692 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5693 | |
| 5694 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5695 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5696 | __func__, |
| 5697 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5698 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5699 | |
| 5700 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5701 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5702 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5703 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5704 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5705 | args->bc_attrs.max_reqs = 1; |
| 5706 | |
| 5707 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5708 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5709 | __func__, |
| 5710 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5711 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5712 | args->bc_attrs.max_reqs); |
| 5713 | } |
| 5714 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5715 | 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] | 5716 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5717 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5718 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5719 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5720 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5721 | return -EINVAL; |
| 5722 | /* |
| 5723 | * Our requested max_ops is the minimum we need; we're not |
| 5724 | * prepared to break up compounds into smaller pieces than that. |
| 5725 | * So, no point even trying to continue if the server won't |
| 5726 | * cooperate: |
| 5727 | */ |
| 5728 | if (rcvd->max_ops < sent->max_ops) |
| 5729 | return -EINVAL; |
| 5730 | if (rcvd->max_reqs == 0) |
| 5731 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5732 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5733 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5734 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5735 | } |
| 5736 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5737 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5738 | { |
| 5739 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5740 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5741 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5742 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5743 | return -EINVAL; |
| 5744 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5745 | return -EINVAL; |
| 5746 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5747 | return -EINVAL; |
| 5748 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5749 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5750 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5751 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5752 | return -EINVAL; |
| 5753 | return 0; |
| 5754 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5755 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5756 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5757 | struct nfs4_session *session) |
| 5758 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5759 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5760 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5761 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5762 | if (ret) |
| 5763 | return ret; |
| 5764 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5765 | } |
| 5766 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5767 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5768 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5769 | { |
| 5770 | struct nfs4_session *session = clp->cl_session; |
| 5771 | struct nfs41_create_session_args args = { |
| 5772 | .client = clp, |
| 5773 | .cb_program = NFS4_CALLBACK, |
| 5774 | }; |
| 5775 | struct nfs41_create_session_res res = { |
| 5776 | .client = clp, |
| 5777 | }; |
| 5778 | struct rpc_message msg = { |
| 5779 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5780 | .rpc_argp = &args, |
| 5781 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5782 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5783 | }; |
| 5784 | int status; |
| 5785 | |
| 5786 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5787 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5788 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5789 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5790 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5791 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5792 | /* Verify the session's negotiated channel_attrs values */ |
| 5793 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5794 | /* Increment the clientid slot sequence id */ |
| 5795 | clp->cl_seqid++; |
| 5796 | } |
| 5797 | |
| 5798 | return status; |
| 5799 | } |
| 5800 | |
| 5801 | /* |
| 5802 | * Issues a CREATE_SESSION operation to the server. |
| 5803 | * It is the responsibility of the caller to verify the session is |
| 5804 | * expired before calling this routine. |
| 5805 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5806 | 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] | 5807 | { |
| 5808 | int status; |
| 5809 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5810 | struct nfs4_session *session = clp->cl_session; |
| 5811 | |
| 5812 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5813 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5814 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5815 | if (status) |
| 5816 | goto out; |
| 5817 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5818 | /* Init or reset the session slot tables */ |
| 5819 | status = nfs4_setup_session_slot_tables(session); |
| 5820 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5821 | if (status) |
| 5822 | goto out; |
| 5823 | |
| 5824 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5825 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5826 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5827 | out: |
| 5828 | dprintk("<-- %s\n", __func__); |
| 5829 | return status; |
| 5830 | } |
| 5831 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5832 | /* |
| 5833 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5834 | * The caller must serialize access to this routine. |
| 5835 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5836 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5837 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5838 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5839 | struct rpc_message msg = { |
| 5840 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5841 | .rpc_argp = session, |
| 5842 | .rpc_cred = cred, |
| 5843 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5844 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5845 | |
| 5846 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5847 | |
| 5848 | /* session is still being setup */ |
| 5849 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5850 | return status; |
| 5851 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5852 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5853 | |
| 5854 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5855 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5856 | "Session has been destroyed regardless...\n", status); |
| 5857 | |
| 5858 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5859 | return status; |
| 5860 | } |
| 5861 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5862 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5863 | * Renew the cl_session lease. |
| 5864 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5865 | struct nfs4_sequence_data { |
| 5866 | struct nfs_client *clp; |
| 5867 | struct nfs4_sequence_args args; |
| 5868 | struct nfs4_sequence_res res; |
| 5869 | }; |
| 5870 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5871 | static void nfs41_sequence_release(void *data) |
| 5872 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5873 | struct nfs4_sequence_data *calldata = data; |
| 5874 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5875 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5876 | if (atomic_read(&clp->cl_count) > 1) |
| 5877 | nfs4_schedule_state_renewal(clp); |
| 5878 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5879 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5880 | } |
| 5881 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5882 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5883 | { |
| 5884 | switch(task->tk_status) { |
| 5885 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5886 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5887 | return -EAGAIN; |
| 5888 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5889 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5890 | } |
| 5891 | return 0; |
| 5892 | } |
| 5893 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5894 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5895 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5896 | struct nfs4_sequence_data *calldata = data; |
| 5897 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5898 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5899 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5900 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5901 | |
| 5902 | if (task->tk_status < 0) { |
| 5903 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5904 | if (atomic_read(&clp->cl_count) == 1) |
| 5905 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5906 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5907 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5908 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5909 | return; |
| 5910 | } |
| 5911 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5912 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5913 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5914 | dprintk("<-- %s\n", __func__); |
| 5915 | } |
| 5916 | |
| 5917 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5918 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5919 | struct nfs4_sequence_data *calldata = data; |
| 5920 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5921 | struct nfs4_sequence_args *args; |
| 5922 | struct nfs4_sequence_res *res; |
| 5923 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5924 | args = task->tk_msg.rpc_argp; |
| 5925 | res = task->tk_msg.rpc_resp; |
| 5926 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5927 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5931 | .rpc_call_done = nfs41_sequence_call_done, |
| 5932 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5933 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5934 | }; |
| 5935 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5936 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5937 | struct rpc_cred *cred, |
| 5938 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5939 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5940 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5941 | struct rpc_message msg = { |
| 5942 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5943 | .rpc_cred = cred, |
| 5944 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5945 | struct rpc_task_setup task_setup_data = { |
| 5946 | .rpc_client = clp->cl_rpcclient, |
| 5947 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5948 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5949 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5950 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5951 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5952 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5953 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5954 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5955 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5956 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5957 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5958 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5959 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5960 | if (is_privileged) |
| 5961 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5962 | msg.rpc_argp = &calldata->args; |
| 5963 | msg.rpc_resp = &calldata->res; |
| 5964 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5965 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5966 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5967 | return rpc_run_task(&task_setup_data); |
| 5968 | } |
| 5969 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5970 | 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] | 5971 | { |
| 5972 | struct rpc_task *task; |
| 5973 | int ret = 0; |
| 5974 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5975 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5976 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5977 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5978 | if (IS_ERR(task)) |
| 5979 | ret = PTR_ERR(task); |
| 5980 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5981 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5982 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5983 | return ret; |
| 5984 | } |
| 5985 | |
| 5986 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5987 | { |
| 5988 | struct rpc_task *task; |
| 5989 | int ret; |
| 5990 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5991 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5992 | if (IS_ERR(task)) { |
| 5993 | ret = PTR_ERR(task); |
| 5994 | goto out; |
| 5995 | } |
| 5996 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5997 | if (!ret) { |
| 5998 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5999 | |
| 6000 | if (task->tk_status == 0) |
| 6001 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6002 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6003 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6004 | rpc_put_task(task); |
| 6005 | out: |
| 6006 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6007 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6008 | } |
| 6009 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6010 | struct nfs4_reclaim_complete_data { |
| 6011 | struct nfs_client *clp; |
| 6012 | struct nfs41_reclaim_complete_args arg; |
| 6013 | struct nfs41_reclaim_complete_res res; |
| 6014 | }; |
| 6015 | |
| 6016 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6017 | { |
| 6018 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6019 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6020 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6021 | &calldata->arg.seq_args, |
| 6022 | &calldata->res.seq_res, |
| 6023 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6024 | } |
| 6025 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6026 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6027 | { |
| 6028 | switch(task->tk_status) { |
| 6029 | case 0: |
| 6030 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6031 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6032 | break; |
| 6033 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6034 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6035 | /* fall through */ |
| 6036 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6037 | return -EAGAIN; |
| 6038 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6039 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6040 | } |
| 6041 | return 0; |
| 6042 | } |
| 6043 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6044 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6045 | { |
| 6046 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6047 | struct nfs_client *clp = calldata->clp; |
| 6048 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6049 | |
| 6050 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6051 | if (!nfs41_sequence_done(task, res)) |
| 6052 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6053 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6054 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6055 | rpc_restart_call_prepare(task); |
| 6056 | return; |
| 6057 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6058 | dprintk("<-- %s\n", __func__); |
| 6059 | } |
| 6060 | |
| 6061 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6062 | { |
| 6063 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6064 | |
| 6065 | kfree(calldata); |
| 6066 | } |
| 6067 | |
| 6068 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6069 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6070 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6071 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6072 | }; |
| 6073 | |
| 6074 | /* |
| 6075 | * Issue a global reclaim complete. |
| 6076 | */ |
| 6077 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6078 | { |
| 6079 | struct nfs4_reclaim_complete_data *calldata; |
| 6080 | struct rpc_task *task; |
| 6081 | struct rpc_message msg = { |
| 6082 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6083 | }; |
| 6084 | struct rpc_task_setup task_setup_data = { |
| 6085 | .rpc_client = clp->cl_rpcclient, |
| 6086 | .rpc_message = &msg, |
| 6087 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6088 | .flags = RPC_TASK_ASYNC, |
| 6089 | }; |
| 6090 | int status = -ENOMEM; |
| 6091 | |
| 6092 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6093 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6094 | if (calldata == NULL) |
| 6095 | goto out; |
| 6096 | calldata->clp = clp; |
| 6097 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6098 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6099 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6100 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6101 | msg.rpc_argp = &calldata->arg; |
| 6102 | msg.rpc_resp = &calldata->res; |
| 6103 | task_setup_data.callback_data = calldata; |
| 6104 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6105 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6106 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6107 | goto out; |
| 6108 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6109 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6110 | if (status == 0) |
| 6111 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6112 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6113 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6114 | out: |
| 6115 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6116 | return status; |
| 6117 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6118 | |
| 6119 | static void |
| 6120 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6121 | { |
| 6122 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6123 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6124 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6125 | |
| 6126 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6127 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6128 | * right now covering the LAYOUTGET we are about to send. |
| 6129 | * However, that is not so catastrophic, and there seems |
| 6130 | * to be no way to prevent it completely. |
| 6131 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6132 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6133 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6134 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6135 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6136 | NFS_I(lgp->args.inode)->layout, |
| 6137 | lgp->args.ctx->state)) { |
| 6138 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6139 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6143 | { |
| 6144 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6145 | struct inode *inode = lgp->args.inode; |
| 6146 | struct nfs_server *server = NFS_SERVER(inode); |
| 6147 | struct pnfs_layout_hdr *lo; |
| 6148 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6149 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6150 | |
| 6151 | dprintk("--> %s\n", __func__); |
| 6152 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6153 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6154 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6155 | |
| 6156 | switch (task->tk_status) { |
| 6157 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6158 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6159 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6160 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6161 | timeo = rpc_get_timeout(task->tk_client); |
| 6162 | giveup = lgp->args.timestamp + timeo; |
| 6163 | if (time_after(giveup, jiffies)) |
| 6164 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6165 | break; |
| 6166 | case -NFS4ERR_EXPIRED: |
| 6167 | case -NFS4ERR_BAD_STATEID: |
| 6168 | spin_lock(&inode->i_lock); |
| 6169 | lo = NFS_I(inode)->layout; |
| 6170 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6171 | spin_unlock(&inode->i_lock); |
| 6172 | /* If the open stateid was bad, then recover it. */ |
| 6173 | state = lgp->args.ctx->state; |
| 6174 | } else { |
| 6175 | LIST_HEAD(head); |
| 6176 | |
| 6177 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6178 | spin_unlock(&inode->i_lock); |
| 6179 | /* Mark the bad layout state as invalid, then |
| 6180 | * retry using the open stateid. */ |
| 6181 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6182 | } |
| 6183 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6184 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6185 | rpc_restart_call_prepare(task); |
| 6186 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6187 | dprintk("<-- %s\n", __func__); |
| 6188 | } |
| 6189 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6190 | static size_t max_response_pages(struct nfs_server *server) |
| 6191 | { |
| 6192 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6193 | return nfs_page_array_len(0, max_resp_sz); |
| 6194 | } |
| 6195 | |
| 6196 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6197 | { |
| 6198 | int i; |
| 6199 | |
| 6200 | if (!pages) |
| 6201 | return; |
| 6202 | |
| 6203 | for (i = 0; i < size; i++) { |
| 6204 | if (!pages[i]) |
| 6205 | break; |
| 6206 | __free_page(pages[i]); |
| 6207 | } |
| 6208 | kfree(pages); |
| 6209 | } |
| 6210 | |
| 6211 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6212 | { |
| 6213 | struct page **pages; |
| 6214 | int i; |
| 6215 | |
| 6216 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6217 | if (!pages) { |
| 6218 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6219 | return NULL; |
| 6220 | } |
| 6221 | |
| 6222 | for (i = 0; i < size; i++) { |
| 6223 | pages[i] = alloc_page(gfp_flags); |
| 6224 | if (!pages[i]) { |
| 6225 | dprintk("%s: failed to allocate page\n", __func__); |
| 6226 | nfs4_free_pages(pages, size); |
| 6227 | return NULL; |
| 6228 | } |
| 6229 | } |
| 6230 | |
| 6231 | return pages; |
| 6232 | } |
| 6233 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6234 | static void nfs4_layoutget_release(void *calldata) |
| 6235 | { |
| 6236 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6237 | struct inode *inode = lgp->args.inode; |
| 6238 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6239 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6240 | |
| 6241 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6242 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6243 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6244 | put_nfs_open_context(lgp->args.ctx); |
| 6245 | kfree(calldata); |
| 6246 | dprintk("<-- %s\n", __func__); |
| 6247 | } |
| 6248 | |
| 6249 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6250 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6251 | .rpc_call_done = nfs4_layoutget_done, |
| 6252 | .rpc_release = nfs4_layoutget_release, |
| 6253 | }; |
| 6254 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6255 | struct pnfs_layout_segment * |
| 6256 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6257 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6258 | struct inode *inode = lgp->args.inode; |
| 6259 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6260 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6261 | struct rpc_task *task; |
| 6262 | struct rpc_message msg = { |
| 6263 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6264 | .rpc_argp = &lgp->args, |
| 6265 | .rpc_resp = &lgp->res, |
| 6266 | }; |
| 6267 | struct rpc_task_setup task_setup_data = { |
| 6268 | .rpc_client = server->client, |
| 6269 | .rpc_message = &msg, |
| 6270 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6271 | .callback_data = lgp, |
| 6272 | .flags = RPC_TASK_ASYNC, |
| 6273 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6274 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6275 | int status = 0; |
| 6276 | |
| 6277 | dprintk("--> %s\n", __func__); |
| 6278 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6279 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6280 | if (!lgp->args.layout.pages) { |
| 6281 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6282 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6283 | } |
| 6284 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6285 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6286 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6287 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6288 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6289 | 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] | 6290 | |
| 6291 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6292 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6293 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6294 | task = rpc_run_task(&task_setup_data); |
| 6295 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6296 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6297 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6298 | if (status == 0) |
| 6299 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6300 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6301 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6302 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6303 | rpc_put_task(task); |
| 6304 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6305 | if (status) |
| 6306 | return ERR_PTR(status); |
| 6307 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6308 | } |
| 6309 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6310 | static void |
| 6311 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6312 | { |
| 6313 | struct nfs4_layoutreturn *lrp = calldata; |
| 6314 | |
| 6315 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6316 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6317 | &lrp->args.seq_args, |
| 6318 | &lrp->res.seq_res, |
| 6319 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6323 | { |
| 6324 | struct nfs4_layoutreturn *lrp = calldata; |
| 6325 | struct nfs_server *server; |
| 6326 | |
| 6327 | dprintk("--> %s\n", __func__); |
| 6328 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6329 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6330 | return; |
| 6331 | |
| 6332 | server = NFS_SERVER(lrp->args.inode); |
| 6333 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6334 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6335 | return; |
| 6336 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6337 | dprintk("<-- %s\n", __func__); |
| 6338 | } |
| 6339 | |
| 6340 | static void nfs4_layoutreturn_release(void *calldata) |
| 6341 | { |
| 6342 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6343 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6344 | |
| 6345 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6346 | spin_lock(&lo->plh_inode->i_lock); |
| 6347 | if (lrp->res.lrs_present) |
| 6348 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6349 | lo->plh_block_lgets--; |
| 6350 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6351 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6352 | kfree(calldata); |
| 6353 | dprintk("<-- %s\n", __func__); |
| 6354 | } |
| 6355 | |
| 6356 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6357 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6358 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6359 | .rpc_release = nfs4_layoutreturn_release, |
| 6360 | }; |
| 6361 | |
| 6362 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6363 | { |
| 6364 | struct rpc_task *task; |
| 6365 | struct rpc_message msg = { |
| 6366 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6367 | .rpc_argp = &lrp->args, |
| 6368 | .rpc_resp = &lrp->res, |
| 6369 | }; |
| 6370 | struct rpc_task_setup task_setup_data = { |
| 6371 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6372 | .rpc_message = &msg, |
| 6373 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6374 | .callback_data = lrp, |
| 6375 | }; |
| 6376 | int status; |
| 6377 | |
| 6378 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6379 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6380 | task = rpc_run_task(&task_setup_data); |
| 6381 | if (IS_ERR(task)) |
| 6382 | return PTR_ERR(task); |
| 6383 | status = task->tk_status; |
| 6384 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6385 | rpc_put_task(task); |
| 6386 | return status; |
| 6387 | } |
| 6388 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6389 | /* |
| 6390 | * Retrieve the list of Data Server devices from the MDS. |
| 6391 | */ |
| 6392 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6393 | const struct nfs_fh *fh, |
| 6394 | struct pnfs_devicelist *devlist) |
| 6395 | { |
| 6396 | struct nfs4_getdevicelist_args args = { |
| 6397 | .fh = fh, |
| 6398 | .layoutclass = server->pnfs_curr_ld->id, |
| 6399 | }; |
| 6400 | struct nfs4_getdevicelist_res res = { |
| 6401 | .devlist = devlist, |
| 6402 | }; |
| 6403 | struct rpc_message msg = { |
| 6404 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6405 | .rpc_argp = &args, |
| 6406 | .rpc_resp = &res, |
| 6407 | }; |
| 6408 | int status; |
| 6409 | |
| 6410 | dprintk("--> %s\n", __func__); |
| 6411 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6412 | &res.seq_res, 0); |
| 6413 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6414 | return status; |
| 6415 | } |
| 6416 | |
| 6417 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6418 | const struct nfs_fh *fh, |
| 6419 | struct pnfs_devicelist *devlist) |
| 6420 | { |
| 6421 | struct nfs4_exception exception = { }; |
| 6422 | int err; |
| 6423 | |
| 6424 | do { |
| 6425 | err = nfs4_handle_exception(server, |
| 6426 | _nfs4_getdevicelist(server, fh, devlist), |
| 6427 | &exception); |
| 6428 | } while (exception.retry); |
| 6429 | |
| 6430 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6431 | err, devlist->num_devs); |
| 6432 | |
| 6433 | return err; |
| 6434 | } |
| 6435 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6436 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6437 | static int |
| 6438 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6439 | { |
| 6440 | struct nfs4_getdeviceinfo_args args = { |
| 6441 | .pdev = pdev, |
| 6442 | }; |
| 6443 | struct nfs4_getdeviceinfo_res res = { |
| 6444 | .pdev = pdev, |
| 6445 | }; |
| 6446 | struct rpc_message msg = { |
| 6447 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6448 | .rpc_argp = &args, |
| 6449 | .rpc_resp = &res, |
| 6450 | }; |
| 6451 | int status; |
| 6452 | |
| 6453 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6454 | 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] | 6455 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6456 | |
| 6457 | return status; |
| 6458 | } |
| 6459 | |
| 6460 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6461 | { |
| 6462 | struct nfs4_exception exception = { }; |
| 6463 | int err; |
| 6464 | |
| 6465 | do { |
| 6466 | err = nfs4_handle_exception(server, |
| 6467 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6468 | &exception); |
| 6469 | } while (exception.retry); |
| 6470 | return err; |
| 6471 | } |
| 6472 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6473 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6474 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6475 | { |
| 6476 | struct nfs4_layoutcommit_data *data = calldata; |
| 6477 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6478 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6479 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6480 | nfs41_setup_sequence(session, |
| 6481 | &data->args.seq_args, |
| 6482 | &data->res.seq_res, |
| 6483 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6484 | } |
| 6485 | |
| 6486 | static void |
| 6487 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6488 | { |
| 6489 | struct nfs4_layoutcommit_data *data = calldata; |
| 6490 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6491 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6492 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6493 | return; |
| 6494 | |
| 6495 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6496 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6497 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6498 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6499 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6500 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6501 | break; |
| 6502 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6503 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6504 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6505 | break; |
| 6506 | default: |
| 6507 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6508 | rpc_restart_call_prepare(task); |
| 6509 | return; |
| 6510 | } |
| 6511 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6512 | } |
| 6513 | |
| 6514 | static void nfs4_layoutcommit_release(void *calldata) |
| 6515 | { |
| 6516 | struct nfs4_layoutcommit_data *data = calldata; |
| 6517 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6518 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6519 | put_rpccred(data->cred); |
| 6520 | kfree(data); |
| 6521 | } |
| 6522 | |
| 6523 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6524 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6525 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6526 | .rpc_release = nfs4_layoutcommit_release, |
| 6527 | }; |
| 6528 | |
| 6529 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6530 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6531 | { |
| 6532 | struct rpc_message msg = { |
| 6533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6534 | .rpc_argp = &data->args, |
| 6535 | .rpc_resp = &data->res, |
| 6536 | .rpc_cred = data->cred, |
| 6537 | }; |
| 6538 | struct rpc_task_setup task_setup_data = { |
| 6539 | .task = &data->task, |
| 6540 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6541 | .rpc_message = &msg, |
| 6542 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6543 | .callback_data = data, |
| 6544 | .flags = RPC_TASK_ASYNC, |
| 6545 | }; |
| 6546 | struct rpc_task *task; |
| 6547 | int status = 0; |
| 6548 | |
| 6549 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6550 | "lbw: %llu inode %lu\n", |
| 6551 | data->task.tk_pid, sync, |
| 6552 | data->args.lastbytewritten, |
| 6553 | data->args.inode->i_ino); |
| 6554 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6555 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6556 | task = rpc_run_task(&task_setup_data); |
| 6557 | if (IS_ERR(task)) |
| 6558 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6559 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6560 | goto out; |
| 6561 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6562 | if (status != 0) |
| 6563 | goto out; |
| 6564 | status = task->tk_status; |
| 6565 | out: |
| 6566 | dprintk("%s: status %d\n", __func__, status); |
| 6567 | rpc_put_task(task); |
| 6568 | return status; |
| 6569 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6570 | |
| 6571 | static int |
| 6572 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6573 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6574 | { |
| 6575 | struct nfs41_secinfo_no_name_args args = { |
| 6576 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6577 | }; |
| 6578 | struct nfs4_secinfo_res res = { |
| 6579 | .flavors = flavors, |
| 6580 | }; |
| 6581 | struct rpc_message msg = { |
| 6582 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6583 | .rpc_argp = &args, |
| 6584 | .rpc_resp = &res, |
| 6585 | }; |
| 6586 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6587 | } |
| 6588 | |
| 6589 | static int |
| 6590 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6591 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6592 | { |
| 6593 | struct nfs4_exception exception = { }; |
| 6594 | int err; |
| 6595 | do { |
| 6596 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6597 | switch (err) { |
| 6598 | case 0: |
| 6599 | case -NFS4ERR_WRONGSEC: |
| 6600 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6601 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6602 | default: |
| 6603 | err = nfs4_handle_exception(server, err, &exception); |
| 6604 | } |
| 6605 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6606 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6607 | return err; |
| 6608 | } |
| 6609 | |
| 6610 | static int |
| 6611 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6612 | struct nfs_fsinfo *info) |
| 6613 | { |
| 6614 | int err; |
| 6615 | struct page *page; |
| 6616 | rpc_authflavor_t flavor; |
| 6617 | struct nfs4_secinfo_flavors *flavors; |
| 6618 | |
| 6619 | page = alloc_page(GFP_KERNEL); |
| 6620 | if (!page) { |
| 6621 | err = -ENOMEM; |
| 6622 | goto out; |
| 6623 | } |
| 6624 | |
| 6625 | flavors = page_address(page); |
| 6626 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6627 | |
| 6628 | /* |
| 6629 | * Fall back on "guess and check" method if |
| 6630 | * the server doesn't support SECINFO_NO_NAME |
| 6631 | */ |
| 6632 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6633 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6634 | goto out_freepage; |
| 6635 | } |
| 6636 | if (err) |
| 6637 | goto out_freepage; |
| 6638 | |
| 6639 | flavor = nfs_find_best_sec(flavors); |
| 6640 | if (err == 0) |
| 6641 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6642 | |
| 6643 | out_freepage: |
| 6644 | put_page(page); |
| 6645 | if (err == -EACCES) |
| 6646 | return -EPERM; |
| 6647 | out: |
| 6648 | return err; |
| 6649 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6650 | |
| 6651 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6652 | { |
| 6653 | int status; |
| 6654 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6655 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6656 | }; |
| 6657 | struct nfs41_test_stateid_res res; |
| 6658 | struct rpc_message msg = { |
| 6659 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6660 | .rpc_argp = &args, |
| 6661 | .rpc_resp = &res, |
| 6662 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6663 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6664 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6665 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6666 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6667 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6668 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6669 | if (status != NFS_OK) { |
| 6670 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6671 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6672 | } |
| 6673 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6674 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6675 | } |
| 6676 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6677 | /** |
| 6678 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6679 | * |
| 6680 | * @server: server / transport on which to perform the operation |
| 6681 | * @stateid: state ID to test |
| 6682 | * |
| 6683 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6684 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6685 | * failed or the state ID is not currently valid. |
| 6686 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6687 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6688 | { |
| 6689 | struct nfs4_exception exception = { }; |
| 6690 | int err; |
| 6691 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6692 | err = _nfs41_test_stateid(server, stateid); |
| 6693 | if (err != -NFS4ERR_DELAY) |
| 6694 | break; |
| 6695 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6696 | } while (exception.retry); |
| 6697 | return err; |
| 6698 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6699 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6700 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6701 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6702 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6703 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6704 | }; |
| 6705 | struct nfs41_free_stateid_res res; |
| 6706 | struct rpc_message msg = { |
| 6707 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6708 | .rpc_argp = &args, |
| 6709 | .rpc_resp = &res, |
| 6710 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6711 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6712 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6713 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6714 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6715 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6716 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6717 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6718 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6719 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6720 | } |
| 6721 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6722 | /** |
| 6723 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6724 | * |
| 6725 | * @server: server / transport on which to perform the operation |
| 6726 | * @stateid: state ID to release |
| 6727 | * |
| 6728 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6729 | * negative NFS4ERR value is returned. |
| 6730 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6731 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6732 | { |
| 6733 | struct nfs4_exception exception = { }; |
| 6734 | int err; |
| 6735 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6736 | err = _nfs4_free_stateid(server, stateid); |
| 6737 | if (err != -NFS4ERR_DELAY) |
| 6738 | break; |
| 6739 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6740 | } while (exception.retry); |
| 6741 | return err; |
| 6742 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6743 | |
| 6744 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6745 | const nfs4_stateid *s2) |
| 6746 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6747 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6748 | return false; |
| 6749 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6750 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6751 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6752 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6753 | return true; |
| 6754 | |
| 6755 | return false; |
| 6756 | } |
| 6757 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6758 | #endif /* CONFIG_NFS_V4_1 */ |
| 6759 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6760 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6761 | const nfs4_stateid *s2) |
| 6762 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6763 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6764 | } |
| 6765 | |
| 6766 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6767 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6768 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6769 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6770 | .recover_open = nfs4_open_reclaim, |
| 6771 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6772 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6773 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6774 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6775 | }; |
| 6776 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6777 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6778 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6779 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6780 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6781 | .recover_open = nfs4_open_reclaim, |
| 6782 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6783 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6784 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6785 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6786 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6787 | }; |
| 6788 | #endif /* CONFIG_NFS_V4_1 */ |
| 6789 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6790 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6791 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6792 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | .recover_open = nfs4_open_expired, |
| 6794 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6795 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6796 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6797 | }; |
| 6798 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6799 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6800 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6801 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6802 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6803 | .recover_open = nfs41_open_expired, |
| 6804 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6805 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6806 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6807 | }; |
| 6808 | #endif /* CONFIG_NFS_V4_1 */ |
| 6809 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6810 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6811 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6812 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6813 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6814 | }; |
| 6815 | |
| 6816 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6817 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6818 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6819 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6820 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6821 | }; |
| 6822 | #endif |
| 6823 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6824 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6825 | .minor_version = 0, |
| 6826 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6827 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6828 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6829 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6830 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6831 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6832 | }; |
| 6833 | |
| 6834 | #if defined(CONFIG_NFS_V4_1) |
| 6835 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6836 | .minor_version = 1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6837 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6838 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6839 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6840 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6841 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6842 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6843 | }; |
| 6844 | #endif |
| 6845 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6846 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6847 | [0] = &nfs_v4_0_minor_ops, |
| 6848 | #if defined(CONFIG_NFS_V4_1) |
| 6849 | [1] = &nfs_v4_1_minor_ops, |
| 6850 | #endif |
| 6851 | }; |
| 6852 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6853 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6854 | .create = nfs_create, |
| 6855 | .lookup = nfs_lookup, |
| 6856 | .atomic_open = nfs_atomic_open, |
| 6857 | .link = nfs_link, |
| 6858 | .unlink = nfs_unlink, |
| 6859 | .symlink = nfs_symlink, |
| 6860 | .mkdir = nfs_mkdir, |
| 6861 | .rmdir = nfs_rmdir, |
| 6862 | .mknod = nfs_mknod, |
| 6863 | .rename = nfs_rename, |
| 6864 | .permission = nfs_permission, |
| 6865 | .getattr = nfs_getattr, |
| 6866 | .setattr = nfs_setattr, |
| 6867 | .getxattr = generic_getxattr, |
| 6868 | .setxattr = generic_setxattr, |
| 6869 | .listxattr = generic_listxattr, |
| 6870 | .removexattr = generic_removexattr, |
| 6871 | }; |
| 6872 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6873 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6874 | .permission = nfs_permission, |
| 6875 | .getattr = nfs_getattr, |
| 6876 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6877 | .getxattr = generic_getxattr, |
| 6878 | .setxattr = generic_setxattr, |
| 6879 | .listxattr = generic_listxattr, |
| 6880 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6881 | }; |
| 6882 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6883 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6884 | .version = 4, /* protocol version */ |
| 6885 | .dentry_ops = &nfs4_dentry_operations, |
| 6886 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6887 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6888 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6889 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6890 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6891 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6892 | .getattr = nfs4_proc_getattr, |
| 6893 | .setattr = nfs4_proc_setattr, |
| 6894 | .lookup = nfs4_proc_lookup, |
| 6895 | .access = nfs4_proc_access, |
| 6896 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6897 | .create = nfs4_proc_create, |
| 6898 | .remove = nfs4_proc_remove, |
| 6899 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6900 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6901 | .unlink_done = nfs4_proc_unlink_done, |
| 6902 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6903 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6904 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6905 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6906 | .link = nfs4_proc_link, |
| 6907 | .symlink = nfs4_proc_symlink, |
| 6908 | .mkdir = nfs4_proc_mkdir, |
| 6909 | .rmdir = nfs4_proc_remove, |
| 6910 | .readdir = nfs4_proc_readdir, |
| 6911 | .mknod = nfs4_proc_mknod, |
| 6912 | .statfs = nfs4_proc_statfs, |
| 6913 | .fsinfo = nfs4_proc_fsinfo, |
| 6914 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6915 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6916 | .decode_dirent = nfs4_decode_dirent, |
| 6917 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6918 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6919 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6920 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6921 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6922 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6923 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6924 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6925 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6926 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6927 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6928 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6929 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6930 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6931 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6932 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6933 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6934 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6935 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6936 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6937 | .create_server = nfs4_create_server, |
| 6938 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6939 | }; |
| 6940 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6941 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6942 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6943 | .list = nfs4_xattr_list_nfs4_acl, |
| 6944 | .get = nfs4_xattr_get_nfs4_acl, |
| 6945 | .set = nfs4_xattr_set_nfs4_acl, |
| 6946 | }; |
| 6947 | |
| 6948 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6949 | &nfs4_xattr_nfs4_acl_handler, |
| 6950 | NULL |
| 6951 | }; |
| 6952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6953 | /* |
| 6954 | * Local variables: |
| 6955 | * c-basic-offset: 8 |
| 6956 | * End: |
| 6957 | */ |