Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 70 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 73 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 74 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 75 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 76 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 78 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 79 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 80 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 81 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 82 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 83 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 84 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 85 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 86 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 87 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 90 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 92 | if (err >= -1000) |
| 93 | return err; |
| 94 | switch (err) { |
| 95 | case -NFS4ERR_RESOURCE: |
| 96 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 97 | case -NFS4ERR_WRONGSEC: |
| 98 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 99 | case -NFS4ERR_BADOWNER: |
| 100 | case -NFS4ERR_BADNAME: |
| 101 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 102 | case -NFS4ERR_SHARE_DENIED: |
| 103 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 104 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 105 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 106 | case -NFS4ERR_ACCESS: |
| 107 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 108 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 110 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 111 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 113 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
| 117 | * This is our standard bitmap for GETATTR requests. |
| 118 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 119 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | FATTR4_WORD0_TYPE |
| 121 | | FATTR4_WORD0_CHANGE |
| 122 | | FATTR4_WORD0_SIZE |
| 123 | | FATTR4_WORD0_FSID |
| 124 | | FATTR4_WORD0_FILEID, |
| 125 | FATTR4_WORD1_MODE |
| 126 | | FATTR4_WORD1_NUMLINKS |
| 127 | | FATTR4_WORD1_OWNER |
| 128 | | FATTR4_WORD1_OWNER_GROUP |
| 129 | | FATTR4_WORD1_RAWDEV |
| 130 | | FATTR4_WORD1_SPACE_USED |
| 131 | | FATTR4_WORD1_TIME_ACCESS |
| 132 | | FATTR4_WORD1_TIME_METADATA |
| 133 | | FATTR4_WORD1_TIME_MODIFY |
| 134 | }; |
| 135 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 136 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 137 | FATTR4_WORD0_TYPE |
| 138 | | FATTR4_WORD0_CHANGE |
| 139 | | FATTR4_WORD0_SIZE |
| 140 | | FATTR4_WORD0_FSID |
| 141 | | FATTR4_WORD0_FILEID, |
| 142 | FATTR4_WORD1_MODE |
| 143 | | FATTR4_WORD1_NUMLINKS |
| 144 | | FATTR4_WORD1_OWNER |
| 145 | | FATTR4_WORD1_OWNER_GROUP |
| 146 | | FATTR4_WORD1_RAWDEV |
| 147 | | FATTR4_WORD1_SPACE_USED |
| 148 | | FATTR4_WORD1_TIME_ACCESS |
| 149 | | FATTR4_WORD1_TIME_METADATA |
| 150 | | FATTR4_WORD1_TIME_MODIFY, |
| 151 | FATTR4_WORD2_MDSTHRESHOLD |
| 152 | }; |
| 153 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 154 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 155 | FATTR4_WORD0_TYPE |
| 156 | | FATTR4_WORD0_CHANGE |
| 157 | | FATTR4_WORD0_FILEID, |
| 158 | }; |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | const u32 nfs4_statfs_bitmap[2] = { |
| 161 | FATTR4_WORD0_FILES_AVAIL |
| 162 | | FATTR4_WORD0_FILES_FREE |
| 163 | | FATTR4_WORD0_FILES_TOTAL, |
| 164 | FATTR4_WORD1_SPACE_AVAIL |
| 165 | | FATTR4_WORD1_SPACE_FREE |
| 166 | | FATTR4_WORD1_SPACE_TOTAL |
| 167 | }; |
| 168 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 169 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | FATTR4_WORD0_MAXLINK |
| 171 | | FATTR4_WORD0_MAXNAME, |
| 172 | 0 |
| 173 | }; |
| 174 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 175 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | | FATTR4_WORD0_MAXREAD |
| 177 | | FATTR4_WORD0_MAXWRITE |
| 178 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 179 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 180 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 181 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 184 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 185 | FATTR4_WORD0_TYPE |
| 186 | | FATTR4_WORD0_CHANGE |
| 187 | | FATTR4_WORD0_SIZE |
| 188 | | FATTR4_WORD0_FSID |
| 189 | | FATTR4_WORD0_FILEID |
| 190 | | FATTR4_WORD0_FS_LOCATIONS, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
| 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 201 | }; |
| 202 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 203 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | struct nfs4_readdir_arg *readdir) |
| 205 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 206 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 209 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | readdir->cookie = 0; |
| 215 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 216 | if (cookie == 2) |
| 217 | return; |
| 218 | |
| 219 | /* |
| 220 | * NFSv4 servers do not return entries for '.' and '..' |
| 221 | * Therefore, we fake these entries here. We let '.' |
| 222 | * have cookie 0 and '..' have cookie 1. Note that |
| 223 | * when talking to the server, we always send cookie 0 |
| 224 | * instead of 1 or 2. |
| 225 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 226 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | if (cookie == 0) { |
| 229 | *p++ = xdr_one; /* next */ |
| 230 | *p++ = xdr_zero; /* cookie, first word */ |
| 231 | *p++ = xdr_one; /* cookie, second word */ |
| 232 | *p++ = xdr_one; /* entry len */ |
| 233 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 234 | p++; |
| 235 | *p++ = xdr_one; /* bitmap length */ |
| 236 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 237 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 238 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | *p++ = xdr_one; /* next */ |
| 242 | *p++ = xdr_zero; /* cookie, first word */ |
| 243 | *p++ = xdr_two; /* cookie, second word */ |
| 244 | *p++ = xdr_two; /* entry len */ |
| 245 | memcpy(p, "..\0\0", 4); /* entry */ |
| 246 | p++; |
| 247 | *p++ = xdr_one; /* bitmap length */ |
| 248 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 249 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 250 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | readdir->pgbase = (char *)p - (char *)start; |
| 253 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 254 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 257 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 258 | { |
| 259 | int res = 0; |
| 260 | |
| 261 | might_sleep(); |
| 262 | |
| 263 | if (*timeout <= 0) |
| 264 | *timeout = NFS4_POLL_RETRY_MIN; |
| 265 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 266 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 267 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 268 | if (fatal_signal_pending(current)) |
| 269 | res = -ERESTARTSYS; |
| 270 | *timeout <<= 1; |
| 271 | return res; |
| 272 | } |
| 273 | |
| 274 | /* This is the error handling routine for processes that are allowed |
| 275 | * to sleep. |
| 276 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 277 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 278 | { |
| 279 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 280 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 281 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 282 | int ret = errorcode; |
| 283 | |
| 284 | exception->retry = 0; |
| 285 | switch(errorcode) { |
| 286 | case 0: |
| 287 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 288 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 289 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 290 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 291 | exception->retry = 1; |
| 292 | return 0; |
| 293 | } |
| 294 | if (state == NULL) |
| 295 | break; |
| 296 | nfs4_schedule_stateid_recovery(server, state); |
| 297 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 298 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 299 | case -NFS4ERR_ADMIN_REVOKED: |
| 300 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 301 | if (state == NULL) |
| 302 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 303 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 304 | nfs4_schedule_stateid_recovery(server, state); |
| 305 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 306 | case -NFS4ERR_EXPIRED: |
| 307 | if (state != NULL) |
| 308 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 309 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 310 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 311 | nfs4_schedule_lease_recovery(clp); |
| 312 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 313 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 314 | case -NFS4ERR_BADSESSION: |
| 315 | case -NFS4ERR_BADSLOT: |
| 316 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 317 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 318 | case -NFS4ERR_DEADSESSION: |
| 319 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 320 | case -NFS4ERR_SEQ_MISORDERED: |
| 321 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 322 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 323 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 324 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 325 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 327 | if (exception->timeout > HZ) { |
| 328 | /* We have retried a decent amount, time to |
| 329 | * fail |
| 330 | */ |
| 331 | ret = -EBUSY; |
| 332 | break; |
| 333 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 334 | case -NFS4ERR_GRACE: |
| 335 | case -NFS4ERR_DELAY: |
| 336 | ret = nfs4_delay(server->client, &exception->timeout); |
| 337 | if (ret != 0) |
| 338 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 339 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 340 | case -NFS4ERR_OLD_STATEID: |
| 341 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 342 | break; |
| 343 | case -NFS4ERR_BADOWNER: |
| 344 | /* The following works around a Linux server bug! */ |
| 345 | case -NFS4ERR_BADNAME: |
| 346 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 347 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 348 | exception->retry = 1; |
| 349 | printk(KERN_WARNING "NFS: v4 server %s " |
| 350 | "does not accept raw " |
| 351 | "uid/gids. " |
| 352 | "Reenabling the idmapper.\n", |
| 353 | server->nfs_client->cl_hostname); |
| 354 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | } |
| 356 | /* We failed to handle the error */ |
| 357 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 358 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 359 | ret = nfs4_wait_clnt_recover(clp); |
| 360 | if (ret == 0) |
| 361 | exception->retry = 1; |
| 362 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 366 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | spin_lock(&clp->cl_lock); |
| 369 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 370 | clp->cl_last_renewal = timestamp; |
| 371 | spin_unlock(&clp->cl_lock); |
| 372 | } |
| 373 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 374 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 375 | { |
| 376 | do_renew_lease(server->nfs_client, timestamp); |
| 377 | } |
| 378 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 379 | #if defined(CONFIG_NFS_V4_1) |
| 380 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 381 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 382 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 383 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 384 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 385 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 386 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 387 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 388 | /* just wake up the next guy waiting since |
| 389 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 390 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 391 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 392 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 393 | tbl = res->sr_slot->table; |
| 394 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 395 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 396 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 397 | /* Be nice to the server: try to ensure that the last transmitted |
| 398 | * value for highest_user_slotid <= target_highest_slotid |
| 399 | */ |
| 400 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 401 | send_new_highest_used_slotid = true; |
| 402 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 403 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 404 | send_new_highest_used_slotid = false; |
| 405 | goto out_unlock; |
| 406 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 407 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 408 | |
| 409 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 410 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 411 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 412 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 413 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 414 | if (send_new_highest_used_slotid) |
| 415 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 418 | static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 419 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 420 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 421 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 422 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 423 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 424 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 425 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 426 | /* don't increment the sequence number if the task wasn't sent */ |
| 427 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 428 | goto out; |
| 429 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 430 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 431 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 432 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 433 | if (slot->interrupted) { |
| 434 | slot->interrupted = 0; |
| 435 | interrupted = true; |
| 436 | } |
| 437 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 438 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | switch (res->sr_status) { |
| 440 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 441 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 442 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 443 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 444 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 445 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 446 | if (res->sr_status_flags != 0) |
| 447 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 448 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 449 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 450 | case 1: |
| 451 | /* |
| 452 | * sr_status remains 1 if an RPC level error occurred. |
| 453 | * The server may or may not have processed the sequence |
| 454 | * operation.. |
| 455 | * Mark the slot as having hosted an interrupted RPC call. |
| 456 | */ |
| 457 | slot->interrupted = 1; |
| 458 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | case -NFS4ERR_DELAY: |
| 460 | /* The server detected a resend of the RPC call and |
| 461 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 462 | * of RFC5661. |
| 463 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 464 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 465 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 466 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 467 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 469 | case -NFS4ERR_BADSLOT: |
| 470 | /* |
| 471 | * The slot id we used was probably retired. Try again |
| 472 | * using a different slot id. |
| 473 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 474 | goto retry_nowait; |
| 475 | case -NFS4ERR_SEQ_MISORDERED: |
| 476 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 477 | * Was the last operation on this sequence interrupted? |
| 478 | * If so, retry after bumping the sequence number. |
| 479 | */ |
| 480 | if (interrupted) { |
| 481 | ++slot->seq_nr; |
| 482 | goto retry_nowait; |
| 483 | } |
| 484 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 485 | * Could this slot have been previously retired? |
| 486 | * If so, then the server may be expecting seq_nr = 1! |
| 487 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 488 | if (slot->seq_nr != 1) { |
| 489 | slot->seq_nr = 1; |
| 490 | goto retry_nowait; |
| 491 | } |
| 492 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 493 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 494 | ++slot->seq_nr; |
| 495 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | default: |
| 497 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 498 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 499 | } |
| 500 | out: |
| 501 | /* The session may be reset by one of the error handlers. */ |
| 502 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 503 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 504 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 505 | retry_nowait: |
| 506 | if (rpc_restart_call_prepare(task)) { |
| 507 | task->tk_status = 0; |
| 508 | ret = 0; |
| 509 | } |
| 510 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 511 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 512 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | goto out; |
| 514 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 515 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 518 | static int nfs4_sequence_done(struct rpc_task *task, |
| 519 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 520 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 521 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 522 | return 1; |
| 523 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 526 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 527 | struct nfs4_sequence_res *res, int cache_reply) |
| 528 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 529 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 530 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 531 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 532 | if (cache_reply) |
| 533 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 534 | res->sr_slot = NULL; |
| 535 | } |
| 536 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 537 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 538 | { |
| 539 | args->sa_privileged = 1; |
| 540 | } |
| 541 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 542 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 543 | struct nfs4_sequence_args *args, |
| 544 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 545 | struct rpc_task *task) |
| 546 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 547 | struct nfs4_slot *slot; |
| 548 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 549 | |
| 550 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 551 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 552 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 553 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 554 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 555 | tbl = &session->fc_slot_table; |
| 556 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 557 | task->tk_timeout = 0; |
| 558 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 559 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 560 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 561 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 562 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 563 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 564 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 567 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 568 | if (IS_ERR(slot)) { |
| 569 | /* If out of memory, try again in 1/4 second */ |
| 570 | if (slot == ERR_PTR(-ENOMEM)) |
| 571 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 572 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 573 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 574 | } |
| 575 | spin_unlock(&tbl->slot_tbl_lock); |
| 576 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 577 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 578 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 579 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 580 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 581 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 582 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 583 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 584 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 585 | /* |
| 586 | * sr_status is only set in decode_sequence, and so will remain |
| 587 | * set to 1 if an rpc level failure occurs. |
| 588 | */ |
| 589 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 590 | out_success: |
| 591 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 592 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 593 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 594 | /* Privileged tasks are queued with top priority */ |
| 595 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 596 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 597 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 598 | else |
| 599 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 600 | spin_unlock(&tbl->slot_tbl_lock); |
| 601 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 602 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 603 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 605 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 606 | struct nfs4_sequence_args *args, |
| 607 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 608 | struct rpc_task *task) |
| 609 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 610 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 611 | int ret = 0; |
| 612 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 613 | if (session == NULL) { |
| 614 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 616 | } |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 617 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 618 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 619 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 620 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 621 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 622 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | out: |
| 624 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | struct nfs4_sequence_args *seq_args; |
| 631 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | }; |
| 633 | |
| 634 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 635 | { |
| 636 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 637 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 638 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 639 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 640 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 641 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 642 | } |
| 643 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 644 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 645 | { |
| 646 | struct nfs41_call_sync_data *data = calldata; |
| 647 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 648 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 651 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 652 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 653 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | }; |
| 655 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 656 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 657 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 658 | struct rpc_message *msg, |
| 659 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 660 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | { |
| 662 | int ret; |
| 663 | struct rpc_task *task; |
| 664 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 665 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 666 | .seq_args = args, |
| 667 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 668 | }; |
| 669 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 670 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | .rpc_message = msg, |
| 672 | .callback_ops = &nfs41_call_sync_ops, |
| 673 | .callback_data = &data |
| 674 | }; |
| 675 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 676 | task = rpc_run_task(&task_setup); |
| 677 | if (IS_ERR(task)) |
| 678 | ret = PTR_ERR(task); |
| 679 | else { |
| 680 | ret = task->tk_status; |
| 681 | rpc_put_task(task); |
| 682 | } |
| 683 | return ret; |
| 684 | } |
| 685 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 687 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 688 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 689 | struct nfs4_sequence_res *res, int cache_reply) |
| 690 | { |
| 691 | } |
| 692 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 693 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 694 | { |
| 695 | } |
| 696 | |
| 697 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 698 | static int nfs4_sequence_done(struct rpc_task *task, |
| 699 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 700 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 701 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 702 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 703 | #endif /* CONFIG_NFS_V4_1 */ |
| 704 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 705 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 706 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 707 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 708 | struct rpc_message *msg, |
| 709 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 710 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 711 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 712 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 715 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 716 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 717 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 718 | struct rpc_message *msg, |
| 719 | struct nfs4_sequence_args *args, |
| 720 | struct nfs4_sequence_res *res, |
| 721 | int cache_reply) |
| 722 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 723 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 724 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 725 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 726 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 727 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 728 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 730 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 732 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 733 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 734 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 735 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 736 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 737 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 738 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 741 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 742 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 743 | struct nfs_openargs o_arg; |
| 744 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 745 | struct nfs_open_confirmargs c_arg; |
| 746 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 747 | struct nfs4_string owner_name; |
| 748 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 749 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 750 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 751 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 752 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 753 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 754 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 755 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 756 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 757 | int rpc_status; |
| 758 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | }; |
| 760 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 761 | |
| 762 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 763 | { |
| 764 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 765 | p->o_res.seqid = p->o_arg.seqid; |
| 766 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 767 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 768 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 769 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 770 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 773 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 774 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 775 | const struct iattr *attrs, |
| 776 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 777 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 778 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 779 | struct inode *dir = parent->d_inode; |
| 780 | struct nfs_server *server = NFS_SERVER(dir); |
| 781 | struct nfs4_opendata *p; |
| 782 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 783 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 784 | if (p == NULL) |
| 785 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 786 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 787 | if (p->o_arg.seqid == NULL) |
| 788 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 789 | nfs_sb_active(dentry->d_sb); |
| 790 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | p->dir = parent; |
| 792 | p->owner = sp; |
| 793 | atomic_inc(&sp->so_count); |
| 794 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 795 | p->o_arg.open_flags = flags; |
| 796 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 797 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 798 | * will return permission denied for all bits until close */ |
| 799 | if (!(flags & O_EXCL)) { |
| 800 | /* ask server to check for all possible rights as results |
| 801 | * are cached */ |
| 802 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 803 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 804 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 805 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 806 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 807 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 808 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 809 | p->o_arg.server = server; |
| 810 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 811 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 812 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 813 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 814 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 815 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 816 | p->o_arg.u.attrs = &p->attrs; |
| 817 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 818 | |
| 819 | verf[0] = jiffies; |
| 820 | verf[1] = current->pid; |
| 821 | memcpy(p->o_arg.u.verifier.data, verf, |
| 822 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 824 | p->c_arg.fh = &p->o_res.fh; |
| 825 | p->c_arg.stateid = &p->o_res.stateid; |
| 826 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 827 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 828 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | return p; |
| 830 | err_free: |
| 831 | kfree(p); |
| 832 | err: |
| 833 | dput(parent); |
| 834 | return NULL; |
| 835 | } |
| 836 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 837 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 838 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 839 | struct nfs4_opendata *p = container_of(kref, |
| 840 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 841 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 842 | |
| 843 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 844 | if (p->state != NULL) |
| 845 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 846 | nfs4_put_state_owner(p->owner); |
| 847 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 848 | dput(p->dentry); |
| 849 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 850 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 851 | kfree(p); |
| 852 | } |
| 853 | |
| 854 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 855 | { |
| 856 | if (p != NULL) |
| 857 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 858 | } |
| 859 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 860 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 861 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 862 | int ret; |
| 863 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 864 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 865 | return ret; |
| 866 | } |
| 867 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 868 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 869 | { |
| 870 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 871 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 872 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 873 | goto out; |
| 874 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 875 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 876 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 877 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 878 | break; |
| 879 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 880 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 881 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 882 | break; |
| 883 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 884 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 885 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 886 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 887 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 888 | return ret; |
| 889 | } |
| 890 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 891 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 892 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 893 | if (delegation == NULL) |
| 894 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 895 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 896 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 897 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 898 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 899 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 900 | return 1; |
| 901 | } |
| 902 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 904 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 906 | case FMODE_WRITE: |
| 907 | state->n_wronly++; |
| 908 | break; |
| 909 | case FMODE_READ: |
| 910 | state->n_rdonly++; |
| 911 | break; |
| 912 | case FMODE_READ|FMODE_WRITE: |
| 913 | state->n_rdwr++; |
| 914 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 915 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 916 | } |
| 917 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 918 | 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] | 919 | { |
| 920 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 921 | nfs4_stateid_copy(&state->stateid, stateid); |
| 922 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 923 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 924 | case FMODE_READ: |
| 925 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 926 | break; |
| 927 | case FMODE_WRITE: |
| 928 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 929 | break; |
| 930 | case FMODE_READ|FMODE_WRITE: |
| 931 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 932 | } |
| 933 | } |
| 934 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 935 | 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] | 936 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 937 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 939 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 940 | } |
| 941 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 942 | 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] | 943 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 944 | /* |
| 945 | * Protect the call to nfs4_state_set_mode_locked and |
| 946 | * serialise the stateid update |
| 947 | */ |
| 948 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 949 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 950 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 951 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 952 | } |
| 953 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 954 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 955 | write_sequnlock(&state->seqlock); |
| 956 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 957 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 958 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | } |
| 960 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | 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] | 962 | { |
| 963 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 964 | struct nfs_delegation *deleg_cur; |
| 965 | int ret = 0; |
| 966 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 967 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 968 | |
| 969 | rcu_read_lock(); |
| 970 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 971 | if (deleg_cur == NULL) |
| 972 | goto no_delegation; |
| 973 | |
| 974 | spin_lock(&deleg_cur->lock); |
| 975 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 976 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 977 | goto no_delegation_unlock; |
| 978 | |
| 979 | if (delegation == NULL) |
| 980 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 981 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 982 | goto no_delegation_unlock; |
| 983 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 984 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 985 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 986 | ret = 1; |
| 987 | no_delegation_unlock: |
| 988 | spin_unlock(&deleg_cur->lock); |
| 989 | no_delegation: |
| 990 | rcu_read_unlock(); |
| 991 | |
| 992 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 993 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 994 | ret = 1; |
| 995 | } |
| 996 | |
| 997 | return ret; |
| 998 | } |
| 999 | |
| 1000 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1002 | { |
| 1003 | struct nfs_delegation *delegation; |
| 1004 | |
| 1005 | rcu_read_lock(); |
| 1006 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1007 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1008 | rcu_read_unlock(); |
| 1009 | return; |
| 1010 | } |
| 1011 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1012 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1015 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | { |
| 1017 | struct nfs4_state *state = opendata->state; |
| 1018 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1019 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1020 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1021 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1022 | nfs4_stateid stateid; |
| 1023 | int ret = -EAGAIN; |
| 1024 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1026 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1027 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1028 | if (can_open_cached(state, fmode, open_mode)) { |
| 1029 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1030 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1031 | goto out_return_state; |
| 1032 | } |
| 1033 | spin_unlock(&state->owner->so_lock); |
| 1034 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1035 | rcu_read_lock(); |
| 1036 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1037 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1038 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1039 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1040 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1041 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1042 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1043 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1044 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1045 | if (ret != 0) |
| 1046 | goto out; |
| 1047 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1048 | |
| 1049 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1050 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1051 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1052 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1053 | out: |
| 1054 | return ERR_PTR(ret); |
| 1055 | out_return_state: |
| 1056 | atomic_inc(&state->count); |
| 1057 | return state; |
| 1058 | } |
| 1059 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1060 | static void |
| 1061 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1062 | { |
| 1063 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1064 | struct nfs_delegation *delegation; |
| 1065 | int delegation_flags = 0; |
| 1066 | |
| 1067 | rcu_read_lock(); |
| 1068 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1069 | if (delegation) |
| 1070 | delegation_flags = delegation->flags; |
| 1071 | rcu_read_unlock(); |
| 1072 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1073 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1074 | "returning a delegation for " |
| 1075 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1076 | clp->cl_hostname); |
| 1077 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1078 | nfs_inode_set_delegation(state->inode, |
| 1079 | data->owner->so_cred, |
| 1080 | &data->o_res); |
| 1081 | else |
| 1082 | nfs_inode_reclaim_delegation(state->inode, |
| 1083 | data->owner->so_cred, |
| 1084 | &data->o_res); |
| 1085 | } |
| 1086 | |
| 1087 | /* |
| 1088 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1089 | * and update the nfs4_state. |
| 1090 | */ |
| 1091 | static struct nfs4_state * |
| 1092 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1093 | { |
| 1094 | struct inode *inode = data->state->inode; |
| 1095 | struct nfs4_state *state = data->state; |
| 1096 | int ret; |
| 1097 | |
| 1098 | if (!data->rpc_done) { |
| 1099 | ret = data->rpc_status; |
| 1100 | goto err; |
| 1101 | } |
| 1102 | |
| 1103 | ret = -ESTALE; |
| 1104 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1105 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1106 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1107 | goto err; |
| 1108 | |
| 1109 | ret = -ENOMEM; |
| 1110 | state = nfs4_get_open_state(inode, data->owner); |
| 1111 | if (state == NULL) |
| 1112 | goto err; |
| 1113 | |
| 1114 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1115 | if (ret) |
| 1116 | goto err; |
| 1117 | |
| 1118 | if (data->o_res.delegation_type != 0) |
| 1119 | nfs4_opendata_check_deleg(data, state); |
| 1120 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1121 | data->o_arg.fmode); |
| 1122 | |
| 1123 | return state; |
| 1124 | err: |
| 1125 | return ERR_PTR(ret); |
| 1126 | |
| 1127 | } |
| 1128 | |
| 1129 | static struct nfs4_state * |
| 1130 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1131 | { |
| 1132 | struct inode *inode; |
| 1133 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1134 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1135 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1136 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1137 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1138 | goto out; |
| 1139 | } |
| 1140 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1141 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1142 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1143 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1144 | 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] | 1145 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1146 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1147 | goto err; |
| 1148 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1149 | state = nfs4_get_open_state(inode, data->owner); |
| 1150 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1151 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1152 | if (data->o_res.delegation_type != 0) |
| 1153 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1154 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1155 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1156 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1157 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1158 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1159 | err_put_inode: |
| 1160 | iput(inode); |
| 1161 | err: |
| 1162 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1163 | } |
| 1164 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1165 | static struct nfs4_state * |
| 1166 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1167 | { |
| 1168 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1169 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1170 | return _nfs4_opendata_to_nfs4_state(data); |
| 1171 | } |
| 1172 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1173 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1174 | { |
| 1175 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1176 | struct nfs_open_context *ctx; |
| 1177 | |
| 1178 | spin_lock(&state->inode->i_lock); |
| 1179 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1180 | if (ctx->state != state) |
| 1181 | continue; |
| 1182 | get_nfs_open_context(ctx); |
| 1183 | spin_unlock(&state->inode->i_lock); |
| 1184 | return ctx; |
| 1185 | } |
| 1186 | spin_unlock(&state->inode->i_lock); |
| 1187 | return ERR_PTR(-ENOENT); |
| 1188 | } |
| 1189 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1190 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1191 | { |
| 1192 | struct nfs4_opendata *opendata; |
| 1193 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1194 | 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] | 1195 | if (opendata == NULL) |
| 1196 | return ERR_PTR(-ENOMEM); |
| 1197 | opendata->state = state; |
| 1198 | atomic_inc(&state->count); |
| 1199 | return opendata; |
| 1200 | } |
| 1201 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1202 | 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] | 1203 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1204 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1205 | int ret; |
| 1206 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1207 | opendata->o_arg.open_flags = 0; |
| 1208 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1209 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1210 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1211 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1212 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1213 | if (ret != 0) |
| 1214 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1215 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1216 | if (IS_ERR(newstate)) |
| 1217 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1218 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1219 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1224 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1225 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1226 | int ret; |
| 1227 | |
| 1228 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1229 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1230 | smp_rmb(); |
| 1231 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1232 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1233 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1234 | if (ret != 0) |
| 1235 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1236 | if (newstate != state) |
| 1237 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1238 | } |
| 1239 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1240 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1241 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1242 | if (ret != 0) |
| 1243 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1244 | if (newstate != state) |
| 1245 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1246 | } |
| 1247 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1248 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1249 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1250 | if (ret != 0) |
| 1251 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1252 | if (newstate != state) |
| 1253 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1254 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1255 | /* |
| 1256 | * We may have performed cached opens for all three recoveries. |
| 1257 | * Check if we need to update the current stateid. |
| 1258 | */ |
| 1259 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1260 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1261 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1262 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1263 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1264 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1265 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1266 | return 0; |
| 1267 | } |
| 1268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | /* |
| 1270 | * OPEN_RECLAIM: |
| 1271 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1273 | 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] | 1274 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1275 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1276 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1277 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | int status; |
| 1279 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1280 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1281 | if (IS_ERR(opendata)) |
| 1282 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1283 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1284 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1285 | rcu_read_lock(); |
| 1286 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1287 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1288 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1289 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1290 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1291 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1292 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | return status; |
| 1294 | } |
| 1295 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1296 | 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] | 1297 | { |
| 1298 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1299 | struct nfs4_exception exception = { }; |
| 1300 | int err; |
| 1301 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1302 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1303 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1304 | break; |
| 1305 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } while (exception.retry); |
| 1307 | return err; |
| 1308 | } |
| 1309 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1310 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1311 | { |
| 1312 | struct nfs_open_context *ctx; |
| 1313 | int ret; |
| 1314 | |
| 1315 | ctx = nfs4_state_find_open_context(state); |
| 1316 | if (IS_ERR(ctx)) |
| 1317 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1318 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1319 | put_nfs_open_context(ctx); |
| 1320 | return ret; |
| 1321 | } |
| 1322 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1323 | 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] | 1324 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1325 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1326 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1328 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1329 | if (IS_ERR(opendata)) |
| 1330 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1331 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1332 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1333 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1334 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1335 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1338 | 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] | 1339 | { |
| 1340 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1341 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | int err; |
| 1343 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1344 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | switch (err) { |
| 1346 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1347 | case -ENOENT: |
| 1348 | case -ESTALE: |
| 1349 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1350 | case -NFS4ERR_BADSESSION: |
| 1351 | case -NFS4ERR_BADSLOT: |
| 1352 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1353 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1354 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1355 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1356 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | case -NFS4ERR_STALE_CLIENTID: |
| 1358 | case -NFS4ERR_STALE_STATEID: |
| 1359 | case -NFS4ERR_EXPIRED: |
| 1360 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1361 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1362 | goto out; |
| 1363 | case -ERESTARTSYS: |
| 1364 | /* |
| 1365 | * The show must go on: exit, but mark the |
| 1366 | * stateid as needing recovery. |
| 1367 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1368 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1369 | case -NFS4ERR_ADMIN_REVOKED: |
| 1370 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1371 | nfs_inode_find_state_and_recover(state->inode, |
| 1372 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1373 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1374 | case -ENOMEM: |
| 1375 | err = 0; |
| 1376 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | err = nfs4_handle_exception(server, err, &exception); |
| 1379 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1380 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | return err; |
| 1382 | } |
| 1383 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1384 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1385 | { |
| 1386 | struct nfs4_opendata *data = calldata; |
| 1387 | |
| 1388 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1389 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1390 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1391 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1392 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1393 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1394 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | static void nfs4_open_confirm_release(void *calldata) |
| 1398 | { |
| 1399 | struct nfs4_opendata *data = calldata; |
| 1400 | struct nfs4_state *state = NULL; |
| 1401 | |
| 1402 | /* If this request hasn't been cancelled, do nothing */ |
| 1403 | if (data->cancelled == 0) |
| 1404 | goto out_free; |
| 1405 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1406 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1407 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1408 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1409 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1410 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1411 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1412 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1416 | .rpc_call_done = nfs4_open_confirm_done, |
| 1417 | .rpc_release = nfs4_open_confirm_release, |
| 1418 | }; |
| 1419 | |
| 1420 | /* |
| 1421 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1422 | */ |
| 1423 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1424 | { |
| 1425 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1426 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1427 | struct rpc_message msg = { |
| 1428 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1429 | .rpc_argp = &data->c_arg, |
| 1430 | .rpc_resp = &data->c_res, |
| 1431 | .rpc_cred = data->owner->so_cred, |
| 1432 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1433 | struct rpc_task_setup task_setup_data = { |
| 1434 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1435 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1436 | .callback_ops = &nfs4_open_confirm_ops, |
| 1437 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1438 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1439 | .flags = RPC_TASK_ASYNC, |
| 1440 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | int status; |
| 1442 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1443 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1444 | data->rpc_done = 0; |
| 1445 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1446 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1447 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1448 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1449 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1450 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1451 | if (status != 0) { |
| 1452 | data->cancelled = 1; |
| 1453 | smp_wmb(); |
| 1454 | } else |
| 1455 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1456 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | return status; |
| 1458 | } |
| 1459 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1460 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | struct nfs4_opendata *data = calldata; |
| 1463 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1464 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1466 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1467 | /* |
| 1468 | * Check if we still need to send an OPEN call, or if we can use |
| 1469 | * a delegation instead. |
| 1470 | */ |
| 1471 | if (data->state != NULL) { |
| 1472 | struct nfs_delegation *delegation; |
| 1473 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1474 | 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] | 1475 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1476 | rcu_read_lock(); |
| 1477 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1478 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1479 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1480 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1481 | rcu_read_unlock(); |
| 1482 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1483 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1484 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1485 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1486 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1487 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1488 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1489 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1490 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1491 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1492 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1493 | &data->o_res.seq_res, |
| 1494 | task) != 0) |
| 1495 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1496 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1497 | unlock_no_action: |
| 1498 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1499 | out_no_action: |
| 1500 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1501 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1502 | } |
| 1503 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1504 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1505 | { |
| 1506 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1508 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1509 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1510 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1511 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1512 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1513 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1514 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1515 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1516 | case S_IFREG: |
| 1517 | break; |
| 1518 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1519 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1520 | break; |
| 1521 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1522 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1523 | break; |
| 1524 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1525 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1526 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1527 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1528 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1529 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1530 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1531 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1532 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1534 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1535 | static void nfs4_open_release(void *calldata) |
| 1536 | { |
| 1537 | struct nfs4_opendata *data = calldata; |
| 1538 | struct nfs4_state *state = NULL; |
| 1539 | |
| 1540 | /* If this request hasn't been cancelled, do nothing */ |
| 1541 | if (data->cancelled == 0) |
| 1542 | goto out_free; |
| 1543 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1544 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1545 | goto out_free; |
| 1546 | /* In case we need an open_confirm, no cleanup! */ |
| 1547 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1548 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1549 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1550 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1551 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1552 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1553 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1557 | .rpc_call_prepare = nfs4_open_prepare, |
| 1558 | .rpc_call_done = nfs4_open_done, |
| 1559 | .rpc_release = nfs4_open_release, |
| 1560 | }; |
| 1561 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1562 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1563 | { |
| 1564 | struct inode *dir = data->dir->d_inode; |
| 1565 | struct nfs_server *server = NFS_SERVER(dir); |
| 1566 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1567 | struct nfs_openres *o_res = &data->o_res; |
| 1568 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1569 | struct rpc_message msg = { |
| 1570 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1571 | .rpc_argp = o_arg, |
| 1572 | .rpc_resp = o_res, |
| 1573 | .rpc_cred = data->owner->so_cred, |
| 1574 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1575 | struct rpc_task_setup task_setup_data = { |
| 1576 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1577 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1578 | .callback_ops = &nfs4_open_ops, |
| 1579 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1580 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1581 | .flags = RPC_TASK_ASYNC, |
| 1582 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1583 | int status; |
| 1584 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1585 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1586 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1587 | data->rpc_done = 0; |
| 1588 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1589 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1590 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1591 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1592 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1593 | if (IS_ERR(task)) |
| 1594 | return PTR_ERR(task); |
| 1595 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1596 | if (status != 0) { |
| 1597 | data->cancelled = 1; |
| 1598 | smp_wmb(); |
| 1599 | } else |
| 1600 | status = data->rpc_status; |
| 1601 | rpc_put_task(task); |
| 1602 | |
| 1603 | return status; |
| 1604 | } |
| 1605 | |
| 1606 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1607 | { |
| 1608 | struct inode *dir = data->dir->d_inode; |
| 1609 | struct nfs_openres *o_res = &data->o_res; |
| 1610 | int status; |
| 1611 | |
| 1612 | status = nfs4_run_open_task(data, 1); |
| 1613 | if (status != 0 || !data->rpc_done) |
| 1614 | return status; |
| 1615 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1616 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1617 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1618 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1619 | status = _nfs4_proc_open_confirm(data); |
| 1620 | if (status != 0) |
| 1621 | return status; |
| 1622 | } |
| 1623 | |
| 1624 | return status; |
| 1625 | } |
| 1626 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1627 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1628 | struct nfs4_opendata *opendata, |
| 1629 | struct nfs4_state *state, fmode_t fmode) |
| 1630 | { |
| 1631 | struct nfs_access_entry cache; |
| 1632 | u32 mask; |
| 1633 | |
| 1634 | /* access call failed or for some reason the server doesn't |
| 1635 | * support any access modes -- defer access call until later */ |
| 1636 | if (opendata->o_res.access_supported == 0) |
| 1637 | return 0; |
| 1638 | |
| 1639 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1640 | /* don't check MAY_WRITE - a newly created file may not have |
| 1641 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1642 | if (fmode & FMODE_READ) |
| 1643 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1644 | if (fmode & FMODE_EXEC) |
| 1645 | mask |= MAY_EXEC; |
| 1646 | |
| 1647 | cache.cred = cred; |
| 1648 | cache.jiffies = jiffies; |
| 1649 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1650 | nfs_access_add_cache(state->inode, &cache); |
| 1651 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1652 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1653 | return 0; |
| 1654 | |
| 1655 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1656 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1657 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1658 | } |
| 1659 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1660 | /* |
| 1661 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1662 | */ |
| 1663 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1664 | { |
| 1665 | struct inode *dir = data->dir->d_inode; |
| 1666 | struct nfs_server *server = NFS_SERVER(dir); |
| 1667 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1668 | struct nfs_openres *o_res = &data->o_res; |
| 1669 | int status; |
| 1670 | |
| 1671 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1672 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1673 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1674 | if (status != 0) { |
| 1675 | if (status == -NFS4ERR_BADNAME && |
| 1676 | !(o_arg->open_flags & O_CREAT)) |
| 1677 | return -ENOENT; |
| 1678 | return status; |
| 1679 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1680 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1681 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1682 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1683 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1684 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1685 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1686 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1688 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1690 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | } |
| 1692 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1693 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1694 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1697 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1698 | { |
| 1699 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1700 | } |
| 1701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | /* |
| 1703 | * OPEN_EXPIRED: |
| 1704 | * reclaim state on the server after a network partition. |
| 1705 | * Assumes caller holds the appropriate lock |
| 1706 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1707 | 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] | 1708 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1709 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1710 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1712 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1713 | if (IS_ERR(opendata)) |
| 1714 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1715 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1716 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1717 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1718 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1719 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1722 | 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] | 1723 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1724 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1725 | struct nfs4_exception exception = { }; |
| 1726 | int err; |
| 1727 | |
| 1728 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1729 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1730 | switch (err) { |
| 1731 | default: |
| 1732 | goto out; |
| 1733 | case -NFS4ERR_GRACE: |
| 1734 | case -NFS4ERR_DELAY: |
| 1735 | nfs4_handle_exception(server, err, &exception); |
| 1736 | err = 0; |
| 1737 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1738 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1739 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1740 | return err; |
| 1741 | } |
| 1742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1744 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1746 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1748 | ctx = nfs4_state_find_open_context(state); |
| 1749 | if (IS_ERR(ctx)) |
| 1750 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1751 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1752 | put_nfs_open_context(ctx); |
| 1753 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1756 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1757 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1758 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1759 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1760 | nfs4_stateid *stateid = &state->stateid; |
| 1761 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1762 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1763 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1764 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1765 | return; |
| 1766 | |
| 1767 | status = nfs41_test_stateid(server, stateid); |
| 1768 | if (status != NFS_OK) { |
| 1769 | /* Free the stateid unless the server explicitly |
| 1770 | * informs us the stateid is unrecognized. */ |
| 1771 | if (status != -NFS4ERR_BAD_STATEID) |
| 1772 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1773 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1774 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1775 | write_seqlock(&state->seqlock); |
| 1776 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1777 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1778 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | /** |
| 1783 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1784 | * |
| 1785 | * @state: NFSv4 state for an inode |
| 1786 | * |
| 1787 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1788 | * Otherwise a negative NFS4ERR value is returned. |
| 1789 | */ |
| 1790 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1791 | { |
| 1792 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1793 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1794 | int status; |
| 1795 | |
| 1796 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1797 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1798 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1799 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1800 | return -NFS4ERR_BAD_STATEID; |
| 1801 | |
| 1802 | status = nfs41_test_stateid(server, stateid); |
| 1803 | if (status != NFS_OK) { |
| 1804 | /* Free the stateid unless the server explicitly |
| 1805 | * informs us the stateid is unrecognized. */ |
| 1806 | if (status != -NFS4ERR_BAD_STATEID) |
| 1807 | nfs41_free_stateid(server, stateid); |
| 1808 | |
| 1809 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1810 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1811 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1812 | } |
| 1813 | return status; |
| 1814 | } |
| 1815 | |
| 1816 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1817 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1818 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1819 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1820 | nfs41_clear_delegation_stateid(state); |
| 1821 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1822 | if (status != NFS_OK) |
| 1823 | status = nfs4_open_expired(sp, state); |
| 1824 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1825 | } |
| 1826 | #endif |
| 1827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1829 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1830 | * fields corresponding to attributes that were used to store the verifier. |
| 1831 | * Make sure we clobber those fields in the later setattr call |
| 1832 | */ |
| 1833 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1834 | { |
| 1835 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1836 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1837 | sattr->ia_valid |= ATTR_ATIME; |
| 1838 | |
| 1839 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1840 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1841 | sattr->ia_valid |= ATTR_MTIME; |
| 1842 | } |
| 1843 | |
| 1844 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1845 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1847 | static int _nfs4_do_open(struct inode *dir, |
| 1848 | struct dentry *dentry, |
| 1849 | fmode_t fmode, |
| 1850 | int flags, |
| 1851 | struct iattr *sattr, |
| 1852 | struct rpc_cred *cred, |
| 1853 | struct nfs4_state **res, |
| 1854 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | { |
| 1856 | struct nfs4_state_owner *sp; |
| 1857 | struct nfs4_state *state = NULL; |
| 1858 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1859 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1860 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
| 1862 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1864 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1865 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1867 | goto out_err; |
| 1868 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1869 | status = nfs4_recover_expired_lease(server); |
| 1870 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1871 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1872 | if (dentry->d_inode != NULL) |
| 1873 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1874 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1875 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1876 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1877 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1879 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1880 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1881 | if (!opendata->f_attr.mdsthreshold) |
| 1882 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1883 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1884 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1885 | if (dentry->d_inode != NULL) |
| 1886 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1887 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1888 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1890 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1892 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1893 | status = PTR_ERR(state); |
| 1894 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1895 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1896 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1897 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1898 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1899 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 1900 | if (status != 0) |
| 1901 | goto err_opendata_put; |
| 1902 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1903 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1904 | nfs4_exclusive_attrset(opendata, sattr); |
| 1905 | |
| 1906 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1907 | status = nfs4_do_setattr(state->inode, cred, |
| 1908 | opendata->o_res.f_attr, sattr, |
| 1909 | state); |
| 1910 | if (status == 0) |
| 1911 | nfs_setattr_update_inode(state->inode, sattr); |
| 1912 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1913 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1914 | |
| 1915 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1916 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1917 | else |
| 1918 | kfree(opendata->f_attr.mdsthreshold); |
| 1919 | opendata->f_attr.mdsthreshold = NULL; |
| 1920 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1921 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | *res = state; |
| 1924 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1925 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1926 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1927 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1928 | err_put_state_owner: |
| 1929 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | *res = NULL; |
| 1932 | return status; |
| 1933 | } |
| 1934 | |
| 1935 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1936 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1937 | struct dentry *dentry, |
| 1938 | fmode_t fmode, |
| 1939 | int flags, |
| 1940 | struct iattr *sattr, |
| 1941 | struct rpc_cred *cred, |
| 1942 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | { |
| 1944 | struct nfs4_exception exception = { }; |
| 1945 | struct nfs4_state *res; |
| 1946 | int status; |
| 1947 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1948 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1950 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1951 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | if (status == 0) |
| 1953 | break; |
| 1954 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1955 | * book-keeping w.r.t. state-changing operations |
| 1956 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1957 | * It is actually a sign of a bug on the client or on the server. |
| 1958 | * |
| 1959 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1960 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | * have unhashed the old state_owner for us, and that we can |
| 1962 | * therefore safely retry using a new one. We should still warn |
| 1963 | * the user though... |
| 1964 | */ |
| 1965 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1966 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1967 | " returned a bad sequence-id error!\n", |
| 1968 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | exception.retry = 1; |
| 1970 | continue; |
| 1971 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1972 | /* |
| 1973 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1974 | * state before it received the OPEN_CONFIRM. |
| 1975 | * Recover by retrying the request as per the discussion |
| 1976 | * on Page 181 of RFC3530. |
| 1977 | */ |
| 1978 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1979 | exception.retry = 1; |
| 1980 | continue; |
| 1981 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1982 | if (status == -EAGAIN) { |
| 1983 | /* We must have found a delegation */ |
| 1984 | exception.retry = 1; |
| 1985 | continue; |
| 1986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1988 | status, &exception)); |
| 1989 | } while (exception.retry); |
| 1990 | return res; |
| 1991 | } |
| 1992 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1993 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1994 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1995 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1997 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1999 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | .iap = sattr, |
| 2001 | .server = server, |
| 2002 | .bitmask = server->attr_bitmask, |
| 2003 | }; |
| 2004 | struct nfs_setattrres res = { |
| 2005 | .fattr = fattr, |
| 2006 | .server = server, |
| 2007 | }; |
| 2008 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2009 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2010 | .rpc_argp = &arg, |
| 2011 | .rpc_resp = &res, |
| 2012 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2014 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2015 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2017 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2019 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2020 | struct nfs_lockowner lockowner = { |
| 2021 | .l_owner = current->files, |
| 2022 | .l_pid = current->tgid, |
| 2023 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2024 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2025 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2026 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2027 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2028 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2029 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2030 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2032 | 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] | 2033 | if (status == 0 && state != NULL) |
| 2034 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2035 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2038 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2039 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2040 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2042 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2043 | struct nfs4_exception exception = { |
| 2044 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2045 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2046 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | int err; |
| 2048 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2049 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2050 | switch (err) { |
| 2051 | case -NFS4ERR_OPENMODE: |
| 2052 | if (state && !(state->state & FMODE_WRITE)) { |
| 2053 | err = -EBADF; |
| 2054 | if (sattr->ia_valid & ATTR_OPEN) |
| 2055 | err = -EACCES; |
| 2056 | goto out; |
| 2057 | } |
| 2058 | } |
| 2059 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2061 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | return err; |
| 2063 | } |
| 2064 | |
| 2065 | struct nfs4_closedata { |
| 2066 | struct inode *inode; |
| 2067 | struct nfs4_state *state; |
| 2068 | struct nfs_closeargs arg; |
| 2069 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2070 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2071 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2072 | bool roc; |
| 2073 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | }; |
| 2075 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2076 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2077 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2078 | struct nfs4_closedata *calldata = data; |
| 2079 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2080 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2081 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2082 | if (calldata->roc) |
| 2083 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2084 | nfs4_put_open_state(calldata->state); |
| 2085 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2086 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2087 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2088 | kfree(calldata); |
| 2089 | } |
| 2090 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2091 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2092 | fmode_t fmode) |
| 2093 | { |
| 2094 | spin_lock(&state->owner->so_lock); |
| 2095 | if (!(fmode & FMODE_READ)) |
| 2096 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2097 | if (!(fmode & FMODE_WRITE)) |
| 2098 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2099 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2100 | spin_unlock(&state->owner->so_lock); |
| 2101 | } |
| 2102 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2103 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2105 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2108 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2109 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2110 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2111 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | /* hmm. we are done with the inode, and in the process of freeing |
| 2113 | * the state_owner. we keep this around to process errors |
| 2114 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | switch (task->tk_status) { |
| 2116 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2117 | if (calldata->roc) |
| 2118 | pnfs_roc_set_barrier(state->inode, |
| 2119 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2120 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2121 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2122 | nfs4_close_clear_stateid_flags(state, |
| 2123 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | break; |
| 2125 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2126 | case -NFS4ERR_OLD_STATEID: |
| 2127 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2129 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2130 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2132 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2133 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2135 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2136 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2137 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2140 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2142 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2143 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2144 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2145 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2146 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2147 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2148 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2149 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2150 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2151 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2152 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2153 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2154 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2155 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2156 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2157 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2158 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2159 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2160 | } |
| 2161 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2162 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2163 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2164 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2165 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2166 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2167 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2168 | |
| 2169 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2170 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2171 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2172 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2173 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2174 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2175 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2176 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2177 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2178 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2179 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2180 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2181 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2182 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2183 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2184 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2185 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2186 | &calldata->arg.seq_args, |
| 2187 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2188 | task) != 0) |
| 2189 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2190 | out: |
| 2191 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2194 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2195 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2196 | .rpc_call_done = nfs4_close_done, |
| 2197 | .rpc_release = nfs4_free_closedata, |
| 2198 | }; |
| 2199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | /* |
| 2201 | * It is possible for data to be read/written from a mem-mapped file |
| 2202 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2203 | * This means that we can't safely call nfsv4 close on a file until |
| 2204 | * the inode is cleared. This in turn means that we are not good |
| 2205 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2206 | * share state even when we are done with one of the three share |
| 2207 | * stateid's in the inode. |
| 2208 | * |
| 2209 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2210 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2211 | 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] | 2212 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2213 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2215 | struct nfs4_state_owner *sp = state->owner; |
| 2216 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2217 | struct rpc_message msg = { |
| 2218 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2219 | .rpc_cred = state->owner->so_cred, |
| 2220 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2221 | struct rpc_task_setup task_setup_data = { |
| 2222 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2223 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2224 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2225 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2226 | .flags = RPC_TASK_ASYNC, |
| 2227 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2228 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2230 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2232 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2233 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2234 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2236 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2237 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2239 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2240 | if (calldata->arg.seqid == NULL) |
| 2241 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2242 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2243 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2244 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2245 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2246 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2247 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2248 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2249 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2250 | msg.rpc_argp = &calldata->arg; |
| 2251 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2252 | task_setup_data.callback_data = calldata; |
| 2253 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2254 | if (IS_ERR(task)) |
| 2255 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2256 | status = 0; |
| 2257 | if (wait) |
| 2258 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2259 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2260 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2261 | out_free_calldata: |
| 2262 | kfree(calldata); |
| 2263 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2264 | nfs4_put_open_state(state); |
| 2265 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2266 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2269 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2270 | 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] | 2271 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | struct nfs4_state *state; |
| 2273 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2274 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2275 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2276 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2277 | if (IS_ERR(state)) |
| 2278 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2279 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2280 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2283 | 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] | 2284 | { |
| 2285 | if (ctx->state == NULL) |
| 2286 | return; |
| 2287 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2288 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2289 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2290 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | |
| 2293 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2294 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2295 | struct nfs4_server_caps_arg args = { |
| 2296 | .fhandle = fhandle, |
| 2297 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | struct nfs4_server_caps_res res = {}; |
| 2299 | struct rpc_message msg = { |
| 2300 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2301 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | .rpc_resp = &res, |
| 2303 | }; |
| 2304 | int status; |
| 2305 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2306 | 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] | 2307 | if (status == 0) { |
| 2308 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2309 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2310 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2311 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2312 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2313 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2315 | server->caps |= NFS_CAP_ACLS; |
| 2316 | if (res.has_links != 0) |
| 2317 | server->caps |= NFS_CAP_HARDLINKS; |
| 2318 | if (res.has_symlinks != 0) |
| 2319 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2320 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2321 | server->caps |= NFS_CAP_FILEID; |
| 2322 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2323 | server->caps |= NFS_CAP_MODE; |
| 2324 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2325 | server->caps |= NFS_CAP_NLINK; |
| 2326 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2327 | server->caps |= NFS_CAP_OWNER; |
| 2328 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2329 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2330 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2331 | server->caps |= NFS_CAP_ATIME; |
| 2332 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2333 | server->caps |= NFS_CAP_CTIME; |
| 2334 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2335 | server->caps |= NFS_CAP_MTIME; |
| 2336 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2337 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2338 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2339 | 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] | 2340 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2341 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | return status; |
| 2345 | } |
| 2346 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2347 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | { |
| 2349 | struct nfs4_exception exception = { }; |
| 2350 | int err; |
| 2351 | do { |
| 2352 | err = nfs4_handle_exception(server, |
| 2353 | _nfs4_server_capabilities(server, fhandle), |
| 2354 | &exception); |
| 2355 | } while (exception.retry); |
| 2356 | return err; |
| 2357 | } |
| 2358 | |
| 2359 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2360 | struct nfs_fsinfo *info) |
| 2361 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | struct nfs4_lookup_root_arg args = { |
| 2363 | .bitmask = nfs4_fattr_bitmap, |
| 2364 | }; |
| 2365 | struct nfs4_lookup_res res = { |
| 2366 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2367 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | .fh = fhandle, |
| 2369 | }; |
| 2370 | struct rpc_message msg = { |
| 2371 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2372 | .rpc_argp = &args, |
| 2373 | .rpc_resp = &res, |
| 2374 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2375 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2376 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2377 | 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] | 2378 | } |
| 2379 | |
| 2380 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2381 | struct nfs_fsinfo *info) |
| 2382 | { |
| 2383 | struct nfs4_exception exception = { }; |
| 2384 | int err; |
| 2385 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2386 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2387 | switch (err) { |
| 2388 | case 0: |
| 2389 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2390 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2391 | default: |
| 2392 | err = nfs4_handle_exception(server, err, &exception); |
| 2393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2395 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | return err; |
| 2397 | } |
| 2398 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2399 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2400 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2401 | { |
| 2402 | struct rpc_auth *auth; |
| 2403 | int ret; |
| 2404 | |
| 2405 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2406 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2407 | ret = -EIO; |
| 2408 | goto out; |
| 2409 | } |
| 2410 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2411 | out: |
| 2412 | return ret; |
| 2413 | } |
| 2414 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2415 | 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] | 2416 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2418 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2419 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2421 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2422 | if (len < 0) |
| 2423 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2424 | |
| 2425 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2426 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2427 | * thus has already been tried. */ |
| 2428 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2429 | continue; |
| 2430 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2431 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2432 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2433 | continue; |
| 2434 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2435 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2436 | /* |
| 2437 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2438 | * to access the mount. It could also mean that we tried to mount |
| 2439 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2440 | * existing mount programs don't handle -EACCES very well so it should |
| 2441 | * be mapped to -EPERM instead. |
| 2442 | */ |
| 2443 | if (status == -EACCES) |
| 2444 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2445 | return status; |
| 2446 | } |
| 2447 | |
| 2448 | /* |
| 2449 | * get the file handle for the "/" directory on the server |
| 2450 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2451 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2452 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2453 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2454 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2455 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2456 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2457 | /* |
| 2458 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2459 | * by nfs4_map_errors() as this function exits. |
| 2460 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2461 | 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] | 2462 | if (status == 0) |
| 2463 | status = nfs4_server_capabilities(server, fhandle); |
| 2464 | if (status == 0) |
| 2465 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2466 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2469 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2470 | struct nfs_fsinfo *info) |
| 2471 | { |
| 2472 | int error; |
| 2473 | struct nfs_fattr *fattr = info->fattr; |
| 2474 | |
| 2475 | error = nfs4_server_capabilities(server, mntfh); |
| 2476 | if (error < 0) { |
| 2477 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2478 | return error; |
| 2479 | } |
| 2480 | |
| 2481 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2482 | if (error < 0) { |
| 2483 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2484 | return error; |
| 2485 | } |
| 2486 | |
| 2487 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2488 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2489 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2490 | |
| 2491 | return error; |
| 2492 | } |
| 2493 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2494 | /* |
| 2495 | * Get locations and (maybe) other attributes of a referral. |
| 2496 | * Note that we'll actually follow the referral later when |
| 2497 | * we detect fsid mismatch in inode revalidation |
| 2498 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2499 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2500 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2501 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2502 | { |
| 2503 | int status = -ENOMEM; |
| 2504 | struct page *page = NULL; |
| 2505 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2506 | |
| 2507 | page = alloc_page(GFP_KERNEL); |
| 2508 | if (page == NULL) |
| 2509 | goto out; |
| 2510 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2511 | if (locations == NULL) |
| 2512 | goto out; |
| 2513 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2514 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2515 | if (status != 0) |
| 2516 | goto out; |
| 2517 | /* Make sure server returned a different fsid for the referral */ |
| 2518 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2519 | dprintk("%s: server did not return a different fsid for" |
| 2520 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2521 | status = -EIO; |
| 2522 | goto out; |
| 2523 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2524 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2525 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2526 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2527 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2528 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2529 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2530 | out: |
| 2531 | if (page) |
| 2532 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2533 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2534 | return status; |
| 2535 | } |
| 2536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2538 | { |
| 2539 | struct nfs4_getattr_arg args = { |
| 2540 | .fh = fhandle, |
| 2541 | .bitmask = server->attr_bitmask, |
| 2542 | }; |
| 2543 | struct nfs4_getattr_res res = { |
| 2544 | .fattr = fattr, |
| 2545 | .server = server, |
| 2546 | }; |
| 2547 | struct rpc_message msg = { |
| 2548 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2549 | .rpc_argp = &args, |
| 2550 | .rpc_resp = &res, |
| 2551 | }; |
| 2552 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2553 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2554 | 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] | 2555 | } |
| 2556 | |
| 2557 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2558 | { |
| 2559 | struct nfs4_exception exception = { }; |
| 2560 | int err; |
| 2561 | do { |
| 2562 | err = nfs4_handle_exception(server, |
| 2563 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2564 | &exception); |
| 2565 | } while (exception.retry); |
| 2566 | return err; |
| 2567 | } |
| 2568 | |
| 2569 | /* |
| 2570 | * The file is not closed if it is opened due to the a request to change |
| 2571 | * the size of the file. The open call will not be needed once the |
| 2572 | * VFS layer lookup-intents are implemented. |
| 2573 | * |
| 2574 | * Close is called when the inode is destroyed. |
| 2575 | * If we haven't opened the file for O_WRONLY, we |
| 2576 | * need to in the size_change case to obtain a stateid. |
| 2577 | * |
| 2578 | * Got race? |
| 2579 | * Because OPEN is always done by name in nfsv4, it is |
| 2580 | * possible that we opened a different file by the same |
| 2581 | * name. We can recognize this race condition, but we |
| 2582 | * can't do anything about it besides returning an error. |
| 2583 | * |
| 2584 | * This will be fixed with VFS changes (lookup-intent). |
| 2585 | */ |
| 2586 | static int |
| 2587 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2588 | struct iattr *sattr) |
| 2589 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2590 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2591 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2592 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | int status; |
| 2594 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2595 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2596 | pnfs_return_layout(inode); |
| 2597 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2598 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2600 | /* Deal with open(O_TRUNC) */ |
| 2601 | if (sattr->ia_valid & ATTR_OPEN) |
| 2602 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2603 | |
| 2604 | /* Optimization: if the end result is no change, don't RPC */ |
| 2605 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2606 | return 0; |
| 2607 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2608 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2609 | if (sattr->ia_valid & ATTR_FILE) { |
| 2610 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2611 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2612 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2613 | if (ctx) { |
| 2614 | cred = ctx->cred; |
| 2615 | state = ctx->state; |
| 2616 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2620 | if (status == 0) |
| 2621 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | return status; |
| 2623 | } |
| 2624 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2625 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2626 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2627 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2628 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2629 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2630 | int status; |
| 2631 | struct nfs4_lookup_arg args = { |
| 2632 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2633 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2634 | .name = name, |
| 2635 | }; |
| 2636 | struct nfs4_lookup_res res = { |
| 2637 | .server = server, |
| 2638 | .fattr = fattr, |
| 2639 | .fh = fhandle, |
| 2640 | }; |
| 2641 | struct rpc_message msg = { |
| 2642 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2643 | .rpc_argp = &args, |
| 2644 | .rpc_resp = &res, |
| 2645 | }; |
| 2646 | |
| 2647 | nfs_fattr_init(fattr); |
| 2648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2650 | 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] | 2651 | dprintk("NFS reply lookup: %d\n", status); |
| 2652 | return status; |
| 2653 | } |
| 2654 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2655 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2656 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2657 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2658 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2659 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2660 | fattr->nlink = 2; |
| 2661 | } |
| 2662 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2663 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2664 | struct qstr *name, struct nfs_fh *fhandle, |
| 2665 | struct nfs_fattr *fattr) |
| 2666 | { |
| 2667 | struct nfs4_exception exception = { }; |
| 2668 | struct rpc_clnt *client = *clnt; |
| 2669 | int err; |
| 2670 | do { |
| 2671 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2672 | switch (err) { |
| 2673 | case -NFS4ERR_BADNAME: |
| 2674 | err = -ENOENT; |
| 2675 | goto out; |
| 2676 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2677 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2678 | goto out; |
| 2679 | case -NFS4ERR_WRONGSEC: |
| 2680 | err = -EPERM; |
| 2681 | if (client != *clnt) |
| 2682 | goto out; |
| 2683 | |
| 2684 | client = nfs4_create_sec_client(client, dir, name); |
| 2685 | if (IS_ERR(client)) |
| 2686 | return PTR_ERR(client); |
| 2687 | |
| 2688 | exception.retry = 1; |
| 2689 | break; |
| 2690 | default: |
| 2691 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2692 | } |
| 2693 | } while (exception.retry); |
| 2694 | |
| 2695 | out: |
| 2696 | if (err == 0) |
| 2697 | *clnt = client; |
| 2698 | else if (client != *clnt) |
| 2699 | rpc_shutdown_client(client); |
| 2700 | |
| 2701 | return err; |
| 2702 | } |
| 2703 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2704 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2705 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2707 | int status; |
| 2708 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2709 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2710 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2711 | if (client != NFS_CLIENT(dir)) { |
| 2712 | rpc_shutdown_client(client); |
| 2713 | nfs_fixup_secinfo_attributes(fattr); |
| 2714 | } |
| 2715 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2718 | struct rpc_clnt * |
| 2719 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2720 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2721 | { |
| 2722 | int status; |
| 2723 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2724 | |
| 2725 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2726 | if (status < 0) { |
| 2727 | rpc_shutdown_client(client); |
| 2728 | return ERR_PTR(status); |
| 2729 | } |
| 2730 | return client; |
| 2731 | } |
| 2732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2734 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2735 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | struct nfs4_accessargs args = { |
| 2737 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2738 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2740 | struct nfs4_accessres res = { |
| 2741 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2742 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | struct rpc_message msg = { |
| 2744 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2745 | .rpc_argp = &args, |
| 2746 | .rpc_resp = &res, |
| 2747 | .rpc_cred = entry->cred, |
| 2748 | }; |
| 2749 | int mode = entry->mask; |
| 2750 | int status; |
| 2751 | |
| 2752 | /* |
| 2753 | * Determine which access bits we want to ask for... |
| 2754 | */ |
| 2755 | if (mode & MAY_READ) |
| 2756 | args.access |= NFS4_ACCESS_READ; |
| 2757 | if (S_ISDIR(inode->i_mode)) { |
| 2758 | if (mode & MAY_WRITE) |
| 2759 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2760 | if (mode & MAY_EXEC) |
| 2761 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2762 | } else { |
| 2763 | if (mode & MAY_WRITE) |
| 2764 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2765 | if (mode & MAY_EXEC) |
| 2766 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2767 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2768 | |
| 2769 | res.fattr = nfs_alloc_fattr(); |
| 2770 | if (res.fattr == NULL) |
| 2771 | return -ENOMEM; |
| 2772 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2773 | 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] | 2774 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2775 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2776 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2778 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | return status; |
| 2780 | } |
| 2781 | |
| 2782 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2783 | { |
| 2784 | struct nfs4_exception exception = { }; |
| 2785 | int err; |
| 2786 | do { |
| 2787 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2788 | _nfs4_proc_access(inode, entry), |
| 2789 | &exception); |
| 2790 | } while (exception.retry); |
| 2791 | return err; |
| 2792 | } |
| 2793 | |
| 2794 | /* |
| 2795 | * TODO: For the time being, we don't try to get any attributes |
| 2796 | * along with any of the zero-copy operations READ, READDIR, |
| 2797 | * READLINK, WRITE. |
| 2798 | * |
| 2799 | * In the case of the first three, we want to put the GETATTR |
| 2800 | * after the read-type operation -- this is because it is hard |
| 2801 | * to predict the length of a GETATTR response in v4, and thus |
| 2802 | * align the READ data correctly. This means that the GETATTR |
| 2803 | * may end up partially falling into the page cache, and we should |
| 2804 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2805 | * To do this efficiently, we need to know the total length |
| 2806 | * of data received, which doesn't seem to be available outside |
| 2807 | * of the RPC layer. |
| 2808 | * |
| 2809 | * In the case of WRITE, we also want to put the GETATTR after |
| 2810 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2811 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | * |
| 2813 | * Both of these changes to the XDR layer would in fact be quite |
| 2814 | * minor, but I decided to leave them for a subsequent patch. |
| 2815 | */ |
| 2816 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2817 | unsigned int pgbase, unsigned int pglen) |
| 2818 | { |
| 2819 | struct nfs4_readlink args = { |
| 2820 | .fh = NFS_FH(inode), |
| 2821 | .pgbase = pgbase, |
| 2822 | .pglen = pglen, |
| 2823 | .pages = &page, |
| 2824 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2825 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | struct rpc_message msg = { |
| 2827 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2828 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2829 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | }; |
| 2831 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2832 | 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] | 2833 | } |
| 2834 | |
| 2835 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2836 | unsigned int pgbase, unsigned int pglen) |
| 2837 | { |
| 2838 | struct nfs4_exception exception = { }; |
| 2839 | int err; |
| 2840 | do { |
| 2841 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2842 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2843 | &exception); |
| 2844 | } while (exception.retry); |
| 2845 | return err; |
| 2846 | } |
| 2847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2849 | * 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] | 2850 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | static int |
| 2852 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2853 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2855 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | int status = 0; |
| 2858 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2859 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2860 | if (IS_ERR(ctx)) |
| 2861 | return PTR_ERR(ctx); |
| 2862 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2863 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2864 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2865 | flags, sattr, ctx->cred, |
| 2866 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2867 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | if (IS_ERR(state)) { |
| 2869 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2870 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2872 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2873 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2874 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2876 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | return status; |
| 2878 | } |
| 2879 | |
| 2880 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2881 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2882 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2883 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2885 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2887 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2888 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2889 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2892 | .rpc_argp = &args, |
| 2893 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2895 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2896 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2897 | 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] | 2898 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2899 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | return status; |
| 2901 | } |
| 2902 | |
| 2903 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2904 | { |
| 2905 | struct nfs4_exception exception = { }; |
| 2906 | int err; |
| 2907 | do { |
| 2908 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2909 | _nfs4_proc_remove(dir, name), |
| 2910 | &exception); |
| 2911 | } while (exception.retry); |
| 2912 | return err; |
| 2913 | } |
| 2914 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2915 | 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] | 2916 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2917 | struct nfs_server *server = NFS_SERVER(dir); |
| 2918 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2919 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2921 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2923 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2926 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2927 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2928 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2929 | &data->args.seq_args, |
| 2930 | &data->res.seq_res, |
| 2931 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2934 | 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] | 2935 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2936 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2937 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2938 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2939 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2940 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2941 | return 0; |
| 2942 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2943 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | } |
| 2945 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2946 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2947 | { |
| 2948 | struct nfs_server *server = NFS_SERVER(dir); |
| 2949 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2950 | struct nfs_renameres *res = msg->rpc_resp; |
| 2951 | |
| 2952 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2953 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2954 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2955 | } |
| 2956 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2957 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2958 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2959 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2960 | &data->args.seq_args, |
| 2961 | &data->res.seq_res, |
| 2962 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2966 | struct inode *new_dir) |
| 2967 | { |
| 2968 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2969 | |
| 2970 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2971 | return 0; |
| 2972 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2973 | return 0; |
| 2974 | |
| 2975 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2976 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2977 | return 1; |
| 2978 | } |
| 2979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2981 | struct inode *new_dir, struct qstr *new_name) |
| 2982 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2983 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2984 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | .old_dir = NFS_FH(old_dir), |
| 2986 | .new_dir = NFS_FH(new_dir), |
| 2987 | .old_name = old_name, |
| 2988 | .new_name = new_name, |
| 2989 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2990 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2991 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2992 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | struct rpc_message msg = { |
| 2994 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2995 | .rpc_argp = &arg, |
| 2996 | .rpc_resp = &res, |
| 2997 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2998 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3000 | 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] | 3001 | if (!status) { |
| 3002 | update_changeattr(old_dir, &res.old_cinfo); |
| 3003 | update_changeattr(new_dir, &res.new_cinfo); |
| 3004 | } |
| 3005 | return status; |
| 3006 | } |
| 3007 | |
| 3008 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3009 | struct inode *new_dir, struct qstr *new_name) |
| 3010 | { |
| 3011 | struct nfs4_exception exception = { }; |
| 3012 | int err; |
| 3013 | do { |
| 3014 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3015 | _nfs4_proc_rename(old_dir, old_name, |
| 3016 | new_dir, new_name), |
| 3017 | &exception); |
| 3018 | } while (exception.retry); |
| 3019 | return err; |
| 3020 | } |
| 3021 | |
| 3022 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3023 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3024 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | struct nfs4_link_arg arg = { |
| 3026 | .fh = NFS_FH(inode), |
| 3027 | .dir_fh = NFS_FH(dir), |
| 3028 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3029 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3031 | struct nfs4_link_res res = { |
| 3032 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3033 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | struct rpc_message msg = { |
| 3035 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3036 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3037 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3039 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3041 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3042 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3043 | goto out; |
| 3044 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3045 | 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] | 3046 | if (!status) { |
| 3047 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3048 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3049 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3050 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3051 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | return status; |
| 3053 | } |
| 3054 | |
| 3055 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3056 | { |
| 3057 | struct nfs4_exception exception = { }; |
| 3058 | int err; |
| 3059 | do { |
| 3060 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3061 | _nfs4_proc_link(inode, dir, name), |
| 3062 | &exception); |
| 3063 | } while (exception.retry); |
| 3064 | return err; |
| 3065 | } |
| 3066 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3067 | struct nfs4_createdata { |
| 3068 | struct rpc_message msg; |
| 3069 | struct nfs4_create_arg arg; |
| 3070 | struct nfs4_create_res res; |
| 3071 | struct nfs_fh fh; |
| 3072 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3073 | }; |
| 3074 | |
| 3075 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3076 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3077 | { |
| 3078 | struct nfs4_createdata *data; |
| 3079 | |
| 3080 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3081 | if (data != NULL) { |
| 3082 | struct nfs_server *server = NFS_SERVER(dir); |
| 3083 | |
| 3084 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3085 | data->msg.rpc_argp = &data->arg; |
| 3086 | data->msg.rpc_resp = &data->res; |
| 3087 | data->arg.dir_fh = NFS_FH(dir); |
| 3088 | data->arg.server = server; |
| 3089 | data->arg.name = name; |
| 3090 | data->arg.attrs = sattr; |
| 3091 | data->arg.ftype = ftype; |
| 3092 | data->arg.bitmask = server->attr_bitmask; |
| 3093 | data->res.server = server; |
| 3094 | data->res.fh = &data->fh; |
| 3095 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3096 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3097 | } |
| 3098 | return data; |
| 3099 | } |
| 3100 | |
| 3101 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3102 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3103 | 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] | 3104 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3105 | if (status == 0) { |
| 3106 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3107 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3108 | } |
| 3109 | return status; |
| 3110 | } |
| 3111 | |
| 3112 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3113 | { |
| 3114 | kfree(data); |
| 3115 | } |
| 3116 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3117 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3118 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3120 | struct nfs4_createdata *data; |
| 3121 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3123 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3124 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3125 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3126 | status = -ENOMEM; |
| 3127 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3128 | if (data == NULL) |
| 3129 | goto out; |
| 3130 | |
| 3131 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3132 | data->arg.u.symlink.pages = &page; |
| 3133 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3135 | status = nfs4_do_create(dir, dentry, data); |
| 3136 | |
| 3137 | nfs4_free_createdata(data); |
| 3138 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | return status; |
| 3140 | } |
| 3141 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3142 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3143 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | { |
| 3145 | struct nfs4_exception exception = { }; |
| 3146 | int err; |
| 3147 | do { |
| 3148 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3149 | _nfs4_proc_symlink(dir, dentry, page, |
| 3150 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | &exception); |
| 3152 | } while (exception.retry); |
| 3153 | return err; |
| 3154 | } |
| 3155 | |
| 3156 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3157 | struct iattr *sattr) |
| 3158 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3159 | struct nfs4_createdata *data; |
| 3160 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3162 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3163 | if (data == NULL) |
| 3164 | goto out; |
| 3165 | |
| 3166 | status = nfs4_do_create(dir, dentry, data); |
| 3167 | |
| 3168 | nfs4_free_createdata(data); |
| 3169 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | return status; |
| 3171 | } |
| 3172 | |
| 3173 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3174 | struct iattr *sattr) |
| 3175 | { |
| 3176 | struct nfs4_exception exception = { }; |
| 3177 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3178 | |
| 3179 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | do { |
| 3181 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3182 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3183 | &exception); |
| 3184 | } while (exception.retry); |
| 3185 | return err; |
| 3186 | } |
| 3187 | |
| 3188 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3189 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | { |
| 3191 | struct inode *dir = dentry->d_inode; |
| 3192 | struct nfs4_readdir_arg args = { |
| 3193 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3194 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | .pgbase = 0, |
| 3196 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3197 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3198 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | }; |
| 3200 | struct nfs4_readdir_res res; |
| 3201 | struct rpc_message msg = { |
| 3202 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3203 | .rpc_argp = &args, |
| 3204 | .rpc_resp = &res, |
| 3205 | .rpc_cred = cred, |
| 3206 | }; |
| 3207 | int status; |
| 3208 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3209 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3210 | dentry->d_parent->d_name.name, |
| 3211 | dentry->d_name.name, |
| 3212 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3213 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3215 | 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] | 3216 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3217 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3218 | status += args.pgbase; |
| 3219 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3220 | |
| 3221 | nfs_invalidate_atime(dir); |
| 3222 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3223 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | return status; |
| 3225 | } |
| 3226 | |
| 3227 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3228 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | { |
| 3230 | struct nfs4_exception exception = { }; |
| 3231 | int err; |
| 3232 | do { |
| 3233 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3234 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3235 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | &exception); |
| 3237 | } while (exception.retry); |
| 3238 | return err; |
| 3239 | } |
| 3240 | |
| 3241 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3242 | struct iattr *sattr, dev_t rdev) |
| 3243 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3244 | struct nfs4_createdata *data; |
| 3245 | int mode = sattr->ia_mode; |
| 3246 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3248 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3249 | if (data == NULL) |
| 3250 | goto out; |
| 3251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3253 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3255 | data->arg.ftype = NF4BLK; |
| 3256 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3257 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | } |
| 3259 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3260 | data->arg.ftype = NF4CHR; |
| 3261 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3262 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3263 | } else if (!S_ISSOCK(mode)) { |
| 3264 | status = -EINVAL; |
| 3265 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3268 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3269 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3270 | nfs4_free_createdata(data); |
| 3271 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | return status; |
| 3273 | } |
| 3274 | |
| 3275 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3276 | struct iattr *sattr, dev_t rdev) |
| 3277 | { |
| 3278 | struct nfs4_exception exception = { }; |
| 3279 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3280 | |
| 3281 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | do { |
| 3283 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3284 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3285 | &exception); |
| 3286 | } while (exception.retry); |
| 3287 | return err; |
| 3288 | } |
| 3289 | |
| 3290 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3291 | struct nfs_fsstat *fsstat) |
| 3292 | { |
| 3293 | struct nfs4_statfs_arg args = { |
| 3294 | .fh = fhandle, |
| 3295 | .bitmask = server->attr_bitmask, |
| 3296 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3297 | struct nfs4_statfs_res res = { |
| 3298 | .fsstat = fsstat, |
| 3299 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | struct rpc_message msg = { |
| 3301 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3302 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3303 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | }; |
| 3305 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3306 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3307 | 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] | 3308 | } |
| 3309 | |
| 3310 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3311 | { |
| 3312 | struct nfs4_exception exception = { }; |
| 3313 | int err; |
| 3314 | do { |
| 3315 | err = nfs4_handle_exception(server, |
| 3316 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3317 | &exception); |
| 3318 | } while (exception.retry); |
| 3319 | return err; |
| 3320 | } |
| 3321 | |
| 3322 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3323 | struct nfs_fsinfo *fsinfo) |
| 3324 | { |
| 3325 | struct nfs4_fsinfo_arg args = { |
| 3326 | .fh = fhandle, |
| 3327 | .bitmask = server->attr_bitmask, |
| 3328 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3329 | struct nfs4_fsinfo_res res = { |
| 3330 | .fsinfo = fsinfo, |
| 3331 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | struct rpc_message msg = { |
| 3333 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3334 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3335 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | }; |
| 3337 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3338 | 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] | 3339 | } |
| 3340 | |
| 3341 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3342 | { |
| 3343 | struct nfs4_exception exception = { }; |
| 3344 | int err; |
| 3345 | |
| 3346 | do { |
| 3347 | err = nfs4_handle_exception(server, |
| 3348 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3349 | &exception); |
| 3350 | } while (exception.retry); |
| 3351 | return err; |
| 3352 | } |
| 3353 | |
| 3354 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3355 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3356 | int error; |
| 3357 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3358 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3359 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3360 | if (error == 0) { |
| 3361 | /* block layout checks this! */ |
| 3362 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3363 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3364 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3365 | |
| 3366 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3370 | struct nfs_pathconf *pathconf) |
| 3371 | { |
| 3372 | struct nfs4_pathconf_arg args = { |
| 3373 | .fh = fhandle, |
| 3374 | .bitmask = server->attr_bitmask, |
| 3375 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3376 | struct nfs4_pathconf_res res = { |
| 3377 | .pathconf = pathconf, |
| 3378 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | struct rpc_message msg = { |
| 3380 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3381 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3382 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | }; |
| 3384 | |
| 3385 | /* None of the pathconf attributes are mandatory to implement */ |
| 3386 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3387 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3388 | return 0; |
| 3389 | } |
| 3390 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3391 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3392 | 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] | 3393 | } |
| 3394 | |
| 3395 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3396 | struct nfs_pathconf *pathconf) |
| 3397 | { |
| 3398 | struct nfs4_exception exception = { }; |
| 3399 | int err; |
| 3400 | |
| 3401 | do { |
| 3402 | err = nfs4_handle_exception(server, |
| 3403 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3404 | &exception); |
| 3405 | } while (exception.retry); |
| 3406 | return err; |
| 3407 | } |
| 3408 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3409 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3410 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3411 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3412 | } |
| 3413 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3414 | 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] | 3415 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3416 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3418 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3419 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3420 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3422 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3423 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3425 | renew_lease(server, data->timestamp); |
| 3426 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3429 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3430 | { |
| 3431 | |
| 3432 | dprintk("--> %s\n", __func__); |
| 3433 | |
| 3434 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3435 | return -EAGAIN; |
| 3436 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3437 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3438 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3439 | } |
| 3440 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3441 | 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] | 3442 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3444 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3445 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3446 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3449 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3450 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3451 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3452 | &data->args.seq_args, |
| 3453 | &data->res.seq_res, |
| 3454 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3457 | 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] | 3458 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3459 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3461 | 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] | 3462 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3463 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3465 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3467 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3468 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3469 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3472 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3473 | { |
| 3474 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3475 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3476 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3477 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3480 | static |
| 3481 | 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] | 3482 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3483 | const struct nfs_pgio_header *hdr = data->header; |
| 3484 | |
| 3485 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3486 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3487 | return false; |
| 3488 | /* Otherwise, request attributes if and only if we don't hold |
| 3489 | * a delegation |
| 3490 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3491 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3492 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3493 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3494 | 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] | 3495 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3496 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3497 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3498 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3499 | data->args.bitmask = NULL; |
| 3500 | data->res.fattr = NULL; |
| 3501 | } else |
| 3502 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3503 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3504 | if (!data->write_done_cb) |
| 3505 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3506 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | data->timestamp = jiffies; |
| 3508 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3509 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3510 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3513 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3514 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3515 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3516 | &data->args.seq_args, |
| 3517 | &data->res.seq_res, |
| 3518 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3521 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3522 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3523 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3524 | &data->args.seq_args, |
| 3525 | &data->res.seq_res, |
| 3526 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3529 | 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] | 3530 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3532 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3533 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3534 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3535 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3537 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3540 | 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] | 3541 | { |
| 3542 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3543 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3544 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3545 | } |
| 3546 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3547 | 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] | 3548 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3549 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3550 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3551 | if (data->commit_done_cb == NULL) |
| 3552 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3553 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3554 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3555 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3558 | struct nfs4_renewdata { |
| 3559 | struct nfs_client *client; |
| 3560 | unsigned long timestamp; |
| 3561 | }; |
| 3562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | /* |
| 3564 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3565 | * standalone procedure for queueing an asynchronous RENEW. |
| 3566 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3567 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3568 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3569 | struct nfs4_renewdata *data = calldata; |
| 3570 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3571 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3572 | if (atomic_read(&clp->cl_count) > 1) |
| 3573 | nfs4_schedule_state_renewal(clp); |
| 3574 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3575 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3576 | } |
| 3577 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3578 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3580 | struct nfs4_renewdata *data = calldata; |
| 3581 | struct nfs_client *clp = data->client; |
| 3582 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | |
| 3584 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3585 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3586 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3587 | return; |
| 3588 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3589 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3590 | return; |
| 3591 | } |
| 3592 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3594 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3597 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3598 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3599 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3600 | }; |
| 3601 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3602 | 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] | 3603 | { |
| 3604 | struct rpc_message msg = { |
| 3605 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3606 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3607 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3609 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3611 | if (renew_flags == 0) |
| 3612 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3613 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3614 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3615 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3616 | if (data == NULL) |
| 3617 | return -ENOMEM; |
| 3618 | data->client = clp; |
| 3619 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3621 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3624 | 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] | 3625 | { |
| 3626 | struct rpc_message msg = { |
| 3627 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3628 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3629 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | }; |
| 3631 | unsigned long now = jiffies; |
| 3632 | int status; |
| 3633 | |
| 3634 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3635 | if (status < 0) |
| 3636 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3637 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | return 0; |
| 3639 | } |
| 3640 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3641 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3642 | { |
| 3643 | return (server->caps & NFS_CAP_ACLS) |
| 3644 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3645 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3646 | } |
| 3647 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3648 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3649 | * 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] | 3650 | * the stack. |
| 3651 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3652 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3653 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3654 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3655 | struct page **pages, unsigned int *pgbase) |
| 3656 | { |
| 3657 | struct page *newpage, **spages; |
| 3658 | int rc = 0; |
| 3659 | size_t len; |
| 3660 | spages = pages; |
| 3661 | |
| 3662 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3663 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3664 | newpage = alloc_page(GFP_KERNEL); |
| 3665 | |
| 3666 | if (newpage == NULL) |
| 3667 | goto unwind; |
| 3668 | memcpy(page_address(newpage), buf, len); |
| 3669 | buf += len; |
| 3670 | buflen -= len; |
| 3671 | *pages++ = newpage; |
| 3672 | rc++; |
| 3673 | } while (buflen != 0); |
| 3674 | |
| 3675 | return rc; |
| 3676 | |
| 3677 | unwind: |
| 3678 | for(; rc > 0; rc--) |
| 3679 | __free_page(spages[rc-1]); |
| 3680 | return -ENOMEM; |
| 3681 | } |
| 3682 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3683 | struct nfs4_cached_acl { |
| 3684 | int cached; |
| 3685 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3686 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3687 | }; |
| 3688 | |
| 3689 | 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] | 3690 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3691 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3692 | |
| 3693 | spin_lock(&inode->i_lock); |
| 3694 | kfree(nfsi->nfs4_acl); |
| 3695 | nfsi->nfs4_acl = acl; |
| 3696 | spin_unlock(&inode->i_lock); |
| 3697 | } |
| 3698 | |
| 3699 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3700 | { |
| 3701 | nfs4_set_cached_acl(inode, NULL); |
| 3702 | } |
| 3703 | |
| 3704 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3705 | { |
| 3706 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3707 | struct nfs4_cached_acl *acl; |
| 3708 | int ret = -ENOENT; |
| 3709 | |
| 3710 | spin_lock(&inode->i_lock); |
| 3711 | acl = nfsi->nfs4_acl; |
| 3712 | if (acl == NULL) |
| 3713 | goto out; |
| 3714 | if (buf == NULL) /* user is just asking for length */ |
| 3715 | goto out_len; |
| 3716 | if (acl->cached == 0) |
| 3717 | goto out; |
| 3718 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3719 | if (acl->len > buflen) |
| 3720 | goto out; |
| 3721 | memcpy(buf, acl->data, acl->len); |
| 3722 | out_len: |
| 3723 | ret = acl->len; |
| 3724 | out: |
| 3725 | spin_unlock(&inode->i_lock); |
| 3726 | return ret; |
| 3727 | } |
| 3728 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3729 | 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] | 3730 | { |
| 3731 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3732 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3733 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3734 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3735 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3736 | if (acl == NULL) |
| 3737 | goto out; |
| 3738 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3739 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3740 | } else { |
| 3741 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3742 | if (acl == NULL) |
| 3743 | goto out; |
| 3744 | acl->cached = 0; |
| 3745 | } |
| 3746 | acl->len = acl_len; |
| 3747 | out: |
| 3748 | nfs4_set_cached_acl(inode, acl); |
| 3749 | } |
| 3750 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3751 | /* |
| 3752 | * The getxattr API returns the required buffer length when called with a |
| 3753 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3754 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3755 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3756 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3757 | * the cache. If not so, we throw away the page, and cache the required |
| 3758 | * length. The next getxattr call will then produce another round trip to |
| 3759 | * the server, this time with the input buf of the required size. |
| 3760 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3761 | 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] | 3762 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3763 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3764 | struct nfs_getaclargs args = { |
| 3765 | .fh = NFS_FH(inode), |
| 3766 | .acl_pages = pages, |
| 3767 | .acl_len = buflen, |
| 3768 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3769 | struct nfs_getaclres res = { |
| 3770 | .acl_len = buflen, |
| 3771 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3772 | struct rpc_message msg = { |
| 3773 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3774 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3775 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3776 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3777 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3778 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3779 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3780 | /* As long as we're doing a round trip to the server anyway, |
| 3781 | * let's be prepared for a page of acl data. */ |
| 3782 | if (npages == 0) |
| 3783 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3784 | if (npages > ARRAY_SIZE(pages)) |
| 3785 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3786 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3787 | for (i = 0; i < npages; i++) { |
| 3788 | pages[i] = alloc_page(GFP_KERNEL); |
| 3789 | if (!pages[i]) |
| 3790 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3791 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3792 | |
| 3793 | /* for decoding across pages */ |
| 3794 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3795 | if (!res.acl_scratch) |
| 3796 | goto out_free; |
| 3797 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3798 | args.acl_len = npages * PAGE_SIZE; |
| 3799 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3800 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3801 | 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] | 3802 | __func__, buf, buflen, npages, args.acl_len); |
| 3803 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3804 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3805 | if (ret) |
| 3806 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3807 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3808 | /* Handle the case where the passed-in buffer is too short */ |
| 3809 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3810 | /* Did the user only issue a request for the acl length? */ |
| 3811 | if (buf == NULL) |
| 3812 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3813 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3814 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3815 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3816 | 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] | 3817 | if (buf) { |
| 3818 | if (res.acl_len > buflen) { |
| 3819 | ret = -ERANGE; |
| 3820 | goto out_free; |
| 3821 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3822 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 3823 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3824 | out_ok: |
| 3825 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3826 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3827 | for (i = 0; i < npages; i++) |
| 3828 | if (pages[i]) |
| 3829 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3830 | if (res.acl_scratch) |
| 3831 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3832 | return ret; |
| 3833 | } |
| 3834 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3835 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3836 | { |
| 3837 | struct nfs4_exception exception = { }; |
| 3838 | ssize_t ret; |
| 3839 | do { |
| 3840 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3841 | if (ret >= 0) |
| 3842 | break; |
| 3843 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3844 | } while (exception.retry); |
| 3845 | return ret; |
| 3846 | } |
| 3847 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3848 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3849 | { |
| 3850 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3851 | int ret; |
| 3852 | |
| 3853 | if (!nfs4_server_supports_acls(server)) |
| 3854 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3855 | ret = nfs_revalidate_inode(server, inode); |
| 3856 | if (ret < 0) |
| 3857 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3858 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3859 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3860 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3861 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3862 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3863 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3864 | return ret; |
| 3865 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3866 | } |
| 3867 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3868 | 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] | 3869 | { |
| 3870 | struct nfs_server *server = NFS_SERVER(inode); |
| 3871 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3872 | struct nfs_setaclargs arg = { |
| 3873 | .fh = NFS_FH(inode), |
| 3874 | .acl_pages = pages, |
| 3875 | .acl_len = buflen, |
| 3876 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3877 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3878 | struct rpc_message msg = { |
| 3879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3880 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3881 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3882 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3883 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3884 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3885 | |
| 3886 | if (!nfs4_server_supports_acls(server)) |
| 3887 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3888 | if (npages > ARRAY_SIZE(pages)) |
| 3889 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3890 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3891 | if (i < 0) |
| 3892 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3893 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3894 | 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] | 3895 | |
| 3896 | /* |
| 3897 | * Free each page after tx, so the only ref left is |
| 3898 | * held by the network stack |
| 3899 | */ |
| 3900 | for (; i > 0; i--) |
| 3901 | put_page(pages[i-1]); |
| 3902 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3903 | /* |
| 3904 | * Acl update can result in inode attribute update. |
| 3905 | * so mark the attribute cache invalid. |
| 3906 | */ |
| 3907 | spin_lock(&inode->i_lock); |
| 3908 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3909 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3910 | nfs_access_zap_cache(inode); |
| 3911 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3912 | return ret; |
| 3913 | } |
| 3914 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3915 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3916 | { |
| 3917 | struct nfs4_exception exception = { }; |
| 3918 | int err; |
| 3919 | do { |
| 3920 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3921 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3922 | &exception); |
| 3923 | } while (exception.retry); |
| 3924 | return err; |
| 3925 | } |
| 3926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3928 | 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] | 3929 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3930 | struct nfs_client *clp = server->nfs_client; |
| 3931 | |
| 3932 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | return 0; |
| 3934 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3935 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3936 | case -NFS4ERR_ADMIN_REVOKED: |
| 3937 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3938 | if (state == NULL) |
| 3939 | break; |
| 3940 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3941 | case -NFS4ERR_OPENMODE: |
| 3942 | if (state == NULL) |
| 3943 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3944 | nfs4_schedule_stateid_recovery(server, state); |
| 3945 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3946 | case -NFS4ERR_EXPIRED: |
| 3947 | if (state != NULL) |
| 3948 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3950 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3951 | nfs4_schedule_lease_recovery(clp); |
| 3952 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3953 | #if defined(CONFIG_NFS_V4_1) |
| 3954 | case -NFS4ERR_BADSESSION: |
| 3955 | case -NFS4ERR_BADSLOT: |
| 3956 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3957 | case -NFS4ERR_DEADSESSION: |
| 3958 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3959 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3960 | case -NFS4ERR_SEQ_MISORDERED: |
| 3961 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3962 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3963 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3964 | task->tk_status = 0; |
| 3965 | return -EAGAIN; |
| 3966 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3968 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3969 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3971 | task->tk_status = 0; |
| 3972 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3973 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | case -NFS4ERR_OLD_STATEID: |
| 3975 | task->tk_status = 0; |
| 3976 | return -EAGAIN; |
| 3977 | } |
| 3978 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3979 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3980 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3981 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3982 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3983 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3984 | task->tk_status = 0; |
| 3985 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3988 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 3989 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3990 | { |
| 3991 | __be32 verf[2]; |
| 3992 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 3993 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 3994 | /* An impossible timestamp guarantees this value |
| 3995 | * will never match a generated boot time. */ |
| 3996 | verf[0] = 0; |
| 3997 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 3998 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3999 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4000 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4001 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4002 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4003 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4004 | } |
| 4005 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4006 | static unsigned int |
| 4007 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4008 | char *buf, size_t len) |
| 4009 | { |
| 4010 | unsigned int result; |
| 4011 | |
| 4012 | rcu_read_lock(); |
| 4013 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4014 | clp->cl_ipaddr, |
| 4015 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4016 | RPC_DISPLAY_ADDR), |
| 4017 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4018 | RPC_DISPLAY_PROTO)); |
| 4019 | rcu_read_unlock(); |
| 4020 | return result; |
| 4021 | } |
| 4022 | |
| 4023 | static unsigned int |
| 4024 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4025 | char *buf, size_t len) |
| 4026 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4027 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4028 | |
| 4029 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4030 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4031 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4032 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4033 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4034 | } |
| 4035 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4036 | /** |
| 4037 | * nfs4_proc_setclientid - Negotiate client ID |
| 4038 | * @clp: state data structure |
| 4039 | * @program: RPC program for NFSv4 callback service |
| 4040 | * @port: IP port number for NFS4 callback service |
| 4041 | * @cred: RPC credential to use for this call |
| 4042 | * @res: where to place the result |
| 4043 | * |
| 4044 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4045 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4046 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4047 | unsigned short port, struct rpc_cred *cred, |
| 4048 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | { |
| 4050 | nfs4_verifier sc_verifier; |
| 4051 | struct nfs4_setclientid setclientid = { |
| 4052 | .sc_verifier = &sc_verifier, |
| 4053 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4054 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | }; |
| 4056 | struct rpc_message msg = { |
| 4057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4058 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4059 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4060 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4062 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4064 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4065 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4066 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4067 | setclientid.sc_name_len = |
| 4068 | nfs4_init_uniform_client_string(clp, |
| 4069 | setclientid.sc_name, |
| 4070 | sizeof(setclientid.sc_name)); |
| 4071 | else |
| 4072 | setclientid.sc_name_len = |
| 4073 | nfs4_init_nonuniform_client_string(clp, |
| 4074 | setclientid.sc_name, |
| 4075 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4076 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4077 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4078 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4079 | sizeof(setclientid.sc_netid), |
| 4080 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4081 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4082 | rcu_read_unlock(); |
| 4083 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4084 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4086 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4087 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4088 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4089 | setclientid.sc_name_len, setclientid.sc_name); |
| 4090 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4091 | dprintk("NFS reply setclientid: %d\n", status); |
| 4092 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4095 | /** |
| 4096 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4097 | * @clp: state data structure |
| 4098 | * @res: result of a previous SETCLIENTID |
| 4099 | * @cred: RPC credential to use for this call |
| 4100 | * |
| 4101 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4102 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4103 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4104 | struct nfs4_setclientid_res *arg, |
| 4105 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | { |
| 4107 | struct nfs_fsinfo fsinfo; |
| 4108 | struct rpc_message msg = { |
| 4109 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4110 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4112 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | }; |
| 4114 | unsigned long now; |
| 4115 | int status; |
| 4116 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4117 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4118 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4119 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4121 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | if (status == 0) { |
| 4123 | spin_lock(&clp->cl_lock); |
| 4124 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4125 | clp->cl_last_renewal = now; |
| 4126 | spin_unlock(&clp->cl_lock); |
| 4127 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4128 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | return status; |
| 4130 | } |
| 4131 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4132 | struct nfs4_delegreturndata { |
| 4133 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4134 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4135 | struct nfs_fh fh; |
| 4136 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4137 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4138 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4139 | int rpc_status; |
| 4140 | }; |
| 4141 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4142 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4143 | { |
| 4144 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4145 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4146 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4147 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4148 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4149 | switch (task->tk_status) { |
| 4150 | case -NFS4ERR_STALE_STATEID: |
| 4151 | case -NFS4ERR_EXPIRED: |
| 4152 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4153 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4154 | break; |
| 4155 | default: |
| 4156 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4157 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4158 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4159 | return; |
| 4160 | } |
| 4161 | } |
| 4162 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | static void nfs4_delegreturn_release(void *calldata) |
| 4166 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4167 | kfree(calldata); |
| 4168 | } |
| 4169 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4170 | #if defined(CONFIG_NFS_V4_1) |
| 4171 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4172 | { |
| 4173 | struct nfs4_delegreturndata *d_data; |
| 4174 | |
| 4175 | d_data = (struct nfs4_delegreturndata *)data; |
| 4176 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4177 | nfs4_setup_sequence(d_data->res.server, |
| 4178 | &d_data->args.seq_args, |
| 4179 | &d_data->res.seq_res, |
| 4180 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4181 | } |
| 4182 | #endif /* CONFIG_NFS_V4_1 */ |
| 4183 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4184 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4185 | #if defined(CONFIG_NFS_V4_1) |
| 4186 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4187 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4188 | .rpc_call_done = nfs4_delegreturn_done, |
| 4189 | .rpc_release = nfs4_delegreturn_release, |
| 4190 | }; |
| 4191 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4192 | 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] | 4193 | { |
| 4194 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4195 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4196 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4197 | struct rpc_message msg = { |
| 4198 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4199 | .rpc_cred = cred, |
| 4200 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4201 | struct rpc_task_setup task_setup_data = { |
| 4202 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4203 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4204 | .callback_ops = &nfs4_delegreturn_ops, |
| 4205 | .flags = RPC_TASK_ASYNC, |
| 4206 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4207 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4208 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4209 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4210 | if (data == NULL) |
| 4211 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4212 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4213 | data->args.fhandle = &data->fh; |
| 4214 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4215 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4216 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4217 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4218 | data->res.fattr = &data->fattr; |
| 4219 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4220 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4221 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4222 | data->rpc_status = 0; |
| 4223 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4224 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4225 | msg.rpc_argp = &data->args; |
| 4226 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4227 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4228 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4229 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4230 | if (!issync) |
| 4231 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4232 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4233 | if (status != 0) |
| 4234 | goto out; |
| 4235 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4236 | if (status == 0) |
| 4237 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4238 | else |
| 4239 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4240 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4241 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4242 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | } |
| 4244 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4245 | 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] | 4246 | { |
| 4247 | struct nfs_server *server = NFS_SERVER(inode); |
| 4248 | struct nfs4_exception exception = { }; |
| 4249 | int err; |
| 4250 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4251 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | switch (err) { |
| 4253 | case -NFS4ERR_STALE_STATEID: |
| 4254 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | case 0: |
| 4256 | return 0; |
| 4257 | } |
| 4258 | err = nfs4_handle_exception(server, err, &exception); |
| 4259 | } while (exception.retry); |
| 4260 | return err; |
| 4261 | } |
| 4262 | |
| 4263 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4264 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4265 | |
| 4266 | /* |
| 4267 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4268 | */ |
| 4269 | static unsigned long |
| 4270 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4271 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4272 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | timeout <<= 1; |
| 4274 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4275 | return NFS4_LOCK_MAXTIMEOUT; |
| 4276 | return timeout; |
| 4277 | } |
| 4278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4280 | { |
| 4281 | struct inode *inode = state->inode; |
| 4282 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4283 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4284 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4286 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4288 | struct nfs_lockt_res res = { |
| 4289 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | }; |
| 4291 | struct rpc_message msg = { |
| 4292 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4293 | .rpc_argp = &arg, |
| 4294 | .rpc_resp = &res, |
| 4295 | .rpc_cred = state->owner->so_cred, |
| 4296 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | struct nfs4_lock_state *lsp; |
| 4298 | int status; |
| 4299 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4300 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4301 | status = nfs4_set_lock_state(state, request); |
| 4302 | if (status != 0) |
| 4303 | goto out; |
| 4304 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4305 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4306 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4307 | 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] | 4308 | switch (status) { |
| 4309 | case 0: |
| 4310 | request->fl_type = F_UNLCK; |
| 4311 | break; |
| 4312 | case -NFS4ERR_DENIED: |
| 4313 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4315 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4316 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | return status; |
| 4318 | } |
| 4319 | |
| 4320 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4321 | { |
| 4322 | struct nfs4_exception exception = { }; |
| 4323 | int err; |
| 4324 | |
| 4325 | do { |
| 4326 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4327 | _nfs4_proc_getlk(state, cmd, request), |
| 4328 | &exception); |
| 4329 | } while (exception.retry); |
| 4330 | return err; |
| 4331 | } |
| 4332 | |
| 4333 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4334 | { |
| 4335 | int res = 0; |
| 4336 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4337 | case FL_POSIX: |
| 4338 | res = posix_lock_file_wait(file, fl); |
| 4339 | break; |
| 4340 | case FL_FLOCK: |
| 4341 | res = flock_lock_file_wait(file, fl); |
| 4342 | break; |
| 4343 | default: |
| 4344 | BUG(); |
| 4345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | return res; |
| 4347 | } |
| 4348 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4349 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4350 | struct nfs_locku_args arg; |
| 4351 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4352 | struct nfs4_lock_state *lsp; |
| 4353 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4354 | struct file_lock fl; |
| 4355 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4356 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4357 | }; |
| 4358 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4359 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4360 | struct nfs_open_context *ctx, |
| 4361 | struct nfs4_lock_state *lsp, |
| 4362 | struct nfs_seqid *seqid) |
| 4363 | { |
| 4364 | struct nfs4_unlockdata *p; |
| 4365 | struct inode *inode = lsp->ls_state->inode; |
| 4366 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4367 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4368 | if (p == NULL) |
| 4369 | return NULL; |
| 4370 | p->arg.fh = NFS_FH(inode); |
| 4371 | p->arg.fl = &p->fl; |
| 4372 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4373 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4374 | p->arg.stateid = &lsp->ls_stateid; |
| 4375 | p->lsp = lsp; |
| 4376 | atomic_inc(&lsp->ls_count); |
| 4377 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4378 | p->ctx = get_nfs_open_context(ctx); |
| 4379 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4380 | p->server = NFS_SERVER(inode); |
| 4381 | return p; |
| 4382 | } |
| 4383 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4384 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4385 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4386 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4387 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4388 | nfs4_put_lock_state(calldata->lsp); |
| 4389 | put_nfs_open_context(calldata->ctx); |
| 4390 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4391 | } |
| 4392 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4393 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4394 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4395 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4396 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4397 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4398 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4399 | switch (task->tk_status) { |
| 4400 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4401 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4402 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4403 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4404 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4405 | case -NFS4ERR_BAD_STATEID: |
| 4406 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4407 | case -NFS4ERR_STALE_STATEID: |
| 4408 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4409 | break; |
| 4410 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4411 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4412 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4413 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4414 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4417 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4418 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4419 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4421 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4422 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4423 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4424 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4425 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 4426 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4427 | return; |
| 4428 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4429 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4430 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4431 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4432 | &calldata->res.seq_res, |
| 4433 | task) != 0) |
| 4434 | nfs_release_seqid(calldata->arg.seqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4437 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4438 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4439 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4440 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4441 | }; |
| 4442 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4443 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4444 | struct nfs_open_context *ctx, |
| 4445 | struct nfs4_lock_state *lsp, |
| 4446 | struct nfs_seqid *seqid) |
| 4447 | { |
| 4448 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4449 | struct rpc_message msg = { |
| 4450 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4451 | .rpc_cred = ctx->cred, |
| 4452 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4453 | struct rpc_task_setup task_setup_data = { |
| 4454 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4455 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4456 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4457 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4458 | .flags = RPC_TASK_ASYNC, |
| 4459 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4460 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4461 | /* Ensure this is an unlock - when canceling a lock, the |
| 4462 | * canceled lock is passed in, and it won't be an unlock. |
| 4463 | */ |
| 4464 | fl->fl_type = F_UNLCK; |
| 4465 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4466 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4467 | if (data == NULL) { |
| 4468 | nfs_free_seqid(seqid); |
| 4469 | return ERR_PTR(-ENOMEM); |
| 4470 | } |
| 4471 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4472 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4473 | msg.rpc_argp = &data->arg; |
| 4474 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4475 | task_setup_data.callback_data = data; |
| 4476 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4477 | } |
| 4478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4480 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4481 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4482 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4483 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4484 | struct rpc_task *task; |
| 4485 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4486 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4488 | status = nfs4_set_lock_state(state, request); |
| 4489 | /* Unlock _before_ we do the RPC call */ |
| 4490 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4491 | down_read(&nfsi->rwsem); |
| 4492 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4493 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4494 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4495 | } |
| 4496 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4497 | if (status != 0) |
| 4498 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4499 | /* Is this a delegated lock? */ |
| 4500 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4501 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4502 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4503 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4504 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4505 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4506 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4507 | 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] | 4508 | status = PTR_ERR(task); |
| 4509 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4510 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4511 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4512 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4513 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4514 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4515 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4518 | struct nfs4_lockdata { |
| 4519 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4520 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4521 | struct nfs4_lock_state *lsp; |
| 4522 | struct nfs_open_context *ctx; |
| 4523 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4524 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4525 | int rpc_status; |
| 4526 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4527 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4528 | }; |
| 4529 | |
| 4530 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4531 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4532 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4533 | { |
| 4534 | struct nfs4_lockdata *p; |
| 4535 | struct inode *inode = lsp->ls_state->inode; |
| 4536 | struct nfs_server *server = NFS_SERVER(inode); |
| 4537 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4538 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4539 | if (p == NULL) |
| 4540 | return NULL; |
| 4541 | |
| 4542 | p->arg.fh = NFS_FH(inode); |
| 4543 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4544 | 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] | 4545 | if (p->arg.open_seqid == NULL) |
| 4546 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4547 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4548 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4549 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4550 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4551 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4552 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4553 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4554 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4555 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4556 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4557 | atomic_inc(&lsp->ls_count); |
| 4558 | p->ctx = get_nfs_open_context(ctx); |
| 4559 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4560 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4561 | out_free_seqid: |
| 4562 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4563 | out_free: |
| 4564 | kfree(p); |
| 4565 | return NULL; |
| 4566 | } |
| 4567 | |
| 4568 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4569 | { |
| 4570 | struct nfs4_lockdata *data = calldata; |
| 4571 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4573 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4574 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4575 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4576 | /* Do we need to do an open_to_lock_owner? */ |
| 4577 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4578 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4579 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4580 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4581 | data->arg.open_stateid = &state->stateid; |
| 4582 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4583 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4584 | } else |
| 4585 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4586 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4587 | if (nfs4_setup_sequence(data->server, |
| 4588 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4589 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4590 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4591 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4592 | nfs_release_seqid(data->arg.open_seqid); |
| 4593 | out_release_lock_seqid: |
| 4594 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4595 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4596 | } |
| 4597 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4598 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4599 | { |
| 4600 | struct nfs4_lockdata *data = calldata; |
| 4601 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4602 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4603 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4604 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4605 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4606 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4607 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4608 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4609 | if (data->rpc_status == 0) |
| 4610 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4611 | else |
| 4612 | goto out; |
| 4613 | } |
| 4614 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4615 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4616 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4617 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4618 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4619 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4620 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | static void nfs4_lock_release(void *calldata) |
| 4624 | { |
| 4625 | struct nfs4_lockdata *data = calldata; |
| 4626 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4627 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4628 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4629 | if (data->cancelled != 0) { |
| 4630 | struct rpc_task *task; |
| 4631 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4632 | data->arg.lock_seqid); |
| 4633 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4634 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4635 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4636 | } else |
| 4637 | nfs_free_seqid(data->arg.lock_seqid); |
| 4638 | nfs4_put_lock_state(data->lsp); |
| 4639 | put_nfs_open_context(data->ctx); |
| 4640 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4641 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4645 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4646 | .rpc_call_done = nfs4_lock_done, |
| 4647 | .rpc_release = nfs4_lock_release, |
| 4648 | }; |
| 4649 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4650 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4651 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4652 | switch (error) { |
| 4653 | case -NFS4ERR_ADMIN_REVOKED: |
| 4654 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4655 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4656 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4657 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4658 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4659 | break; |
| 4660 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4661 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4662 | case -NFS4ERR_EXPIRED: |
| 4663 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4664 | }; |
| 4665 | } |
| 4666 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4667 | 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] | 4668 | { |
| 4669 | struct nfs4_lockdata *data; |
| 4670 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4671 | struct rpc_message msg = { |
| 4672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4673 | .rpc_cred = state->owner->so_cred, |
| 4674 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4675 | struct rpc_task_setup task_setup_data = { |
| 4676 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4677 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4678 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4679 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4680 | .flags = RPC_TASK_ASYNC, |
| 4681 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4682 | int ret; |
| 4683 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4684 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4685 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4686 | fl->fl_u.nfs4_fl.owner, |
| 4687 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4688 | if (data == NULL) |
| 4689 | return -ENOMEM; |
| 4690 | if (IS_SETLKW(cmd)) |
| 4691 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4692 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4693 | msg.rpc_argp = &data->arg; |
| 4694 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4695 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4696 | if (recovery_type > NFS_LOCK_NEW) { |
| 4697 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4698 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4699 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4700 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4701 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4702 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4703 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4704 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4705 | if (ret == 0) { |
| 4706 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4707 | if (ret) |
| 4708 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4709 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4710 | } else |
| 4711 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4712 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4713 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4714 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4718 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4719 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4720 | struct nfs4_exception exception = { |
| 4721 | .inode = state->inode, |
| 4722 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4723 | int err; |
| 4724 | |
| 4725 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4726 | /* Cache the lock if possible... */ |
| 4727 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4728 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4729 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4730 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4731 | break; |
| 4732 | nfs4_handle_exception(server, err, &exception); |
| 4733 | } while (exception.retry); |
| 4734 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4738 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4739 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4740 | struct nfs4_exception exception = { |
| 4741 | .inode = state->inode, |
| 4742 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4743 | int err; |
| 4744 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4745 | err = nfs4_set_lock_state(state, request); |
| 4746 | if (err != 0) |
| 4747 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4748 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4749 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4750 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4751 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4752 | switch (err) { |
| 4753 | default: |
| 4754 | goto out; |
| 4755 | case -NFS4ERR_GRACE: |
| 4756 | case -NFS4ERR_DELAY: |
| 4757 | nfs4_handle_exception(server, err, &exception); |
| 4758 | err = 0; |
| 4759 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4760 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4761 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4762 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4765 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4766 | /** |
| 4767 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4768 | * |
| 4769 | * @state: NFSv4 state for an inode |
| 4770 | * |
| 4771 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4772 | * Otherwise a negative NFS4ERR value is returned. |
| 4773 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4774 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4775 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4776 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4777 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4778 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4779 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4780 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4781 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4782 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4783 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4784 | /* Free the stateid unless the server |
| 4785 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4786 | if (status != -NFS4ERR_BAD_STATEID) |
| 4787 | nfs41_free_stateid(server, |
| 4788 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4789 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4790 | ret = status; |
| 4791 | } |
| 4792 | } |
| 4793 | }; |
| 4794 | |
| 4795 | return ret; |
| 4796 | } |
| 4797 | |
| 4798 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4799 | { |
| 4800 | int status = NFS_OK; |
| 4801 | |
| 4802 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4803 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4804 | if (status != NFS_OK) |
| 4805 | status = nfs4_lock_expired(state, request); |
| 4806 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4807 | } |
| 4808 | #endif |
| 4809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4811 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4812 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4813 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4814 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4815 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4816 | if ((fl_flags & FL_POSIX) && |
| 4817 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4818 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4819 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4820 | status = nfs4_set_lock_state(state, request); |
| 4821 | if (status != 0) |
| 4822 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4823 | request->fl_flags |= FL_ACCESS; |
| 4824 | status = do_vfs_lock(request->fl_file, request); |
| 4825 | if (status < 0) |
| 4826 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4827 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4828 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4829 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4830 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4831 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4832 | status = do_vfs_lock(request->fl_file, request); |
| 4833 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4834 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4835 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4836 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4837 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4838 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4839 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4840 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4841 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4842 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4843 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4844 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4845 | out: |
| 4846 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | return status; |
| 4848 | } |
| 4849 | |
| 4850 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4851 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4852 | struct nfs4_exception exception = { |
| 4853 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4854 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4855 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | int err; |
| 4857 | |
| 4858 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4859 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4860 | if (err == -NFS4ERR_DENIED) |
| 4861 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4863 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | } while (exception.retry); |
| 4865 | return err; |
| 4866 | } |
| 4867 | |
| 4868 | static int |
| 4869 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4870 | { |
| 4871 | struct nfs_open_context *ctx; |
| 4872 | struct nfs4_state *state; |
| 4873 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4874 | int status; |
| 4875 | |
| 4876 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4877 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | state = ctx->state; |
| 4879 | |
| 4880 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4881 | return -EINVAL; |
| 4882 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4883 | if (IS_GETLK(cmd)) { |
| 4884 | if (state != NULL) |
| 4885 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4886 | return 0; |
| 4887 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | |
| 4889 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4890 | return -EINVAL; |
| 4891 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4892 | if (request->fl_type == F_UNLCK) { |
| 4893 | if (state != NULL) |
| 4894 | return nfs4_proc_unlck(state, cmd, request); |
| 4895 | return 0; |
| 4896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4898 | if (state == NULL) |
| 4899 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4900 | /* |
| 4901 | * Don't rely on the VFS having checked the file open mode, |
| 4902 | * since it won't do this for flock() locks. |
| 4903 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4904 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4905 | case F_RDLCK: |
| 4906 | if (!(filp->f_mode & FMODE_READ)) |
| 4907 | return -EBADF; |
| 4908 | break; |
| 4909 | case F_WRLCK: |
| 4910 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4911 | return -EBADF; |
| 4912 | } |
| 4913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | do { |
| 4915 | status = nfs4_proc_setlk(state, cmd, request); |
| 4916 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4917 | break; |
| 4918 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4919 | status = -ERESTARTSYS; |
| 4920 | if (signalled()) |
| 4921 | break; |
| 4922 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | return status; |
| 4924 | } |
| 4925 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4926 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4927 | { |
| 4928 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4929 | struct nfs4_exception exception = { }; |
| 4930 | int err; |
| 4931 | |
| 4932 | err = nfs4_set_lock_state(state, fl); |
| 4933 | if (err != 0) |
| 4934 | goto out; |
| 4935 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4936 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4937 | switch (err) { |
| 4938 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4939 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4940 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4941 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4942 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4943 | goto out; |
| 4944 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4945 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4946 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4947 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4948 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4949 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4950 | case -NFS4ERR_BADSESSION: |
| 4951 | case -NFS4ERR_BADSLOT: |
| 4952 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4953 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4954 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4955 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4956 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4957 | case -ERESTARTSYS: |
| 4958 | /* |
| 4959 | * The show must go on: exit, but mark the |
| 4960 | * stateid as needing recovery. |
| 4961 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4962 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4963 | case -NFS4ERR_ADMIN_REVOKED: |
| 4964 | case -NFS4ERR_BAD_STATEID: |
| 4965 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4966 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4967 | err = 0; |
| 4968 | goto out; |
| 4969 | case -ENOMEM: |
| 4970 | case -NFS4ERR_DENIED: |
| 4971 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4972 | err = 0; |
| 4973 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4974 | case -NFS4ERR_DELAY: |
| 4975 | break; |
| 4976 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4977 | err = nfs4_handle_exception(server, err, &exception); |
| 4978 | } while (exception.retry); |
| 4979 | out: |
| 4980 | return err; |
| 4981 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4982 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4983 | struct nfs_release_lockowner_data { |
| 4984 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4985 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4986 | struct nfs_release_lockowner_args args; |
| 4987 | }; |
| 4988 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4989 | static void nfs4_release_lockowner_release(void *calldata) |
| 4990 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4991 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4992 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4993 | kfree(calldata); |
| 4994 | } |
| 4995 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4996 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4997 | .rpc_release = nfs4_release_lockowner_release, |
| 4998 | }; |
| 4999 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5000 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5001 | { |
| 5002 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5003 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5004 | struct rpc_message msg = { |
| 5005 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5006 | }; |
| 5007 | |
| 5008 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5009 | return -EINVAL; |
| 5010 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5011 | if (!data) |
| 5012 | return -ENOMEM; |
| 5013 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5014 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5015 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5016 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5017 | data->args.lock_owner.s_dev = server->s_dev; |
| 5018 | msg.rpc_argp = &data->args; |
| 5019 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5020 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5021 | } |
| 5022 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5023 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5024 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5025 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5026 | const void *buf, size_t buflen, |
| 5027 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5028 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5029 | if (strcmp(key, "") != 0) |
| 5030 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5031 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5032 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5035 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5036 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5037 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5038 | if (strcmp(key, "") != 0) |
| 5039 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5040 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5041 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5042 | } |
| 5043 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5044 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5045 | size_t list_len, const char *name, |
| 5046 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5047 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5048 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5049 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5050 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5051 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5052 | |
| 5053 | if (list && len <= list_len) |
| 5054 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5055 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5056 | } |
| 5057 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5058 | /* |
| 5059 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5060 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5061 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5062 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5063 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5064 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5065 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5066 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5067 | return; |
| 5068 | |
| 5069 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5070 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5071 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5072 | fattr->nlink = 2; |
| 5073 | } |
| 5074 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5075 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5076 | const struct qstr *name, |
| 5077 | struct nfs4_fs_locations *fs_locations, |
| 5078 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5079 | { |
| 5080 | struct nfs_server *server = NFS_SERVER(dir); |
| 5081 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5082 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5083 | }; |
| 5084 | struct nfs4_fs_locations_arg args = { |
| 5085 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5086 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5087 | .page = page, |
| 5088 | .bitmask = bitmask, |
| 5089 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5090 | struct nfs4_fs_locations_res res = { |
| 5091 | .fs_locations = fs_locations, |
| 5092 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5093 | struct rpc_message msg = { |
| 5094 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5095 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5096 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5097 | }; |
| 5098 | int status; |
| 5099 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5100 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5101 | |
| 5102 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5103 | * is not supported */ |
| 5104 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5105 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5106 | else |
| 5107 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5108 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5109 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5110 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5111 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5112 | 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] | 5113 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5114 | return status; |
| 5115 | } |
| 5116 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5117 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5118 | const struct qstr *name, |
| 5119 | struct nfs4_fs_locations *fs_locations, |
| 5120 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5121 | { |
| 5122 | struct nfs4_exception exception = { }; |
| 5123 | int err; |
| 5124 | do { |
| 5125 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5126 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5127 | &exception); |
| 5128 | } while (exception.retry); |
| 5129 | return err; |
| 5130 | } |
| 5131 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5132 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5133 | { |
| 5134 | int status; |
| 5135 | struct nfs4_secinfo_arg args = { |
| 5136 | .dir_fh = NFS_FH(dir), |
| 5137 | .name = name, |
| 5138 | }; |
| 5139 | struct nfs4_secinfo_res res = { |
| 5140 | .flavors = flavors, |
| 5141 | }; |
| 5142 | struct rpc_message msg = { |
| 5143 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5144 | .rpc_argp = &args, |
| 5145 | .rpc_resp = &res, |
| 5146 | }; |
| 5147 | |
| 5148 | dprintk("NFS call secinfo %s\n", name->name); |
| 5149 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5150 | dprintk("NFS reply secinfo: %d\n", status); |
| 5151 | return status; |
| 5152 | } |
| 5153 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5154 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5155 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5156 | { |
| 5157 | struct nfs4_exception exception = { }; |
| 5158 | int err; |
| 5159 | do { |
| 5160 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5161 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5162 | &exception); |
| 5163 | } while (exception.retry); |
| 5164 | return err; |
| 5165 | } |
| 5166 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5167 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5168 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5169 | * Check the exchange flags returned by the server for invalid flags, having |
| 5170 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5171 | * DS flags set. |
| 5172 | */ |
| 5173 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5174 | { |
| 5175 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5176 | goto out_inval; |
| 5177 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5178 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5179 | goto out_inval; |
| 5180 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5181 | goto out_inval; |
| 5182 | return NFS_OK; |
| 5183 | out_inval: |
| 5184 | return -NFS4ERR_INVAL; |
| 5185 | } |
| 5186 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5187 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5188 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5189 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5190 | { |
| 5191 | if (a->server_scope_sz == b->server_scope_sz && |
| 5192 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5193 | return true; |
| 5194 | |
| 5195 | return false; |
| 5196 | } |
| 5197 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5198 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5199 | * nfs4_proc_bind_conn_to_session() |
| 5200 | * |
| 5201 | * The 4.1 client currently uses the same TCP connection for the |
| 5202 | * fore and backchannel. |
| 5203 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5204 | 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] | 5205 | { |
| 5206 | int status; |
| 5207 | struct nfs41_bind_conn_to_session_res res; |
| 5208 | struct rpc_message msg = { |
| 5209 | .rpc_proc = |
| 5210 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5211 | .rpc_argp = clp, |
| 5212 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5213 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5214 | }; |
| 5215 | |
| 5216 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5217 | |
| 5218 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5219 | if (unlikely(res.session == NULL)) { |
| 5220 | status = -ENOMEM; |
| 5221 | goto out; |
| 5222 | } |
| 5223 | |
| 5224 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5225 | if (status == 0) { |
| 5226 | if (memcmp(res.session->sess_id.data, |
| 5227 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5228 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5229 | status = -EIO; |
| 5230 | goto out_session; |
| 5231 | } |
| 5232 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5233 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5234 | __func__); |
| 5235 | status = -EIO; |
| 5236 | goto out_session; |
| 5237 | } |
| 5238 | if (res.use_conn_in_rdma_mode) { |
| 5239 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5240 | __func__); |
| 5241 | status = -EIO; |
| 5242 | goto out_session; |
| 5243 | } |
| 5244 | } |
| 5245 | out_session: |
| 5246 | kfree(res.session); |
| 5247 | out: |
| 5248 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5249 | return status; |
| 5250 | } |
| 5251 | |
| 5252 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5253 | * nfs4_proc_exchange_id() |
| 5254 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5255 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5256 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5257 | * Since the clientid has expired, all compounds using sessions |
| 5258 | * associated with the stale clientid will be returning |
| 5259 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5260 | * be in some phase of session reset. |
| 5261 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5262 | 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] | 5263 | { |
| 5264 | nfs4_verifier verifier; |
| 5265 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5266 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5267 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5268 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5269 | }; |
| 5270 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5271 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5272 | }; |
| 5273 | int status; |
| 5274 | struct rpc_message msg = { |
| 5275 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5276 | .rpc_argp = &args, |
| 5277 | .rpc_resp = &res, |
| 5278 | .rpc_cred = cred, |
| 5279 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5280 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5281 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5282 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5283 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5284 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5285 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5286 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5287 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5288 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5289 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5290 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5291 | status = -ENOMEM; |
| 5292 | goto out; |
| 5293 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5294 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5295 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5296 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5297 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5298 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5299 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5300 | } |
| 5301 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5302 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5303 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5304 | status = -ENOMEM; |
| 5305 | goto out_server_scope; |
| 5306 | } |
| 5307 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5308 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5309 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5310 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5311 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5312 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5313 | clp->cl_clientid = res.clientid; |
| 5314 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5315 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5316 | clp->cl_seqid = res.seqid; |
| 5317 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5318 | kfree(clp->cl_serverowner); |
| 5319 | clp->cl_serverowner = res.server_owner; |
| 5320 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5321 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5322 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5323 | kfree(clp->cl_implid); |
| 5324 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5325 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5326 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5327 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5328 | res.server_scope)) { |
| 5329 | dprintk("%s: server_scope mismatch detected\n", |
| 5330 | __func__); |
| 5331 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5332 | kfree(clp->cl_serverscope); |
| 5333 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5334 | } |
| 5335 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5336 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5337 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5338 | goto out; |
| 5339 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5340 | } else |
| 5341 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5342 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5343 | out_server_owner: |
| 5344 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5345 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5346 | kfree(res.server_scope); |
| 5347 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5348 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5349 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5350 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5351 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5352 | clp->cl_implid->date.seconds, |
| 5353 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5354 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5355 | return status; |
| 5356 | } |
| 5357 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5358 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5359 | struct rpc_cred *cred) |
| 5360 | { |
| 5361 | struct rpc_message msg = { |
| 5362 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5363 | .rpc_argp = clp, |
| 5364 | .rpc_cred = cred, |
| 5365 | }; |
| 5366 | int status; |
| 5367 | |
| 5368 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5369 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5370 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5371 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5372 | return status; |
| 5373 | } |
| 5374 | |
| 5375 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5376 | struct rpc_cred *cred) |
| 5377 | { |
| 5378 | unsigned int loop; |
| 5379 | int ret; |
| 5380 | |
| 5381 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5382 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5383 | switch (ret) { |
| 5384 | case -NFS4ERR_DELAY: |
| 5385 | case -NFS4ERR_CLIENTID_BUSY: |
| 5386 | ssleep(1); |
| 5387 | break; |
| 5388 | default: |
| 5389 | return ret; |
| 5390 | } |
| 5391 | } |
| 5392 | return 0; |
| 5393 | } |
| 5394 | |
| 5395 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5396 | { |
| 5397 | struct rpc_cred *cred; |
| 5398 | int ret = 0; |
| 5399 | |
| 5400 | if (clp->cl_mvops->minor_version < 1) |
| 5401 | goto out; |
| 5402 | if (clp->cl_exchange_flags == 0) |
| 5403 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5404 | if (clp->cl_preserve_clid) |
| 5405 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5406 | cred = nfs4_get_exchange_id_cred(clp); |
| 5407 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5408 | if (cred) |
| 5409 | put_rpccred(cred); |
| 5410 | switch (ret) { |
| 5411 | case 0: |
| 5412 | case -NFS4ERR_STALE_CLIENTID: |
| 5413 | clp->cl_exchange_flags = 0; |
| 5414 | } |
| 5415 | out: |
| 5416 | return ret; |
| 5417 | } |
| 5418 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5419 | struct nfs4_get_lease_time_data { |
| 5420 | struct nfs4_get_lease_time_args *args; |
| 5421 | struct nfs4_get_lease_time_res *res; |
| 5422 | struct nfs_client *clp; |
| 5423 | }; |
| 5424 | |
| 5425 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5426 | void *calldata) |
| 5427 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5428 | struct nfs4_get_lease_time_data *data = |
| 5429 | (struct nfs4_get_lease_time_data *)calldata; |
| 5430 | |
| 5431 | dprintk("--> %s\n", __func__); |
| 5432 | /* just setup sequence, do not trigger session recovery |
| 5433 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5434 | nfs41_setup_sequence(data->clp->cl_session, |
| 5435 | &data->args->la_seq_args, |
| 5436 | &data->res->lr_seq_res, |
| 5437 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5438 | dprintk("<-- %s\n", __func__); |
| 5439 | } |
| 5440 | |
| 5441 | /* |
| 5442 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5443 | * from sequence operation or clientid errors. |
| 5444 | */ |
| 5445 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5446 | { |
| 5447 | struct nfs4_get_lease_time_data *data = |
| 5448 | (struct nfs4_get_lease_time_data *)calldata; |
| 5449 | |
| 5450 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5451 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5452 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5453 | switch (task->tk_status) { |
| 5454 | case -NFS4ERR_DELAY: |
| 5455 | case -NFS4ERR_GRACE: |
| 5456 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5457 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5458 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5459 | /* fall through */ |
| 5460 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5461 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5462 | return; |
| 5463 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5464 | dprintk("<-- %s\n", __func__); |
| 5465 | } |
| 5466 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5467 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5468 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5469 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5470 | }; |
| 5471 | |
| 5472 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5473 | { |
| 5474 | struct rpc_task *task; |
| 5475 | struct nfs4_get_lease_time_args args; |
| 5476 | struct nfs4_get_lease_time_res res = { |
| 5477 | .lr_fsinfo = fsinfo, |
| 5478 | }; |
| 5479 | struct nfs4_get_lease_time_data data = { |
| 5480 | .args = &args, |
| 5481 | .res = &res, |
| 5482 | .clp = clp, |
| 5483 | }; |
| 5484 | struct rpc_message msg = { |
| 5485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5486 | .rpc_argp = &args, |
| 5487 | .rpc_resp = &res, |
| 5488 | }; |
| 5489 | struct rpc_task_setup task_setup = { |
| 5490 | .rpc_client = clp->cl_rpcclient, |
| 5491 | .rpc_message = &msg, |
| 5492 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5493 | .callback_data = &data, |
| 5494 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5495 | }; |
| 5496 | int status; |
| 5497 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5498 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5499 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5500 | dprintk("--> %s\n", __func__); |
| 5501 | task = rpc_run_task(&task_setup); |
| 5502 | |
| 5503 | if (IS_ERR(task)) |
| 5504 | status = PTR_ERR(task); |
| 5505 | else { |
| 5506 | status = task->tk_status; |
| 5507 | rpc_put_task(task); |
| 5508 | } |
| 5509 | dprintk("<-- %s return %d\n", __func__, status); |
| 5510 | |
| 5511 | return status; |
| 5512 | } |
| 5513 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5514 | /* |
| 5515 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5516 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5517 | * use them. |
| 5518 | * |
| 5519 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5520 | * always set csa_cachethis to FALSE because the current implementation |
| 5521 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5522 | */ |
| 5523 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5524 | { |
| 5525 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5526 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5527 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5528 | |
| 5529 | if (mxrqst_sz == 0) |
| 5530 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5531 | if (mxresp_sz == 0) |
| 5532 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5533 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5534 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5535 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5536 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5537 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5538 | |
| 5539 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5540 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5541 | __func__, |
| 5542 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5543 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5544 | |
| 5545 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5546 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5547 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5548 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5549 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5550 | args->bc_attrs.max_reqs = 1; |
| 5551 | |
| 5552 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5553 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5554 | __func__, |
| 5555 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5556 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5557 | args->bc_attrs.max_reqs); |
| 5558 | } |
| 5559 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5560 | 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] | 5561 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5562 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5563 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5564 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5565 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5566 | return -EINVAL; |
| 5567 | /* |
| 5568 | * Our requested max_ops is the minimum we need; we're not |
| 5569 | * prepared to break up compounds into smaller pieces than that. |
| 5570 | * So, no point even trying to continue if the server won't |
| 5571 | * cooperate: |
| 5572 | */ |
| 5573 | if (rcvd->max_ops < sent->max_ops) |
| 5574 | return -EINVAL; |
| 5575 | if (rcvd->max_reqs == 0) |
| 5576 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5577 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5578 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5579 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5580 | } |
| 5581 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5582 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5583 | { |
| 5584 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5585 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5586 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5587 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5588 | return -EINVAL; |
| 5589 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5590 | return -EINVAL; |
| 5591 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5592 | return -EINVAL; |
| 5593 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5594 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5595 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5596 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5597 | return -EINVAL; |
| 5598 | return 0; |
| 5599 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5600 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5601 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5602 | struct nfs4_session *session) |
| 5603 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5604 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5605 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5606 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5607 | if (ret) |
| 5608 | return ret; |
| 5609 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5610 | } |
| 5611 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5612 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5613 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5614 | { |
| 5615 | struct nfs4_session *session = clp->cl_session; |
| 5616 | struct nfs41_create_session_args args = { |
| 5617 | .client = clp, |
| 5618 | .cb_program = NFS4_CALLBACK, |
| 5619 | }; |
| 5620 | struct nfs41_create_session_res res = { |
| 5621 | .client = clp, |
| 5622 | }; |
| 5623 | struct rpc_message msg = { |
| 5624 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5625 | .rpc_argp = &args, |
| 5626 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5627 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5628 | }; |
| 5629 | int status; |
| 5630 | |
| 5631 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5632 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5633 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5634 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5635 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5636 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5637 | /* Verify the session's negotiated channel_attrs values */ |
| 5638 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5639 | /* Increment the clientid slot sequence id */ |
| 5640 | clp->cl_seqid++; |
| 5641 | } |
| 5642 | |
| 5643 | return status; |
| 5644 | } |
| 5645 | |
| 5646 | /* |
| 5647 | * Issues a CREATE_SESSION operation to the server. |
| 5648 | * It is the responsibility of the caller to verify the session is |
| 5649 | * expired before calling this routine. |
| 5650 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5651 | 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] | 5652 | { |
| 5653 | int status; |
| 5654 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5655 | struct nfs4_session *session = clp->cl_session; |
| 5656 | |
| 5657 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5658 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5659 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5660 | if (status) |
| 5661 | goto out; |
| 5662 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5663 | /* Init or reset the session slot tables */ |
| 5664 | status = nfs4_setup_session_slot_tables(session); |
| 5665 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5666 | if (status) |
| 5667 | goto out; |
| 5668 | |
| 5669 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5670 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5671 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5672 | out: |
| 5673 | dprintk("<-- %s\n", __func__); |
| 5674 | return status; |
| 5675 | } |
| 5676 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5677 | /* |
| 5678 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5679 | * The caller must serialize access to this routine. |
| 5680 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5681 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5682 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5683 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5684 | struct rpc_message msg = { |
| 5685 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5686 | .rpc_argp = session, |
| 5687 | .rpc_cred = cred, |
| 5688 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5689 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5690 | |
| 5691 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5692 | |
| 5693 | /* session is still being setup */ |
| 5694 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5695 | return status; |
| 5696 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5697 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5698 | |
| 5699 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5700 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5701 | "Session has been destroyed regardless...\n", status); |
| 5702 | |
| 5703 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5704 | return status; |
| 5705 | } |
| 5706 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5707 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5708 | * Renew the cl_session lease. |
| 5709 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5710 | struct nfs4_sequence_data { |
| 5711 | struct nfs_client *clp; |
| 5712 | struct nfs4_sequence_args args; |
| 5713 | struct nfs4_sequence_res res; |
| 5714 | }; |
| 5715 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5716 | static void nfs41_sequence_release(void *data) |
| 5717 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5718 | struct nfs4_sequence_data *calldata = data; |
| 5719 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5720 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5721 | if (atomic_read(&clp->cl_count) > 1) |
| 5722 | nfs4_schedule_state_renewal(clp); |
| 5723 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5724 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5725 | } |
| 5726 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5727 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5728 | { |
| 5729 | switch(task->tk_status) { |
| 5730 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5731 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5732 | return -EAGAIN; |
| 5733 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5734 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5735 | } |
| 5736 | return 0; |
| 5737 | } |
| 5738 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5739 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5740 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5741 | struct nfs4_sequence_data *calldata = data; |
| 5742 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5743 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5744 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5745 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5746 | |
| 5747 | if (task->tk_status < 0) { |
| 5748 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5749 | if (atomic_read(&clp->cl_count) == 1) |
| 5750 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5751 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5752 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5753 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5754 | return; |
| 5755 | } |
| 5756 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5757 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5758 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5759 | dprintk("<-- %s\n", __func__); |
| 5760 | } |
| 5761 | |
| 5762 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5763 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5764 | struct nfs4_sequence_data *calldata = data; |
| 5765 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5766 | struct nfs4_sequence_args *args; |
| 5767 | struct nfs4_sequence_res *res; |
| 5768 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5769 | args = task->tk_msg.rpc_argp; |
| 5770 | res = task->tk_msg.rpc_resp; |
| 5771 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5772 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5776 | .rpc_call_done = nfs41_sequence_call_done, |
| 5777 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5778 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5779 | }; |
| 5780 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5781 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5782 | struct rpc_cred *cred, |
| 5783 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5784 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5785 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5786 | struct rpc_message msg = { |
| 5787 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5788 | .rpc_cred = cred, |
| 5789 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5790 | struct rpc_task_setup task_setup_data = { |
| 5791 | .rpc_client = clp->cl_rpcclient, |
| 5792 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5793 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5794 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5795 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5796 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5797 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5798 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5799 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5800 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5801 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5802 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5803 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5804 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5805 | if (is_privileged) |
| 5806 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5807 | msg.rpc_argp = &calldata->args; |
| 5808 | msg.rpc_resp = &calldata->res; |
| 5809 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5810 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5811 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5812 | return rpc_run_task(&task_setup_data); |
| 5813 | } |
| 5814 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5815 | 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] | 5816 | { |
| 5817 | struct rpc_task *task; |
| 5818 | int ret = 0; |
| 5819 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5820 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5821 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5822 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5823 | if (IS_ERR(task)) |
| 5824 | ret = PTR_ERR(task); |
| 5825 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5826 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5827 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5828 | return ret; |
| 5829 | } |
| 5830 | |
| 5831 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5832 | { |
| 5833 | struct rpc_task *task; |
| 5834 | int ret; |
| 5835 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5836 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5837 | if (IS_ERR(task)) { |
| 5838 | ret = PTR_ERR(task); |
| 5839 | goto out; |
| 5840 | } |
| 5841 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5842 | if (!ret) { |
| 5843 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5844 | |
| 5845 | if (task->tk_status == 0) |
| 5846 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5847 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5848 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5849 | rpc_put_task(task); |
| 5850 | out: |
| 5851 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5852 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5853 | } |
| 5854 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5855 | struct nfs4_reclaim_complete_data { |
| 5856 | struct nfs_client *clp; |
| 5857 | struct nfs41_reclaim_complete_args arg; |
| 5858 | struct nfs41_reclaim_complete_res res; |
| 5859 | }; |
| 5860 | |
| 5861 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5862 | { |
| 5863 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5864 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5865 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 5866 | &calldata->arg.seq_args, |
| 5867 | &calldata->res.seq_res, |
| 5868 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5869 | } |
| 5870 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5871 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5872 | { |
| 5873 | switch(task->tk_status) { |
| 5874 | case 0: |
| 5875 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5876 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5877 | break; |
| 5878 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5879 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5880 | /* fall through */ |
| 5881 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5882 | return -EAGAIN; |
| 5883 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5884 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5885 | } |
| 5886 | return 0; |
| 5887 | } |
| 5888 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5889 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5890 | { |
| 5891 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5892 | struct nfs_client *clp = calldata->clp; |
| 5893 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5894 | |
| 5895 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5896 | if (!nfs41_sequence_done(task, res)) |
| 5897 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5898 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5899 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5900 | rpc_restart_call_prepare(task); |
| 5901 | return; |
| 5902 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5903 | dprintk("<-- %s\n", __func__); |
| 5904 | } |
| 5905 | |
| 5906 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5907 | { |
| 5908 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5909 | |
| 5910 | kfree(calldata); |
| 5911 | } |
| 5912 | |
| 5913 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5914 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5915 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5916 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5917 | }; |
| 5918 | |
| 5919 | /* |
| 5920 | * Issue a global reclaim complete. |
| 5921 | */ |
| 5922 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5923 | { |
| 5924 | struct nfs4_reclaim_complete_data *calldata; |
| 5925 | struct rpc_task *task; |
| 5926 | struct rpc_message msg = { |
| 5927 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5928 | }; |
| 5929 | struct rpc_task_setup task_setup_data = { |
| 5930 | .rpc_client = clp->cl_rpcclient, |
| 5931 | .rpc_message = &msg, |
| 5932 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5933 | .flags = RPC_TASK_ASYNC, |
| 5934 | }; |
| 5935 | int status = -ENOMEM; |
| 5936 | |
| 5937 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5938 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5939 | if (calldata == NULL) |
| 5940 | goto out; |
| 5941 | calldata->clp = clp; |
| 5942 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5943 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5944 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5945 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5946 | msg.rpc_argp = &calldata->arg; |
| 5947 | msg.rpc_resp = &calldata->res; |
| 5948 | task_setup_data.callback_data = calldata; |
| 5949 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5950 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5951 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5952 | goto out; |
| 5953 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5954 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5955 | if (status == 0) |
| 5956 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5957 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5958 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5959 | out: |
| 5960 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5961 | return status; |
| 5962 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5963 | |
| 5964 | static void |
| 5965 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5966 | { |
| 5967 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5968 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 5969 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5970 | |
| 5971 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5972 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5973 | * right now covering the LAYOUTGET we are about to send. |
| 5974 | * However, that is not so catastrophic, and there seems |
| 5975 | * to be no way to prevent it completely. |
| 5976 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 5977 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5978 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5979 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5980 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5981 | NFS_I(lgp->args.inode)->layout, |
| 5982 | lgp->args.ctx->state)) { |
| 5983 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5984 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5988 | { |
| 5989 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 5990 | struct inode *inode = lgp->args.inode; |
| 5991 | struct nfs_server *server = NFS_SERVER(inode); |
| 5992 | struct pnfs_layout_hdr *lo; |
| 5993 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5994 | |
| 5995 | dprintk("--> %s\n", __func__); |
| 5996 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 5997 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 5998 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5999 | |
| 6000 | switch (task->tk_status) { |
| 6001 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6002 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6003 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6004 | case -NFS4ERR_RECALLCONFLICT: |
| 6005 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6006 | break; |
| 6007 | case -NFS4ERR_EXPIRED: |
| 6008 | case -NFS4ERR_BAD_STATEID: |
| 6009 | spin_lock(&inode->i_lock); |
| 6010 | lo = NFS_I(inode)->layout; |
| 6011 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6012 | spin_unlock(&inode->i_lock); |
| 6013 | /* If the open stateid was bad, then recover it. */ |
| 6014 | state = lgp->args.ctx->state; |
| 6015 | } else { |
| 6016 | LIST_HEAD(head); |
| 6017 | |
| 6018 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6019 | spin_unlock(&inode->i_lock); |
| 6020 | /* Mark the bad layout state as invalid, then |
| 6021 | * retry using the open stateid. */ |
| 6022 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6023 | } |
| 6024 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6025 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6026 | rpc_restart_call_prepare(task); |
| 6027 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6028 | dprintk("<-- %s\n", __func__); |
| 6029 | } |
| 6030 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6031 | static size_t max_response_pages(struct nfs_server *server) |
| 6032 | { |
| 6033 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6034 | return nfs_page_array_len(0, max_resp_sz); |
| 6035 | } |
| 6036 | |
| 6037 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6038 | { |
| 6039 | int i; |
| 6040 | |
| 6041 | if (!pages) |
| 6042 | return; |
| 6043 | |
| 6044 | for (i = 0; i < size; i++) { |
| 6045 | if (!pages[i]) |
| 6046 | break; |
| 6047 | __free_page(pages[i]); |
| 6048 | } |
| 6049 | kfree(pages); |
| 6050 | } |
| 6051 | |
| 6052 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6053 | { |
| 6054 | struct page **pages; |
| 6055 | int i; |
| 6056 | |
| 6057 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6058 | if (!pages) { |
| 6059 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6060 | return NULL; |
| 6061 | } |
| 6062 | |
| 6063 | for (i = 0; i < size; i++) { |
| 6064 | pages[i] = alloc_page(gfp_flags); |
| 6065 | if (!pages[i]) { |
| 6066 | dprintk("%s: failed to allocate page\n", __func__); |
| 6067 | nfs4_free_pages(pages, size); |
| 6068 | return NULL; |
| 6069 | } |
| 6070 | } |
| 6071 | |
| 6072 | return pages; |
| 6073 | } |
| 6074 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6075 | static void nfs4_layoutget_release(void *calldata) |
| 6076 | { |
| 6077 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6078 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6079 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6080 | |
| 6081 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6082 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6083 | put_nfs_open_context(lgp->args.ctx); |
| 6084 | kfree(calldata); |
| 6085 | dprintk("<-- %s\n", __func__); |
| 6086 | } |
| 6087 | |
| 6088 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6089 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6090 | .rpc_call_done = nfs4_layoutget_done, |
| 6091 | .rpc_release = nfs4_layoutget_release, |
| 6092 | }; |
| 6093 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6094 | struct pnfs_layout_segment * |
| 6095 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6096 | { |
| 6097 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6098 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6099 | struct rpc_task *task; |
| 6100 | struct rpc_message msg = { |
| 6101 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6102 | .rpc_argp = &lgp->args, |
| 6103 | .rpc_resp = &lgp->res, |
| 6104 | }; |
| 6105 | struct rpc_task_setup task_setup_data = { |
| 6106 | .rpc_client = server->client, |
| 6107 | .rpc_message = &msg, |
| 6108 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6109 | .callback_data = lgp, |
| 6110 | .flags = RPC_TASK_ASYNC, |
| 6111 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6112 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6113 | int status = 0; |
| 6114 | |
| 6115 | dprintk("--> %s\n", __func__); |
| 6116 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6117 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6118 | if (!lgp->args.layout.pages) { |
| 6119 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6120 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6121 | } |
| 6122 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6123 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6124 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6125 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6126 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6127 | task = rpc_run_task(&task_setup_data); |
| 6128 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6129 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6130 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6131 | if (status == 0) |
| 6132 | status = task->tk_status; |
| 6133 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6134 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6135 | rpc_put_task(task); |
| 6136 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6137 | if (status) |
| 6138 | return ERR_PTR(status); |
| 6139 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6140 | } |
| 6141 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6142 | static void |
| 6143 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6144 | { |
| 6145 | struct nfs4_layoutreturn *lrp = calldata; |
| 6146 | |
| 6147 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6148 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6149 | &lrp->args.seq_args, |
| 6150 | &lrp->res.seq_res, |
| 6151 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6155 | { |
| 6156 | struct nfs4_layoutreturn *lrp = calldata; |
| 6157 | struct nfs_server *server; |
| 6158 | |
| 6159 | dprintk("--> %s\n", __func__); |
| 6160 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6161 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6162 | return; |
| 6163 | |
| 6164 | server = NFS_SERVER(lrp->args.inode); |
| 6165 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6166 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6167 | return; |
| 6168 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6169 | dprintk("<-- %s\n", __func__); |
| 6170 | } |
| 6171 | |
| 6172 | static void nfs4_layoutreturn_release(void *calldata) |
| 6173 | { |
| 6174 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6175 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6176 | |
| 6177 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6178 | spin_lock(&lo->plh_inode->i_lock); |
| 6179 | if (lrp->res.lrs_present) |
| 6180 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6181 | lo->plh_block_lgets--; |
| 6182 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6183 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6184 | kfree(calldata); |
| 6185 | dprintk("<-- %s\n", __func__); |
| 6186 | } |
| 6187 | |
| 6188 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6189 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6190 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6191 | .rpc_release = nfs4_layoutreturn_release, |
| 6192 | }; |
| 6193 | |
| 6194 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6195 | { |
| 6196 | struct rpc_task *task; |
| 6197 | struct rpc_message msg = { |
| 6198 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6199 | .rpc_argp = &lrp->args, |
| 6200 | .rpc_resp = &lrp->res, |
| 6201 | }; |
| 6202 | struct rpc_task_setup task_setup_data = { |
| 6203 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6204 | .rpc_message = &msg, |
| 6205 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6206 | .callback_data = lrp, |
| 6207 | }; |
| 6208 | int status; |
| 6209 | |
| 6210 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6211 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6212 | task = rpc_run_task(&task_setup_data); |
| 6213 | if (IS_ERR(task)) |
| 6214 | return PTR_ERR(task); |
| 6215 | status = task->tk_status; |
| 6216 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6217 | rpc_put_task(task); |
| 6218 | return status; |
| 6219 | } |
| 6220 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6221 | /* |
| 6222 | * Retrieve the list of Data Server devices from the MDS. |
| 6223 | */ |
| 6224 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6225 | const struct nfs_fh *fh, |
| 6226 | struct pnfs_devicelist *devlist) |
| 6227 | { |
| 6228 | struct nfs4_getdevicelist_args args = { |
| 6229 | .fh = fh, |
| 6230 | .layoutclass = server->pnfs_curr_ld->id, |
| 6231 | }; |
| 6232 | struct nfs4_getdevicelist_res res = { |
| 6233 | .devlist = devlist, |
| 6234 | }; |
| 6235 | struct rpc_message msg = { |
| 6236 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6237 | .rpc_argp = &args, |
| 6238 | .rpc_resp = &res, |
| 6239 | }; |
| 6240 | int status; |
| 6241 | |
| 6242 | dprintk("--> %s\n", __func__); |
| 6243 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6244 | &res.seq_res, 0); |
| 6245 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6246 | return status; |
| 6247 | } |
| 6248 | |
| 6249 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6250 | const struct nfs_fh *fh, |
| 6251 | struct pnfs_devicelist *devlist) |
| 6252 | { |
| 6253 | struct nfs4_exception exception = { }; |
| 6254 | int err; |
| 6255 | |
| 6256 | do { |
| 6257 | err = nfs4_handle_exception(server, |
| 6258 | _nfs4_getdevicelist(server, fh, devlist), |
| 6259 | &exception); |
| 6260 | } while (exception.retry); |
| 6261 | |
| 6262 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6263 | err, devlist->num_devs); |
| 6264 | |
| 6265 | return err; |
| 6266 | } |
| 6267 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6268 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6269 | static int |
| 6270 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6271 | { |
| 6272 | struct nfs4_getdeviceinfo_args args = { |
| 6273 | .pdev = pdev, |
| 6274 | }; |
| 6275 | struct nfs4_getdeviceinfo_res res = { |
| 6276 | .pdev = pdev, |
| 6277 | }; |
| 6278 | struct rpc_message msg = { |
| 6279 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6280 | .rpc_argp = &args, |
| 6281 | .rpc_resp = &res, |
| 6282 | }; |
| 6283 | int status; |
| 6284 | |
| 6285 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6286 | 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] | 6287 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6288 | |
| 6289 | return status; |
| 6290 | } |
| 6291 | |
| 6292 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6293 | { |
| 6294 | struct nfs4_exception exception = { }; |
| 6295 | int err; |
| 6296 | |
| 6297 | do { |
| 6298 | err = nfs4_handle_exception(server, |
| 6299 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6300 | &exception); |
| 6301 | } while (exception.retry); |
| 6302 | return err; |
| 6303 | } |
| 6304 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6305 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6306 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6307 | { |
| 6308 | struct nfs4_layoutcommit_data *data = calldata; |
| 6309 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6310 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6311 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6312 | nfs41_setup_sequence(session, |
| 6313 | &data->args.seq_args, |
| 6314 | &data->res.seq_res, |
| 6315 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | static void |
| 6319 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6320 | { |
| 6321 | struct nfs4_layoutcommit_data *data = calldata; |
| 6322 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6323 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6324 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6325 | return; |
| 6326 | |
| 6327 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6328 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6329 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6330 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6331 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6332 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6333 | break; |
| 6334 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6335 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6336 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6337 | break; |
| 6338 | default: |
| 6339 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6340 | rpc_restart_call_prepare(task); |
| 6341 | return; |
| 6342 | } |
| 6343 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6344 | } |
| 6345 | |
| 6346 | static void nfs4_layoutcommit_release(void *calldata) |
| 6347 | { |
| 6348 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6349 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6350 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6351 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6352 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6353 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6354 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6355 | list_del_init(&lseg->pls_lc_list); |
| 6356 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6357 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6358 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6359 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6360 | |
| 6361 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6362 | smp_mb__after_clear_bit(); |
| 6363 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6364 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6365 | put_rpccred(data->cred); |
| 6366 | kfree(data); |
| 6367 | } |
| 6368 | |
| 6369 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6370 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6371 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6372 | .rpc_release = nfs4_layoutcommit_release, |
| 6373 | }; |
| 6374 | |
| 6375 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6376 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6377 | { |
| 6378 | struct rpc_message msg = { |
| 6379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6380 | .rpc_argp = &data->args, |
| 6381 | .rpc_resp = &data->res, |
| 6382 | .rpc_cred = data->cred, |
| 6383 | }; |
| 6384 | struct rpc_task_setup task_setup_data = { |
| 6385 | .task = &data->task, |
| 6386 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6387 | .rpc_message = &msg, |
| 6388 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6389 | .callback_data = data, |
| 6390 | .flags = RPC_TASK_ASYNC, |
| 6391 | }; |
| 6392 | struct rpc_task *task; |
| 6393 | int status = 0; |
| 6394 | |
| 6395 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6396 | "lbw: %llu inode %lu\n", |
| 6397 | data->task.tk_pid, sync, |
| 6398 | data->args.lastbytewritten, |
| 6399 | data->args.inode->i_ino); |
| 6400 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6401 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6402 | task = rpc_run_task(&task_setup_data); |
| 6403 | if (IS_ERR(task)) |
| 6404 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6405 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6406 | goto out; |
| 6407 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6408 | if (status != 0) |
| 6409 | goto out; |
| 6410 | status = task->tk_status; |
| 6411 | out: |
| 6412 | dprintk("%s: status %d\n", __func__, status); |
| 6413 | rpc_put_task(task); |
| 6414 | return status; |
| 6415 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6416 | |
| 6417 | static int |
| 6418 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6419 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6420 | { |
| 6421 | struct nfs41_secinfo_no_name_args args = { |
| 6422 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6423 | }; |
| 6424 | struct nfs4_secinfo_res res = { |
| 6425 | .flavors = flavors, |
| 6426 | }; |
| 6427 | struct rpc_message msg = { |
| 6428 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6429 | .rpc_argp = &args, |
| 6430 | .rpc_resp = &res, |
| 6431 | }; |
| 6432 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6433 | } |
| 6434 | |
| 6435 | static int |
| 6436 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6437 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6438 | { |
| 6439 | struct nfs4_exception exception = { }; |
| 6440 | int err; |
| 6441 | do { |
| 6442 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6443 | switch (err) { |
| 6444 | case 0: |
| 6445 | case -NFS4ERR_WRONGSEC: |
| 6446 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6447 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6448 | default: |
| 6449 | err = nfs4_handle_exception(server, err, &exception); |
| 6450 | } |
| 6451 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6452 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6453 | return err; |
| 6454 | } |
| 6455 | |
| 6456 | static int |
| 6457 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6458 | struct nfs_fsinfo *info) |
| 6459 | { |
| 6460 | int err; |
| 6461 | struct page *page; |
| 6462 | rpc_authflavor_t flavor; |
| 6463 | struct nfs4_secinfo_flavors *flavors; |
| 6464 | |
| 6465 | page = alloc_page(GFP_KERNEL); |
| 6466 | if (!page) { |
| 6467 | err = -ENOMEM; |
| 6468 | goto out; |
| 6469 | } |
| 6470 | |
| 6471 | flavors = page_address(page); |
| 6472 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6473 | |
| 6474 | /* |
| 6475 | * Fall back on "guess and check" method if |
| 6476 | * the server doesn't support SECINFO_NO_NAME |
| 6477 | */ |
| 6478 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6479 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6480 | goto out_freepage; |
| 6481 | } |
| 6482 | if (err) |
| 6483 | goto out_freepage; |
| 6484 | |
| 6485 | flavor = nfs_find_best_sec(flavors); |
| 6486 | if (err == 0) |
| 6487 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6488 | |
| 6489 | out_freepage: |
| 6490 | put_page(page); |
| 6491 | if (err == -EACCES) |
| 6492 | return -EPERM; |
| 6493 | out: |
| 6494 | return err; |
| 6495 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6496 | |
| 6497 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6498 | { |
| 6499 | int status; |
| 6500 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6501 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6502 | }; |
| 6503 | struct nfs41_test_stateid_res res; |
| 6504 | struct rpc_message msg = { |
| 6505 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6506 | .rpc_argp = &args, |
| 6507 | .rpc_resp = &res, |
| 6508 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6509 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6510 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6511 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6512 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6513 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6514 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6515 | if (status != NFS_OK) { |
| 6516 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6517 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6518 | } |
| 6519 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6520 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6521 | } |
| 6522 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6523 | /** |
| 6524 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6525 | * |
| 6526 | * @server: server / transport on which to perform the operation |
| 6527 | * @stateid: state ID to test |
| 6528 | * |
| 6529 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6530 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6531 | * failed or the state ID is not currently valid. |
| 6532 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6533 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6534 | { |
| 6535 | struct nfs4_exception exception = { }; |
| 6536 | int err; |
| 6537 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6538 | err = _nfs41_test_stateid(server, stateid); |
| 6539 | if (err != -NFS4ERR_DELAY) |
| 6540 | break; |
| 6541 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6542 | } while (exception.retry); |
| 6543 | return err; |
| 6544 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6545 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6546 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6547 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6548 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6549 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6550 | }; |
| 6551 | struct nfs41_free_stateid_res res; |
| 6552 | struct rpc_message msg = { |
| 6553 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6554 | .rpc_argp = &args, |
| 6555 | .rpc_resp = &res, |
| 6556 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6557 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6558 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6559 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6560 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6561 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6562 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6563 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6564 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6565 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6566 | } |
| 6567 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6568 | /** |
| 6569 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6570 | * |
| 6571 | * @server: server / transport on which to perform the operation |
| 6572 | * @stateid: state ID to release |
| 6573 | * |
| 6574 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6575 | * negative NFS4ERR value is returned. |
| 6576 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6577 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6578 | { |
| 6579 | struct nfs4_exception exception = { }; |
| 6580 | int err; |
| 6581 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6582 | err = _nfs4_free_stateid(server, stateid); |
| 6583 | if (err != -NFS4ERR_DELAY) |
| 6584 | break; |
| 6585 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6586 | } while (exception.retry); |
| 6587 | return err; |
| 6588 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6589 | |
| 6590 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6591 | const nfs4_stateid *s2) |
| 6592 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6593 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6594 | return false; |
| 6595 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6596 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6597 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6598 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6599 | return true; |
| 6600 | |
| 6601 | return false; |
| 6602 | } |
| 6603 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6604 | #endif /* CONFIG_NFS_V4_1 */ |
| 6605 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6606 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6607 | const nfs4_stateid *s2) |
| 6608 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6609 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6610 | } |
| 6611 | |
| 6612 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6613 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6614 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6615 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6616 | .recover_open = nfs4_open_reclaim, |
| 6617 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6618 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6619 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6620 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | }; |
| 6622 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6623 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6624 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6625 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6626 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6627 | .recover_open = nfs4_open_reclaim, |
| 6628 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6629 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6630 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6631 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6632 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6633 | }; |
| 6634 | #endif /* CONFIG_NFS_V4_1 */ |
| 6635 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6636 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6637 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6638 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6639 | .recover_open = nfs4_open_expired, |
| 6640 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6641 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6642 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6643 | }; |
| 6644 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6645 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6646 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6647 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6648 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6649 | .recover_open = nfs41_open_expired, |
| 6650 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6651 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6652 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6653 | }; |
| 6654 | #endif /* CONFIG_NFS_V4_1 */ |
| 6655 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6656 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6657 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6658 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6659 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6660 | }; |
| 6661 | |
| 6662 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6663 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6664 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6665 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6666 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6667 | }; |
| 6668 | #endif |
| 6669 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6670 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6671 | .minor_version = 0, |
| 6672 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6673 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6674 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6675 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6676 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6677 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6678 | }; |
| 6679 | |
| 6680 | #if defined(CONFIG_NFS_V4_1) |
| 6681 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6682 | .minor_version = 1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6683 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6684 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6685 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6686 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6687 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6688 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6689 | }; |
| 6690 | #endif |
| 6691 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6692 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6693 | [0] = &nfs_v4_0_minor_ops, |
| 6694 | #if defined(CONFIG_NFS_V4_1) |
| 6695 | [1] = &nfs_v4_1_minor_ops, |
| 6696 | #endif |
| 6697 | }; |
| 6698 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6699 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6700 | .create = nfs_create, |
| 6701 | .lookup = nfs_lookup, |
| 6702 | .atomic_open = nfs_atomic_open, |
| 6703 | .link = nfs_link, |
| 6704 | .unlink = nfs_unlink, |
| 6705 | .symlink = nfs_symlink, |
| 6706 | .mkdir = nfs_mkdir, |
| 6707 | .rmdir = nfs_rmdir, |
| 6708 | .mknod = nfs_mknod, |
| 6709 | .rename = nfs_rename, |
| 6710 | .permission = nfs_permission, |
| 6711 | .getattr = nfs_getattr, |
| 6712 | .setattr = nfs_setattr, |
| 6713 | .getxattr = generic_getxattr, |
| 6714 | .setxattr = generic_setxattr, |
| 6715 | .listxattr = generic_listxattr, |
| 6716 | .removexattr = generic_removexattr, |
| 6717 | }; |
| 6718 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6719 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6720 | .permission = nfs_permission, |
| 6721 | .getattr = nfs_getattr, |
| 6722 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6723 | .getxattr = generic_getxattr, |
| 6724 | .setxattr = generic_setxattr, |
| 6725 | .listxattr = generic_listxattr, |
| 6726 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6727 | }; |
| 6728 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6729 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6730 | .version = 4, /* protocol version */ |
| 6731 | .dentry_ops = &nfs4_dentry_operations, |
| 6732 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6733 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6734 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6735 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6736 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6737 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6738 | .getattr = nfs4_proc_getattr, |
| 6739 | .setattr = nfs4_proc_setattr, |
| 6740 | .lookup = nfs4_proc_lookup, |
| 6741 | .access = nfs4_proc_access, |
| 6742 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6743 | .create = nfs4_proc_create, |
| 6744 | .remove = nfs4_proc_remove, |
| 6745 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6746 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6747 | .unlink_done = nfs4_proc_unlink_done, |
| 6748 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6749 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6750 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6751 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6752 | .link = nfs4_proc_link, |
| 6753 | .symlink = nfs4_proc_symlink, |
| 6754 | .mkdir = nfs4_proc_mkdir, |
| 6755 | .rmdir = nfs4_proc_remove, |
| 6756 | .readdir = nfs4_proc_readdir, |
| 6757 | .mknod = nfs4_proc_mknod, |
| 6758 | .statfs = nfs4_proc_statfs, |
| 6759 | .fsinfo = nfs4_proc_fsinfo, |
| 6760 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6761 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6762 | .decode_dirent = nfs4_decode_dirent, |
| 6763 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6764 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6765 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6766 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6767 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6768 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6769 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6770 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6771 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6772 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6773 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6774 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6775 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6776 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6777 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6778 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6779 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6780 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6781 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6782 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6783 | .create_server = nfs4_create_server, |
| 6784 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6785 | }; |
| 6786 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6787 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6788 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6789 | .list = nfs4_xattr_list_nfs4_acl, |
| 6790 | .get = nfs4_xattr_get_nfs4_acl, |
| 6791 | .set = nfs4_xattr_set_nfs4_acl, |
| 6792 | }; |
| 6793 | |
| 6794 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6795 | &nfs4_xattr_nfs4_acl_handler, |
| 6796 | NULL |
| 6797 | }; |
| 6798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6799 | /* |
| 6800 | * Local variables: |
| 6801 | * c-basic-offset: 8 |
| 6802 | * End: |
| 6803 | */ |