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, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1629 | struct nfs4_state *state, fmode_t fmode, |
| 1630 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1631 | { |
| 1632 | struct nfs_access_entry cache; |
| 1633 | u32 mask; |
| 1634 | |
| 1635 | /* access call failed or for some reason the server doesn't |
| 1636 | * support any access modes -- defer access call until later */ |
| 1637 | if (opendata->o_res.access_supported == 0) |
| 1638 | return 0; |
| 1639 | |
| 1640 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1641 | /* don't check MAY_WRITE - a newly created file may not have |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1642 | * write mode bits, but POSIX allows the creating process to write. |
| 1643 | * use openflags to check for exec, because fmode won't |
| 1644 | * always have FMODE_EXEC set when file open for exec. */ |
| 1645 | if (openflags & __FMODE_EXEC) { |
| 1646 | /* ONLY check for exec rights */ |
| 1647 | mask = MAY_EXEC; |
| 1648 | } else if (fmode & FMODE_READ) |
| 1649 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1650 | |
| 1651 | cache.cred = cred; |
| 1652 | cache.jiffies = jiffies; |
| 1653 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1654 | nfs_access_add_cache(state->inode, &cache); |
| 1655 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1656 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1657 | return 0; |
| 1658 | |
| 1659 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1660 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1661 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1662 | } |
| 1663 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1664 | /* |
| 1665 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1666 | */ |
| 1667 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1668 | { |
| 1669 | struct inode *dir = data->dir->d_inode; |
| 1670 | struct nfs_server *server = NFS_SERVER(dir); |
| 1671 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1672 | struct nfs_openres *o_res = &data->o_res; |
| 1673 | int status; |
| 1674 | |
| 1675 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1676 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1677 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1678 | if (status != 0) { |
| 1679 | if (status == -NFS4ERR_BADNAME && |
| 1680 | !(o_arg->open_flags & O_CREAT)) |
| 1681 | return -ENOENT; |
| 1682 | return status; |
| 1683 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1684 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1685 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1686 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1687 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1688 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1689 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1690 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1692 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1694 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | } |
| 1696 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1697 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1698 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1701 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1702 | { |
| 1703 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1704 | } |
| 1705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | /* |
| 1707 | * OPEN_EXPIRED: |
| 1708 | * reclaim state on the server after a network partition. |
| 1709 | * Assumes caller holds the appropriate lock |
| 1710 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1711 | 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] | 1712 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1713 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1714 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1716 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1717 | if (IS_ERR(opendata)) |
| 1718 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1719 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1720 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1721 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1722 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1723 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1726 | 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] | 1727 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1728 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1729 | struct nfs4_exception exception = { }; |
| 1730 | int err; |
| 1731 | |
| 1732 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1733 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1734 | switch (err) { |
| 1735 | default: |
| 1736 | goto out; |
| 1737 | case -NFS4ERR_GRACE: |
| 1738 | case -NFS4ERR_DELAY: |
| 1739 | nfs4_handle_exception(server, err, &exception); |
| 1740 | err = 0; |
| 1741 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1742 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1743 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1744 | return err; |
| 1745 | } |
| 1746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1748 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1750 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1752 | ctx = nfs4_state_find_open_context(state); |
| 1753 | if (IS_ERR(ctx)) |
| 1754 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1755 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1756 | put_nfs_open_context(ctx); |
| 1757 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1760 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1761 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1762 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1763 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1764 | nfs4_stateid *stateid = &state->stateid; |
| 1765 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1766 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1767 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1768 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1769 | return; |
| 1770 | |
| 1771 | status = nfs41_test_stateid(server, stateid); |
| 1772 | if (status != NFS_OK) { |
| 1773 | /* Free the stateid unless the server explicitly |
| 1774 | * informs us the stateid is unrecognized. */ |
| 1775 | if (status != -NFS4ERR_BAD_STATEID) |
| 1776 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1777 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1778 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1779 | write_seqlock(&state->seqlock); |
| 1780 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1781 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1782 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | /** |
| 1787 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1788 | * |
| 1789 | * @state: NFSv4 state for an inode |
| 1790 | * |
| 1791 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1792 | * Otherwise a negative NFS4ERR value is returned. |
| 1793 | */ |
| 1794 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1795 | { |
| 1796 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1797 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1798 | int status; |
| 1799 | |
| 1800 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1801 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1802 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1803 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1804 | return -NFS4ERR_BAD_STATEID; |
| 1805 | |
| 1806 | status = nfs41_test_stateid(server, stateid); |
| 1807 | if (status != NFS_OK) { |
| 1808 | /* Free the stateid unless the server explicitly |
| 1809 | * informs us the stateid is unrecognized. */ |
| 1810 | if (status != -NFS4ERR_BAD_STATEID) |
| 1811 | nfs41_free_stateid(server, stateid); |
| 1812 | |
| 1813 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1814 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1815 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1816 | } |
| 1817 | return status; |
| 1818 | } |
| 1819 | |
| 1820 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1821 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1822 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1823 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1824 | nfs41_clear_delegation_stateid(state); |
| 1825 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1826 | if (status != NFS_OK) |
| 1827 | status = nfs4_open_expired(sp, state); |
| 1828 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1829 | } |
| 1830 | #endif |
| 1831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1833 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1834 | * fields corresponding to attributes that were used to store the verifier. |
| 1835 | * Make sure we clobber those fields in the later setattr call |
| 1836 | */ |
| 1837 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1838 | { |
| 1839 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1840 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1841 | sattr->ia_valid |= ATTR_ATIME; |
| 1842 | |
| 1843 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1844 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1845 | sattr->ia_valid |= ATTR_MTIME; |
| 1846 | } |
| 1847 | |
| 1848 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1849 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1851 | static int _nfs4_do_open(struct inode *dir, |
| 1852 | struct dentry *dentry, |
| 1853 | fmode_t fmode, |
| 1854 | int flags, |
| 1855 | struct iattr *sattr, |
| 1856 | struct rpc_cred *cred, |
| 1857 | struct nfs4_state **res, |
| 1858 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | { |
| 1860 | struct nfs4_state_owner *sp; |
| 1861 | struct nfs4_state *state = NULL; |
| 1862 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1863 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1864 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
| 1866 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1868 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1869 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1871 | goto out_err; |
| 1872 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1873 | status = nfs4_recover_expired_lease(server); |
| 1874 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1875 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1876 | if (dentry->d_inode != NULL) |
| 1877 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1878 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1879 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1880 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1881 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1883 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1884 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1885 | if (!opendata->f_attr.mdsthreshold) |
| 1886 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1887 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1888 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1889 | if (dentry->d_inode != NULL) |
| 1890 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1891 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1892 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1894 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1896 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1897 | status = PTR_ERR(state); |
| 1898 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1899 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1900 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1901 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1902 | |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1903 | status = nfs4_opendata_access(cred, opendata, state, fmode, flags); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1904 | if (status != 0) |
| 1905 | goto err_opendata_put; |
| 1906 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1907 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1908 | nfs4_exclusive_attrset(opendata, sattr); |
| 1909 | |
| 1910 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1911 | status = nfs4_do_setattr(state->inode, cred, |
| 1912 | opendata->o_res.f_attr, sattr, |
| 1913 | state); |
| 1914 | if (status == 0) |
| 1915 | nfs_setattr_update_inode(state->inode, sattr); |
| 1916 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1917 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1918 | |
| 1919 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1920 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1921 | else |
| 1922 | kfree(opendata->f_attr.mdsthreshold); |
| 1923 | opendata->f_attr.mdsthreshold = NULL; |
| 1924 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1925 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | *res = state; |
| 1928 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1929 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1930 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1931 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1932 | err_put_state_owner: |
| 1933 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | *res = NULL; |
| 1936 | return status; |
| 1937 | } |
| 1938 | |
| 1939 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1940 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1941 | struct dentry *dentry, |
| 1942 | fmode_t fmode, |
| 1943 | int flags, |
| 1944 | struct iattr *sattr, |
| 1945 | struct rpc_cred *cred, |
| 1946 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | { |
| 1948 | struct nfs4_exception exception = { }; |
| 1949 | struct nfs4_state *res; |
| 1950 | int status; |
| 1951 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1952 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1954 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1955 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | if (status == 0) |
| 1957 | break; |
| 1958 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1959 | * book-keeping w.r.t. state-changing operations |
| 1960 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1961 | * It is actually a sign of a bug on the client or on the server. |
| 1962 | * |
| 1963 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1964 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | * have unhashed the old state_owner for us, and that we can |
| 1966 | * therefore safely retry using a new one. We should still warn |
| 1967 | * the user though... |
| 1968 | */ |
| 1969 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1970 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1971 | " returned a bad sequence-id error!\n", |
| 1972 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | exception.retry = 1; |
| 1974 | continue; |
| 1975 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1976 | /* |
| 1977 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1978 | * state before it received the OPEN_CONFIRM. |
| 1979 | * Recover by retrying the request as per the discussion |
| 1980 | * on Page 181 of RFC3530. |
| 1981 | */ |
| 1982 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1983 | exception.retry = 1; |
| 1984 | continue; |
| 1985 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1986 | if (status == -EAGAIN) { |
| 1987 | /* We must have found a delegation */ |
| 1988 | exception.retry = 1; |
| 1989 | continue; |
| 1990 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1992 | status, &exception)); |
| 1993 | } while (exception.retry); |
| 1994 | return res; |
| 1995 | } |
| 1996 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1997 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1998 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1999 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2001 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2003 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | .iap = sattr, |
| 2005 | .server = server, |
| 2006 | .bitmask = server->attr_bitmask, |
| 2007 | }; |
| 2008 | struct nfs_setattrres res = { |
| 2009 | .fattr = fattr, |
| 2010 | .server = server, |
| 2011 | }; |
| 2012 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2013 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2014 | .rpc_argp = &arg, |
| 2015 | .rpc_resp = &res, |
| 2016 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2018 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2019 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2021 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2023 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2024 | struct nfs_lockowner lockowner = { |
| 2025 | .l_owner = current->files, |
| 2026 | .l_pid = current->tgid, |
| 2027 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2028 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2029 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2030 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2031 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2032 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2033 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2034 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2036 | 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] | 2037 | if (status == 0 && state != NULL) |
| 2038 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2039 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2042 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2043 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2044 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2046 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2047 | struct nfs4_exception exception = { |
| 2048 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2049 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2050 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | int err; |
| 2052 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2053 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2054 | switch (err) { |
| 2055 | case -NFS4ERR_OPENMODE: |
| 2056 | if (state && !(state->state & FMODE_WRITE)) { |
| 2057 | err = -EBADF; |
| 2058 | if (sattr->ia_valid & ATTR_OPEN) |
| 2059 | err = -EACCES; |
| 2060 | goto out; |
| 2061 | } |
| 2062 | } |
| 2063 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2065 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | return err; |
| 2067 | } |
| 2068 | |
| 2069 | struct nfs4_closedata { |
| 2070 | struct inode *inode; |
| 2071 | struct nfs4_state *state; |
| 2072 | struct nfs_closeargs arg; |
| 2073 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2074 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2075 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2076 | bool roc; |
| 2077 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | }; |
| 2079 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2080 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2081 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2082 | struct nfs4_closedata *calldata = data; |
| 2083 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2084 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2085 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2086 | if (calldata->roc) |
| 2087 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2088 | nfs4_put_open_state(calldata->state); |
| 2089 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2090 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2091 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2092 | kfree(calldata); |
| 2093 | } |
| 2094 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2095 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2096 | fmode_t fmode) |
| 2097 | { |
| 2098 | spin_lock(&state->owner->so_lock); |
| 2099 | if (!(fmode & FMODE_READ)) |
| 2100 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2101 | if (!(fmode & FMODE_WRITE)) |
| 2102 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2103 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2104 | spin_unlock(&state->owner->so_lock); |
| 2105 | } |
| 2106 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2107 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2109 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2112 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2113 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2114 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2115 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | /* hmm. we are done with the inode, and in the process of freeing |
| 2117 | * the state_owner. we keep this around to process errors |
| 2118 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | switch (task->tk_status) { |
| 2120 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2121 | if (calldata->roc) |
| 2122 | pnfs_roc_set_barrier(state->inode, |
| 2123 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2124 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2125 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2126 | nfs4_close_clear_stateid_flags(state, |
| 2127 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | break; |
| 2129 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2130 | case -NFS4ERR_OLD_STATEID: |
| 2131 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2133 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2134 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2136 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2137 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2139 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2140 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2141 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2144 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2146 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2147 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2148 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2149 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2150 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2151 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2152 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2153 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2154 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2155 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2156 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2157 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2158 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2159 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2160 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2161 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2162 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2163 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2164 | } |
| 2165 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2166 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2167 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2168 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2169 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2170 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2171 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2172 | |
| 2173 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2174 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2175 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2176 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2177 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2178 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2179 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2180 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2181 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2182 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2183 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2184 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2185 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2186 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2187 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2188 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2189 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2190 | &calldata->arg.seq_args, |
| 2191 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2192 | task) != 0) |
| 2193 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2194 | out: |
| 2195 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2198 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2199 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2200 | .rpc_call_done = nfs4_close_done, |
| 2201 | .rpc_release = nfs4_free_closedata, |
| 2202 | }; |
| 2203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | /* |
| 2205 | * It is possible for data to be read/written from a mem-mapped file |
| 2206 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2207 | * This means that we can't safely call nfsv4 close on a file until |
| 2208 | * the inode is cleared. This in turn means that we are not good |
| 2209 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2210 | * share state even when we are done with one of the three share |
| 2211 | * stateid's in the inode. |
| 2212 | * |
| 2213 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2214 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2215 | 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] | 2216 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2217 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2219 | struct nfs4_state_owner *sp = state->owner; |
| 2220 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2221 | struct rpc_message msg = { |
| 2222 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2223 | .rpc_cred = state->owner->so_cred, |
| 2224 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2225 | struct rpc_task_setup task_setup_data = { |
| 2226 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2227 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2228 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2229 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2230 | .flags = RPC_TASK_ASYNC, |
| 2231 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2232 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2234 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2236 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2237 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2238 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2240 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2241 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2243 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2244 | if (calldata->arg.seqid == NULL) |
| 2245 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2246 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2247 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2248 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2249 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2250 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2251 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2252 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2253 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2254 | msg.rpc_argp = &calldata->arg; |
| 2255 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2256 | task_setup_data.callback_data = calldata; |
| 2257 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2258 | if (IS_ERR(task)) |
| 2259 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2260 | status = 0; |
| 2261 | if (wait) |
| 2262 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2263 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2264 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2265 | out_free_calldata: |
| 2266 | kfree(calldata); |
| 2267 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2268 | nfs4_put_open_state(state); |
| 2269 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2270 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2273 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2274 | 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] | 2275 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | struct nfs4_state *state; |
| 2277 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2278 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2279 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2280 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2281 | if (IS_ERR(state)) |
| 2282 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2283 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2284 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2287 | 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] | 2288 | { |
| 2289 | if (ctx->state == NULL) |
| 2290 | return; |
| 2291 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2292 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2293 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2294 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | |
| 2297 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2298 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2299 | struct nfs4_server_caps_arg args = { |
| 2300 | .fhandle = fhandle, |
| 2301 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | struct nfs4_server_caps_res res = {}; |
| 2303 | struct rpc_message msg = { |
| 2304 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2305 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | .rpc_resp = &res, |
| 2307 | }; |
| 2308 | int status; |
| 2309 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2310 | 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] | 2311 | if (status == 0) { |
| 2312 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2313 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2314 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2315 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2316 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2317 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2319 | server->caps |= NFS_CAP_ACLS; |
| 2320 | if (res.has_links != 0) |
| 2321 | server->caps |= NFS_CAP_HARDLINKS; |
| 2322 | if (res.has_symlinks != 0) |
| 2323 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2324 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2325 | server->caps |= NFS_CAP_FILEID; |
| 2326 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2327 | server->caps |= NFS_CAP_MODE; |
| 2328 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2329 | server->caps |= NFS_CAP_NLINK; |
| 2330 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2331 | server->caps |= NFS_CAP_OWNER; |
| 2332 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2333 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2334 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2335 | server->caps |= NFS_CAP_ATIME; |
| 2336 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2337 | server->caps |= NFS_CAP_CTIME; |
| 2338 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2339 | server->caps |= NFS_CAP_MTIME; |
| 2340 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2341 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2342 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2343 | 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] | 2344 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2345 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | return status; |
| 2349 | } |
| 2350 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2351 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | { |
| 2353 | struct nfs4_exception exception = { }; |
| 2354 | int err; |
| 2355 | do { |
| 2356 | err = nfs4_handle_exception(server, |
| 2357 | _nfs4_server_capabilities(server, fhandle), |
| 2358 | &exception); |
| 2359 | } while (exception.retry); |
| 2360 | return err; |
| 2361 | } |
| 2362 | |
| 2363 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2364 | struct nfs_fsinfo *info) |
| 2365 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | struct nfs4_lookup_root_arg args = { |
| 2367 | .bitmask = nfs4_fattr_bitmap, |
| 2368 | }; |
| 2369 | struct nfs4_lookup_res res = { |
| 2370 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2371 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | .fh = fhandle, |
| 2373 | }; |
| 2374 | struct rpc_message msg = { |
| 2375 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2376 | .rpc_argp = &args, |
| 2377 | .rpc_resp = &res, |
| 2378 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2379 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2380 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2381 | 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] | 2382 | } |
| 2383 | |
| 2384 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2385 | struct nfs_fsinfo *info) |
| 2386 | { |
| 2387 | struct nfs4_exception exception = { }; |
| 2388 | int err; |
| 2389 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2390 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2391 | switch (err) { |
| 2392 | case 0: |
| 2393 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2394 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2395 | default: |
| 2396 | err = nfs4_handle_exception(server, err, &exception); |
| 2397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2399 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | return err; |
| 2401 | } |
| 2402 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2403 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2404 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2405 | { |
| 2406 | struct rpc_auth *auth; |
| 2407 | int ret; |
| 2408 | |
| 2409 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2410 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2411 | ret = -EIO; |
| 2412 | goto out; |
| 2413 | } |
| 2414 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2415 | out: |
| 2416 | return ret; |
| 2417 | } |
| 2418 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2419 | 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] | 2420 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2422 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2423 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2425 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2426 | if (len < 0) |
| 2427 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2428 | |
| 2429 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2430 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2431 | * thus has already been tried. */ |
| 2432 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2433 | continue; |
| 2434 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2435 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2436 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2437 | continue; |
| 2438 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2439 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2440 | /* |
| 2441 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2442 | * to access the mount. It could also mean that we tried to mount |
| 2443 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2444 | * existing mount programs don't handle -EACCES very well so it should |
| 2445 | * be mapped to -EPERM instead. |
| 2446 | */ |
| 2447 | if (status == -EACCES) |
| 2448 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2449 | return status; |
| 2450 | } |
| 2451 | |
| 2452 | /* |
| 2453 | * get the file handle for the "/" directory on the server |
| 2454 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2455 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2456 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2457 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2458 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2459 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2460 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2461 | /* |
| 2462 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2463 | * by nfs4_map_errors() as this function exits. |
| 2464 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2465 | 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] | 2466 | if (status == 0) |
| 2467 | status = nfs4_server_capabilities(server, fhandle); |
| 2468 | if (status == 0) |
| 2469 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2470 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2473 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2474 | struct nfs_fsinfo *info) |
| 2475 | { |
| 2476 | int error; |
| 2477 | struct nfs_fattr *fattr = info->fattr; |
| 2478 | |
| 2479 | error = nfs4_server_capabilities(server, mntfh); |
| 2480 | if (error < 0) { |
| 2481 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2482 | return error; |
| 2483 | } |
| 2484 | |
| 2485 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2486 | if (error < 0) { |
| 2487 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2488 | return error; |
| 2489 | } |
| 2490 | |
| 2491 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2492 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2493 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2494 | |
| 2495 | return error; |
| 2496 | } |
| 2497 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2498 | /* |
| 2499 | * Get locations and (maybe) other attributes of a referral. |
| 2500 | * Note that we'll actually follow the referral later when |
| 2501 | * we detect fsid mismatch in inode revalidation |
| 2502 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2503 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2504 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2505 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2506 | { |
| 2507 | int status = -ENOMEM; |
| 2508 | struct page *page = NULL; |
| 2509 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2510 | |
| 2511 | page = alloc_page(GFP_KERNEL); |
| 2512 | if (page == NULL) |
| 2513 | goto out; |
| 2514 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2515 | if (locations == NULL) |
| 2516 | goto out; |
| 2517 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2518 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2519 | if (status != 0) |
| 2520 | goto out; |
| 2521 | /* Make sure server returned a different fsid for the referral */ |
| 2522 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2523 | dprintk("%s: server did not return a different fsid for" |
| 2524 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2525 | status = -EIO; |
| 2526 | goto out; |
| 2527 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2528 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2529 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2530 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2531 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2532 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2533 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2534 | out: |
| 2535 | if (page) |
| 2536 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2537 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2538 | return status; |
| 2539 | } |
| 2540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2542 | { |
| 2543 | struct nfs4_getattr_arg args = { |
| 2544 | .fh = fhandle, |
| 2545 | .bitmask = server->attr_bitmask, |
| 2546 | }; |
| 2547 | struct nfs4_getattr_res res = { |
| 2548 | .fattr = fattr, |
| 2549 | .server = server, |
| 2550 | }; |
| 2551 | struct rpc_message msg = { |
| 2552 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2553 | .rpc_argp = &args, |
| 2554 | .rpc_resp = &res, |
| 2555 | }; |
| 2556 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2557 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2558 | 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] | 2559 | } |
| 2560 | |
| 2561 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2562 | { |
| 2563 | struct nfs4_exception exception = { }; |
| 2564 | int err; |
| 2565 | do { |
| 2566 | err = nfs4_handle_exception(server, |
| 2567 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2568 | &exception); |
| 2569 | } while (exception.retry); |
| 2570 | return err; |
| 2571 | } |
| 2572 | |
| 2573 | /* |
| 2574 | * The file is not closed if it is opened due to the a request to change |
| 2575 | * the size of the file. The open call will not be needed once the |
| 2576 | * VFS layer lookup-intents are implemented. |
| 2577 | * |
| 2578 | * Close is called when the inode is destroyed. |
| 2579 | * If we haven't opened the file for O_WRONLY, we |
| 2580 | * need to in the size_change case to obtain a stateid. |
| 2581 | * |
| 2582 | * Got race? |
| 2583 | * Because OPEN is always done by name in nfsv4, it is |
| 2584 | * possible that we opened a different file by the same |
| 2585 | * name. We can recognize this race condition, but we |
| 2586 | * can't do anything about it besides returning an error. |
| 2587 | * |
| 2588 | * This will be fixed with VFS changes (lookup-intent). |
| 2589 | */ |
| 2590 | static int |
| 2591 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2592 | struct iattr *sattr) |
| 2593 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2594 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2595 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2596 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | int status; |
| 2598 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2599 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2600 | pnfs_return_layout(inode); |
| 2601 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2602 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2604 | /* Deal with open(O_TRUNC) */ |
| 2605 | if (sattr->ia_valid & ATTR_OPEN) |
| 2606 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2607 | |
| 2608 | /* Optimization: if the end result is no change, don't RPC */ |
| 2609 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2610 | return 0; |
| 2611 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2612 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2613 | if (sattr->ia_valid & ATTR_FILE) { |
| 2614 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2615 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2616 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2617 | if (ctx) { |
| 2618 | cred = ctx->cred; |
| 2619 | state = ctx->state; |
| 2620 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2624 | if (status == 0) |
| 2625 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | return status; |
| 2627 | } |
| 2628 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2629 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2630 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2631 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2632 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2633 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2634 | int status; |
| 2635 | struct nfs4_lookup_arg args = { |
| 2636 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2637 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2638 | .name = name, |
| 2639 | }; |
| 2640 | struct nfs4_lookup_res res = { |
| 2641 | .server = server, |
| 2642 | .fattr = fattr, |
| 2643 | .fh = fhandle, |
| 2644 | }; |
| 2645 | struct rpc_message msg = { |
| 2646 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2647 | .rpc_argp = &args, |
| 2648 | .rpc_resp = &res, |
| 2649 | }; |
| 2650 | |
| 2651 | nfs_fattr_init(fattr); |
| 2652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2654 | 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] | 2655 | dprintk("NFS reply lookup: %d\n", status); |
| 2656 | return status; |
| 2657 | } |
| 2658 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2659 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2660 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2661 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2662 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2663 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2664 | fattr->nlink = 2; |
| 2665 | } |
| 2666 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2667 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2668 | struct qstr *name, struct nfs_fh *fhandle, |
| 2669 | struct nfs_fattr *fattr) |
| 2670 | { |
| 2671 | struct nfs4_exception exception = { }; |
| 2672 | struct rpc_clnt *client = *clnt; |
| 2673 | int err; |
| 2674 | do { |
| 2675 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2676 | switch (err) { |
| 2677 | case -NFS4ERR_BADNAME: |
| 2678 | err = -ENOENT; |
| 2679 | goto out; |
| 2680 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2681 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2682 | goto out; |
| 2683 | case -NFS4ERR_WRONGSEC: |
| 2684 | err = -EPERM; |
| 2685 | if (client != *clnt) |
| 2686 | goto out; |
| 2687 | |
| 2688 | client = nfs4_create_sec_client(client, dir, name); |
| 2689 | if (IS_ERR(client)) |
| 2690 | return PTR_ERR(client); |
| 2691 | |
| 2692 | exception.retry = 1; |
| 2693 | break; |
| 2694 | default: |
| 2695 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2696 | } |
| 2697 | } while (exception.retry); |
| 2698 | |
| 2699 | out: |
| 2700 | if (err == 0) |
| 2701 | *clnt = client; |
| 2702 | else if (client != *clnt) |
| 2703 | rpc_shutdown_client(client); |
| 2704 | |
| 2705 | return err; |
| 2706 | } |
| 2707 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2708 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2709 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2711 | int status; |
| 2712 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2713 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2714 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2715 | if (client != NFS_CLIENT(dir)) { |
| 2716 | rpc_shutdown_client(client); |
| 2717 | nfs_fixup_secinfo_attributes(fattr); |
| 2718 | } |
| 2719 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2722 | struct rpc_clnt * |
| 2723 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2724 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2725 | { |
| 2726 | int status; |
| 2727 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2728 | |
| 2729 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2730 | if (status < 0) { |
| 2731 | rpc_shutdown_client(client); |
| 2732 | return ERR_PTR(status); |
| 2733 | } |
| 2734 | return client; |
| 2735 | } |
| 2736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2738 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2739 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | struct nfs4_accessargs args = { |
| 2741 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2742 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2744 | struct nfs4_accessres res = { |
| 2745 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2746 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | struct rpc_message msg = { |
| 2748 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2749 | .rpc_argp = &args, |
| 2750 | .rpc_resp = &res, |
| 2751 | .rpc_cred = entry->cred, |
| 2752 | }; |
| 2753 | int mode = entry->mask; |
| 2754 | int status; |
| 2755 | |
| 2756 | /* |
| 2757 | * Determine which access bits we want to ask for... |
| 2758 | */ |
| 2759 | if (mode & MAY_READ) |
| 2760 | args.access |= NFS4_ACCESS_READ; |
| 2761 | if (S_ISDIR(inode->i_mode)) { |
| 2762 | if (mode & MAY_WRITE) |
| 2763 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2764 | if (mode & MAY_EXEC) |
| 2765 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2766 | } else { |
| 2767 | if (mode & MAY_WRITE) |
| 2768 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2769 | if (mode & MAY_EXEC) |
| 2770 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2771 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2772 | |
| 2773 | res.fattr = nfs_alloc_fattr(); |
| 2774 | if (res.fattr == NULL) |
| 2775 | return -ENOMEM; |
| 2776 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2777 | 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] | 2778 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2779 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2780 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2782 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | return status; |
| 2784 | } |
| 2785 | |
| 2786 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2787 | { |
| 2788 | struct nfs4_exception exception = { }; |
| 2789 | int err; |
| 2790 | do { |
| 2791 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2792 | _nfs4_proc_access(inode, entry), |
| 2793 | &exception); |
| 2794 | } while (exception.retry); |
| 2795 | return err; |
| 2796 | } |
| 2797 | |
| 2798 | /* |
| 2799 | * TODO: For the time being, we don't try to get any attributes |
| 2800 | * along with any of the zero-copy operations READ, READDIR, |
| 2801 | * READLINK, WRITE. |
| 2802 | * |
| 2803 | * In the case of the first three, we want to put the GETATTR |
| 2804 | * after the read-type operation -- this is because it is hard |
| 2805 | * to predict the length of a GETATTR response in v4, and thus |
| 2806 | * align the READ data correctly. This means that the GETATTR |
| 2807 | * may end up partially falling into the page cache, and we should |
| 2808 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2809 | * To do this efficiently, we need to know the total length |
| 2810 | * of data received, which doesn't seem to be available outside |
| 2811 | * of the RPC layer. |
| 2812 | * |
| 2813 | * In the case of WRITE, we also want to put the GETATTR after |
| 2814 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2815 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | * |
| 2817 | * Both of these changes to the XDR layer would in fact be quite |
| 2818 | * minor, but I decided to leave them for a subsequent patch. |
| 2819 | */ |
| 2820 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2821 | unsigned int pgbase, unsigned int pglen) |
| 2822 | { |
| 2823 | struct nfs4_readlink args = { |
| 2824 | .fh = NFS_FH(inode), |
| 2825 | .pgbase = pgbase, |
| 2826 | .pglen = pglen, |
| 2827 | .pages = &page, |
| 2828 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2829 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | struct rpc_message msg = { |
| 2831 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2832 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2833 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | }; |
| 2835 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2836 | 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] | 2837 | } |
| 2838 | |
| 2839 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2840 | unsigned int pgbase, unsigned int pglen) |
| 2841 | { |
| 2842 | struct nfs4_exception exception = { }; |
| 2843 | int err; |
| 2844 | do { |
| 2845 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2846 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2847 | &exception); |
| 2848 | } while (exception.retry); |
| 2849 | return err; |
| 2850 | } |
| 2851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2853 | * 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] | 2854 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | static int |
| 2856 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2857 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2859 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | int status = 0; |
| 2862 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2863 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2864 | if (IS_ERR(ctx)) |
| 2865 | return PTR_ERR(ctx); |
| 2866 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2867 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2868 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2869 | flags, sattr, ctx->cred, |
| 2870 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2871 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | if (IS_ERR(state)) { |
| 2873 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2874 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2876 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2877 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2878 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2880 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | return status; |
| 2882 | } |
| 2883 | |
| 2884 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2885 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2886 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2887 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2889 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2891 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2892 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2893 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2895 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2896 | .rpc_argp = &args, |
| 2897 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2899 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2900 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2901 | 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] | 2902 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2903 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | return status; |
| 2905 | } |
| 2906 | |
| 2907 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2908 | { |
| 2909 | struct nfs4_exception exception = { }; |
| 2910 | int err; |
| 2911 | do { |
| 2912 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2913 | _nfs4_proc_remove(dir, name), |
| 2914 | &exception); |
| 2915 | } while (exception.retry); |
| 2916 | return err; |
| 2917 | } |
| 2918 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2919 | 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] | 2920 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2921 | struct nfs_server *server = NFS_SERVER(dir); |
| 2922 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2923 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2925 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2927 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | } |
| 2929 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2930 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2931 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2932 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2933 | &data->args.seq_args, |
| 2934 | &data->res.seq_res, |
| 2935 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2938 | 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] | 2939 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2940 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2941 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2942 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2943 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2944 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2945 | return 0; |
| 2946 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2947 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2950 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2951 | { |
| 2952 | struct nfs_server *server = NFS_SERVER(dir); |
| 2953 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2954 | struct nfs_renameres *res = msg->rpc_resp; |
| 2955 | |
| 2956 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2957 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2958 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2959 | } |
| 2960 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2961 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2962 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2963 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2964 | &data->args.seq_args, |
| 2965 | &data->res.seq_res, |
| 2966 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2970 | struct inode *new_dir) |
| 2971 | { |
| 2972 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2973 | |
| 2974 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2975 | return 0; |
| 2976 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2977 | return 0; |
| 2978 | |
| 2979 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2980 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2981 | return 1; |
| 2982 | } |
| 2983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2985 | struct inode *new_dir, struct qstr *new_name) |
| 2986 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2987 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2988 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | .old_dir = NFS_FH(old_dir), |
| 2990 | .new_dir = NFS_FH(new_dir), |
| 2991 | .old_name = old_name, |
| 2992 | .new_name = new_name, |
| 2993 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2994 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2995 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2996 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | struct rpc_message msg = { |
| 2998 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2999 | .rpc_argp = &arg, |
| 3000 | .rpc_resp = &res, |
| 3001 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3002 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3004 | 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] | 3005 | if (!status) { |
| 3006 | update_changeattr(old_dir, &res.old_cinfo); |
| 3007 | update_changeattr(new_dir, &res.new_cinfo); |
| 3008 | } |
| 3009 | return status; |
| 3010 | } |
| 3011 | |
| 3012 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3013 | struct inode *new_dir, struct qstr *new_name) |
| 3014 | { |
| 3015 | struct nfs4_exception exception = { }; |
| 3016 | int err; |
| 3017 | do { |
| 3018 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3019 | _nfs4_proc_rename(old_dir, old_name, |
| 3020 | new_dir, new_name), |
| 3021 | &exception); |
| 3022 | } while (exception.retry); |
| 3023 | return err; |
| 3024 | } |
| 3025 | |
| 3026 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3027 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3028 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | struct nfs4_link_arg arg = { |
| 3030 | .fh = NFS_FH(inode), |
| 3031 | .dir_fh = NFS_FH(dir), |
| 3032 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3033 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3035 | struct nfs4_link_res res = { |
| 3036 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3037 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | struct rpc_message msg = { |
| 3039 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3040 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3041 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3043 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3045 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3046 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3047 | goto out; |
| 3048 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3049 | 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] | 3050 | if (!status) { |
| 3051 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3052 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3053 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3054 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3055 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | return status; |
| 3057 | } |
| 3058 | |
| 3059 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3060 | { |
| 3061 | struct nfs4_exception exception = { }; |
| 3062 | int err; |
| 3063 | do { |
| 3064 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3065 | _nfs4_proc_link(inode, dir, name), |
| 3066 | &exception); |
| 3067 | } while (exception.retry); |
| 3068 | return err; |
| 3069 | } |
| 3070 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3071 | struct nfs4_createdata { |
| 3072 | struct rpc_message msg; |
| 3073 | struct nfs4_create_arg arg; |
| 3074 | struct nfs4_create_res res; |
| 3075 | struct nfs_fh fh; |
| 3076 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3077 | }; |
| 3078 | |
| 3079 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3080 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3081 | { |
| 3082 | struct nfs4_createdata *data; |
| 3083 | |
| 3084 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3085 | if (data != NULL) { |
| 3086 | struct nfs_server *server = NFS_SERVER(dir); |
| 3087 | |
| 3088 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3089 | data->msg.rpc_argp = &data->arg; |
| 3090 | data->msg.rpc_resp = &data->res; |
| 3091 | data->arg.dir_fh = NFS_FH(dir); |
| 3092 | data->arg.server = server; |
| 3093 | data->arg.name = name; |
| 3094 | data->arg.attrs = sattr; |
| 3095 | data->arg.ftype = ftype; |
| 3096 | data->arg.bitmask = server->attr_bitmask; |
| 3097 | data->res.server = server; |
| 3098 | data->res.fh = &data->fh; |
| 3099 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3100 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3101 | } |
| 3102 | return data; |
| 3103 | } |
| 3104 | |
| 3105 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3106 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3107 | 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] | 3108 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3109 | if (status == 0) { |
| 3110 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3111 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3112 | } |
| 3113 | return status; |
| 3114 | } |
| 3115 | |
| 3116 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3117 | { |
| 3118 | kfree(data); |
| 3119 | } |
| 3120 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3121 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3122 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3124 | struct nfs4_createdata *data; |
| 3125 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3127 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3128 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3129 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3130 | status = -ENOMEM; |
| 3131 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3132 | if (data == NULL) |
| 3133 | goto out; |
| 3134 | |
| 3135 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3136 | data->arg.u.symlink.pages = &page; |
| 3137 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3139 | status = nfs4_do_create(dir, dentry, data); |
| 3140 | |
| 3141 | nfs4_free_createdata(data); |
| 3142 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | return status; |
| 3144 | } |
| 3145 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3146 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3147 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | { |
| 3149 | struct nfs4_exception exception = { }; |
| 3150 | int err; |
| 3151 | do { |
| 3152 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3153 | _nfs4_proc_symlink(dir, dentry, page, |
| 3154 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | &exception); |
| 3156 | } while (exception.retry); |
| 3157 | return err; |
| 3158 | } |
| 3159 | |
| 3160 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3161 | struct iattr *sattr) |
| 3162 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3163 | struct nfs4_createdata *data; |
| 3164 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3166 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3167 | if (data == NULL) |
| 3168 | goto out; |
| 3169 | |
| 3170 | status = nfs4_do_create(dir, dentry, data); |
| 3171 | |
| 3172 | nfs4_free_createdata(data); |
| 3173 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | return status; |
| 3175 | } |
| 3176 | |
| 3177 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3178 | struct iattr *sattr) |
| 3179 | { |
| 3180 | struct nfs4_exception exception = { }; |
| 3181 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3182 | |
| 3183 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | do { |
| 3185 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3186 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3187 | &exception); |
| 3188 | } while (exception.retry); |
| 3189 | return err; |
| 3190 | } |
| 3191 | |
| 3192 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3193 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | { |
| 3195 | struct inode *dir = dentry->d_inode; |
| 3196 | struct nfs4_readdir_arg args = { |
| 3197 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3198 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | .pgbase = 0, |
| 3200 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3201 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3202 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | }; |
| 3204 | struct nfs4_readdir_res res; |
| 3205 | struct rpc_message msg = { |
| 3206 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3207 | .rpc_argp = &args, |
| 3208 | .rpc_resp = &res, |
| 3209 | .rpc_cred = cred, |
| 3210 | }; |
| 3211 | int status; |
| 3212 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3213 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3214 | dentry->d_parent->d_name.name, |
| 3215 | dentry->d_name.name, |
| 3216 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3217 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3219 | 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] | 3220 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3221 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3222 | status += args.pgbase; |
| 3223 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3224 | |
| 3225 | nfs_invalidate_atime(dir); |
| 3226 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3227 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | return status; |
| 3229 | } |
| 3230 | |
| 3231 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3232 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | { |
| 3234 | struct nfs4_exception exception = { }; |
| 3235 | int err; |
| 3236 | do { |
| 3237 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3238 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3239 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | &exception); |
| 3241 | } while (exception.retry); |
| 3242 | return err; |
| 3243 | } |
| 3244 | |
| 3245 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3246 | struct iattr *sattr, dev_t rdev) |
| 3247 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3248 | struct nfs4_createdata *data; |
| 3249 | int mode = sattr->ia_mode; |
| 3250 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3252 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3253 | if (data == NULL) |
| 3254 | goto out; |
| 3255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3257 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3259 | data->arg.ftype = NF4BLK; |
| 3260 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3261 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | } |
| 3263 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3264 | data->arg.ftype = NF4CHR; |
| 3265 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3266 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3267 | } else if (!S_ISSOCK(mode)) { |
| 3268 | status = -EINVAL; |
| 3269 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3272 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3273 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3274 | nfs4_free_createdata(data); |
| 3275 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | return status; |
| 3277 | } |
| 3278 | |
| 3279 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3280 | struct iattr *sattr, dev_t rdev) |
| 3281 | { |
| 3282 | struct nfs4_exception exception = { }; |
| 3283 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3284 | |
| 3285 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | do { |
| 3287 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3288 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3289 | &exception); |
| 3290 | } while (exception.retry); |
| 3291 | return err; |
| 3292 | } |
| 3293 | |
| 3294 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3295 | struct nfs_fsstat *fsstat) |
| 3296 | { |
| 3297 | struct nfs4_statfs_arg args = { |
| 3298 | .fh = fhandle, |
| 3299 | .bitmask = server->attr_bitmask, |
| 3300 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3301 | struct nfs4_statfs_res res = { |
| 3302 | .fsstat = fsstat, |
| 3303 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | struct rpc_message msg = { |
| 3305 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3306 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3307 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | }; |
| 3309 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3310 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3311 | 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] | 3312 | } |
| 3313 | |
| 3314 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3315 | { |
| 3316 | struct nfs4_exception exception = { }; |
| 3317 | int err; |
| 3318 | do { |
| 3319 | err = nfs4_handle_exception(server, |
| 3320 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3321 | &exception); |
| 3322 | } while (exception.retry); |
| 3323 | return err; |
| 3324 | } |
| 3325 | |
| 3326 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3327 | struct nfs_fsinfo *fsinfo) |
| 3328 | { |
| 3329 | struct nfs4_fsinfo_arg args = { |
| 3330 | .fh = fhandle, |
| 3331 | .bitmask = server->attr_bitmask, |
| 3332 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3333 | struct nfs4_fsinfo_res res = { |
| 3334 | .fsinfo = fsinfo, |
| 3335 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | struct rpc_message msg = { |
| 3337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3338 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3339 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | }; |
| 3341 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3342 | 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] | 3343 | } |
| 3344 | |
| 3345 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3346 | { |
| 3347 | struct nfs4_exception exception = { }; |
| 3348 | int err; |
| 3349 | |
| 3350 | do { |
| 3351 | err = nfs4_handle_exception(server, |
| 3352 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3353 | &exception); |
| 3354 | } while (exception.retry); |
| 3355 | return err; |
| 3356 | } |
| 3357 | |
| 3358 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3359 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3360 | int error; |
| 3361 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3362 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3363 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3364 | if (error == 0) { |
| 3365 | /* block layout checks this! */ |
| 3366 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3367 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3368 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3369 | |
| 3370 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3374 | struct nfs_pathconf *pathconf) |
| 3375 | { |
| 3376 | struct nfs4_pathconf_arg args = { |
| 3377 | .fh = fhandle, |
| 3378 | .bitmask = server->attr_bitmask, |
| 3379 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3380 | struct nfs4_pathconf_res res = { |
| 3381 | .pathconf = pathconf, |
| 3382 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | struct rpc_message msg = { |
| 3384 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3385 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3386 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | }; |
| 3388 | |
| 3389 | /* None of the pathconf attributes are mandatory to implement */ |
| 3390 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3391 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3392 | return 0; |
| 3393 | } |
| 3394 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3395 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3396 | 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] | 3397 | } |
| 3398 | |
| 3399 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3400 | struct nfs_pathconf *pathconf) |
| 3401 | { |
| 3402 | struct nfs4_exception exception = { }; |
| 3403 | int err; |
| 3404 | |
| 3405 | do { |
| 3406 | err = nfs4_handle_exception(server, |
| 3407 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3408 | &exception); |
| 3409 | } while (exception.retry); |
| 3410 | return err; |
| 3411 | } |
| 3412 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3413 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3414 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3415 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3416 | } |
| 3417 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3418 | 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] | 3419 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3420 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3422 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3423 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3424 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3426 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3427 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3429 | renew_lease(server, data->timestamp); |
| 3430 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3433 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3434 | { |
| 3435 | |
| 3436 | dprintk("--> %s\n", __func__); |
| 3437 | |
| 3438 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3439 | return -EAGAIN; |
| 3440 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3441 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3442 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3445 | 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] | 3446 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3448 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3449 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3450 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3453 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3454 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3455 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3456 | &data->args.seq_args, |
| 3457 | &data->res.seq_res, |
| 3458 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | } |
| 3460 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3461 | 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] | 3462 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3463 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3465 | 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] | 3466 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3467 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3469 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3471 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3472 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3473 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3476 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3477 | { |
| 3478 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3479 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3480 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3481 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3482 | } |
| 3483 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3484 | static |
| 3485 | 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] | 3486 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3487 | const struct nfs_pgio_header *hdr = data->header; |
| 3488 | |
| 3489 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3490 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3491 | return false; |
| 3492 | /* Otherwise, request attributes if and only if we don't hold |
| 3493 | * a delegation |
| 3494 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3495 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3496 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3497 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3498 | 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] | 3499 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3500 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3501 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3502 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3503 | data->args.bitmask = NULL; |
| 3504 | data->res.fattr = NULL; |
| 3505 | } else |
| 3506 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3507 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3508 | if (!data->write_done_cb) |
| 3509 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3510 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | data->timestamp = jiffies; |
| 3512 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3513 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3514 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3517 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3518 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3519 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3520 | &data->args.seq_args, |
| 3521 | &data->res.seq_res, |
| 3522 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3525 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3526 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3527 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3528 | &data->args.seq_args, |
| 3529 | &data->res.seq_res, |
| 3530 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3533 | 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] | 3534 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3536 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3537 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3538 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3539 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3541 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | } |
| 3543 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3544 | 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] | 3545 | { |
| 3546 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3547 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3548 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3551 | 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] | 3552 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3553 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3554 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3555 | if (data->commit_done_cb == NULL) |
| 3556 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3557 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3558 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3559 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | } |
| 3561 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3562 | struct nfs4_renewdata { |
| 3563 | struct nfs_client *client; |
| 3564 | unsigned long timestamp; |
| 3565 | }; |
| 3566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | /* |
| 3568 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3569 | * standalone procedure for queueing an asynchronous RENEW. |
| 3570 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3571 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3572 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3573 | struct nfs4_renewdata *data = calldata; |
| 3574 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3575 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3576 | if (atomic_read(&clp->cl_count) > 1) |
| 3577 | nfs4_schedule_state_renewal(clp); |
| 3578 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3579 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3580 | } |
| 3581 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3582 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3584 | struct nfs4_renewdata *data = calldata; |
| 3585 | struct nfs_client *clp = data->client; |
| 3586 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | |
| 3588 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3589 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3590 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3591 | return; |
| 3592 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3593 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3594 | return; |
| 3595 | } |
| 3596 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3598 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3601 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3602 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3603 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3604 | }; |
| 3605 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3606 | 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] | 3607 | { |
| 3608 | struct rpc_message msg = { |
| 3609 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3610 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3611 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3613 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3615 | if (renew_flags == 0) |
| 3616 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3617 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3618 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3619 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3620 | if (data == NULL) |
| 3621 | return -ENOMEM; |
| 3622 | data->client = clp; |
| 3623 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3625 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3628 | 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] | 3629 | { |
| 3630 | struct rpc_message msg = { |
| 3631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3632 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3633 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | }; |
| 3635 | unsigned long now = jiffies; |
| 3636 | int status; |
| 3637 | |
| 3638 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3639 | if (status < 0) |
| 3640 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3641 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | return 0; |
| 3643 | } |
| 3644 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3645 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3646 | { |
| 3647 | return (server->caps & NFS_CAP_ACLS) |
| 3648 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3649 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3650 | } |
| 3651 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3652 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3653 | * 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] | 3654 | * the stack. |
| 3655 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3656 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3657 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3658 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3659 | struct page **pages, unsigned int *pgbase) |
| 3660 | { |
| 3661 | struct page *newpage, **spages; |
| 3662 | int rc = 0; |
| 3663 | size_t len; |
| 3664 | spages = pages; |
| 3665 | |
| 3666 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3667 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3668 | newpage = alloc_page(GFP_KERNEL); |
| 3669 | |
| 3670 | if (newpage == NULL) |
| 3671 | goto unwind; |
| 3672 | memcpy(page_address(newpage), buf, len); |
| 3673 | buf += len; |
| 3674 | buflen -= len; |
| 3675 | *pages++ = newpage; |
| 3676 | rc++; |
| 3677 | } while (buflen != 0); |
| 3678 | |
| 3679 | return rc; |
| 3680 | |
| 3681 | unwind: |
| 3682 | for(; rc > 0; rc--) |
| 3683 | __free_page(spages[rc-1]); |
| 3684 | return -ENOMEM; |
| 3685 | } |
| 3686 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3687 | struct nfs4_cached_acl { |
| 3688 | int cached; |
| 3689 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3690 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3691 | }; |
| 3692 | |
| 3693 | 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] | 3694 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3695 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3696 | |
| 3697 | spin_lock(&inode->i_lock); |
| 3698 | kfree(nfsi->nfs4_acl); |
| 3699 | nfsi->nfs4_acl = acl; |
| 3700 | spin_unlock(&inode->i_lock); |
| 3701 | } |
| 3702 | |
| 3703 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3704 | { |
| 3705 | nfs4_set_cached_acl(inode, NULL); |
| 3706 | } |
| 3707 | |
| 3708 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3709 | { |
| 3710 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3711 | struct nfs4_cached_acl *acl; |
| 3712 | int ret = -ENOENT; |
| 3713 | |
| 3714 | spin_lock(&inode->i_lock); |
| 3715 | acl = nfsi->nfs4_acl; |
| 3716 | if (acl == NULL) |
| 3717 | goto out; |
| 3718 | if (buf == NULL) /* user is just asking for length */ |
| 3719 | goto out_len; |
| 3720 | if (acl->cached == 0) |
| 3721 | goto out; |
| 3722 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3723 | if (acl->len > buflen) |
| 3724 | goto out; |
| 3725 | memcpy(buf, acl->data, acl->len); |
| 3726 | out_len: |
| 3727 | ret = acl->len; |
| 3728 | out: |
| 3729 | spin_unlock(&inode->i_lock); |
| 3730 | return ret; |
| 3731 | } |
| 3732 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3733 | 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] | 3734 | { |
| 3735 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3736 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3737 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3738 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3739 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3740 | if (acl == NULL) |
| 3741 | goto out; |
| 3742 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3743 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3744 | } else { |
| 3745 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3746 | if (acl == NULL) |
| 3747 | goto out; |
| 3748 | acl->cached = 0; |
| 3749 | } |
| 3750 | acl->len = acl_len; |
| 3751 | out: |
| 3752 | nfs4_set_cached_acl(inode, acl); |
| 3753 | } |
| 3754 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3755 | /* |
| 3756 | * The getxattr API returns the required buffer length when called with a |
| 3757 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3758 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3759 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3760 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3761 | * the cache. If not so, we throw away the page, and cache the required |
| 3762 | * length. The next getxattr call will then produce another round trip to |
| 3763 | * the server, this time with the input buf of the required size. |
| 3764 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3765 | 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] | 3766 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3767 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3768 | struct nfs_getaclargs args = { |
| 3769 | .fh = NFS_FH(inode), |
| 3770 | .acl_pages = pages, |
| 3771 | .acl_len = buflen, |
| 3772 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3773 | struct nfs_getaclres res = { |
| 3774 | .acl_len = buflen, |
| 3775 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3776 | struct rpc_message msg = { |
| 3777 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3778 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3779 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3780 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3781 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3782 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3783 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3784 | /* As long as we're doing a round trip to the server anyway, |
| 3785 | * let's be prepared for a page of acl data. */ |
| 3786 | if (npages == 0) |
| 3787 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3788 | if (npages > ARRAY_SIZE(pages)) |
| 3789 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3790 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3791 | for (i = 0; i < npages; i++) { |
| 3792 | pages[i] = alloc_page(GFP_KERNEL); |
| 3793 | if (!pages[i]) |
| 3794 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3795 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3796 | |
| 3797 | /* for decoding across pages */ |
| 3798 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3799 | if (!res.acl_scratch) |
| 3800 | goto out_free; |
| 3801 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3802 | args.acl_len = npages * PAGE_SIZE; |
| 3803 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3804 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3805 | 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] | 3806 | __func__, buf, buflen, npages, args.acl_len); |
| 3807 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3808 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3809 | if (ret) |
| 3810 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3811 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3812 | /* Handle the case where the passed-in buffer is too short */ |
| 3813 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3814 | /* Did the user only issue a request for the acl length? */ |
| 3815 | if (buf == NULL) |
| 3816 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3817 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3818 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3819 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3820 | 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] | 3821 | if (buf) { |
| 3822 | if (res.acl_len > buflen) { |
| 3823 | ret = -ERANGE; |
| 3824 | goto out_free; |
| 3825 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3826 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 3827 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3828 | out_ok: |
| 3829 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3830 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3831 | for (i = 0; i < npages; i++) |
| 3832 | if (pages[i]) |
| 3833 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3834 | if (res.acl_scratch) |
| 3835 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3836 | return ret; |
| 3837 | } |
| 3838 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3839 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3840 | { |
| 3841 | struct nfs4_exception exception = { }; |
| 3842 | ssize_t ret; |
| 3843 | do { |
| 3844 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3845 | if (ret >= 0) |
| 3846 | break; |
| 3847 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3848 | } while (exception.retry); |
| 3849 | return ret; |
| 3850 | } |
| 3851 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3852 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3853 | { |
| 3854 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3855 | int ret; |
| 3856 | |
| 3857 | if (!nfs4_server_supports_acls(server)) |
| 3858 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3859 | ret = nfs_revalidate_inode(server, inode); |
| 3860 | if (ret < 0) |
| 3861 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3862 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3863 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3864 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3865 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3866 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3867 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3868 | return ret; |
| 3869 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3870 | } |
| 3871 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3872 | 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] | 3873 | { |
| 3874 | struct nfs_server *server = NFS_SERVER(inode); |
| 3875 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3876 | struct nfs_setaclargs arg = { |
| 3877 | .fh = NFS_FH(inode), |
| 3878 | .acl_pages = pages, |
| 3879 | .acl_len = buflen, |
| 3880 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3881 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3882 | struct rpc_message msg = { |
| 3883 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3884 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3885 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3886 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3887 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3888 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3889 | |
| 3890 | if (!nfs4_server_supports_acls(server)) |
| 3891 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3892 | if (npages > ARRAY_SIZE(pages)) |
| 3893 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3894 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3895 | if (i < 0) |
| 3896 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3897 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3898 | 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] | 3899 | |
| 3900 | /* |
| 3901 | * Free each page after tx, so the only ref left is |
| 3902 | * held by the network stack |
| 3903 | */ |
| 3904 | for (; i > 0; i--) |
| 3905 | put_page(pages[i-1]); |
| 3906 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3907 | /* |
| 3908 | * Acl update can result in inode attribute update. |
| 3909 | * so mark the attribute cache invalid. |
| 3910 | */ |
| 3911 | spin_lock(&inode->i_lock); |
| 3912 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3913 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3914 | nfs_access_zap_cache(inode); |
| 3915 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3916 | return ret; |
| 3917 | } |
| 3918 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3919 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3920 | { |
| 3921 | struct nfs4_exception exception = { }; |
| 3922 | int err; |
| 3923 | do { |
| 3924 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3925 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3926 | &exception); |
| 3927 | } while (exception.retry); |
| 3928 | return err; |
| 3929 | } |
| 3930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3932 | 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] | 3933 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3934 | struct nfs_client *clp = server->nfs_client; |
| 3935 | |
| 3936 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | return 0; |
| 3938 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3939 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3940 | case -NFS4ERR_ADMIN_REVOKED: |
| 3941 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3942 | if (state == NULL) |
| 3943 | break; |
| 3944 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3945 | case -NFS4ERR_OPENMODE: |
| 3946 | if (state == NULL) |
| 3947 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3948 | nfs4_schedule_stateid_recovery(server, state); |
| 3949 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3950 | case -NFS4ERR_EXPIRED: |
| 3951 | if (state != NULL) |
| 3952 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3954 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3955 | nfs4_schedule_lease_recovery(clp); |
| 3956 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3957 | #if defined(CONFIG_NFS_V4_1) |
| 3958 | case -NFS4ERR_BADSESSION: |
| 3959 | case -NFS4ERR_BADSLOT: |
| 3960 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3961 | case -NFS4ERR_DEADSESSION: |
| 3962 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3963 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3964 | case -NFS4ERR_SEQ_MISORDERED: |
| 3965 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3966 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3967 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3968 | task->tk_status = 0; |
| 3969 | return -EAGAIN; |
| 3970 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3972 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3973 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3975 | task->tk_status = 0; |
| 3976 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3977 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | case -NFS4ERR_OLD_STATEID: |
| 3979 | task->tk_status = 0; |
| 3980 | return -EAGAIN; |
| 3981 | } |
| 3982 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3983 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3984 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3985 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3986 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3987 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3988 | task->tk_status = 0; |
| 3989 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3992 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 3993 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3994 | { |
| 3995 | __be32 verf[2]; |
| 3996 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 3997 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 3998 | /* An impossible timestamp guarantees this value |
| 3999 | * will never match a generated boot time. */ |
| 4000 | verf[0] = 0; |
| 4001 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4002 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4003 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4004 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4005 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4006 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4007 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4008 | } |
| 4009 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4010 | static unsigned int |
| 4011 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4012 | char *buf, size_t len) |
| 4013 | { |
| 4014 | unsigned int result; |
| 4015 | |
| 4016 | rcu_read_lock(); |
| 4017 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4018 | clp->cl_ipaddr, |
| 4019 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4020 | RPC_DISPLAY_ADDR), |
| 4021 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4022 | RPC_DISPLAY_PROTO)); |
| 4023 | rcu_read_unlock(); |
| 4024 | return result; |
| 4025 | } |
| 4026 | |
| 4027 | static unsigned int |
| 4028 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4029 | char *buf, size_t len) |
| 4030 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4031 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4032 | |
| 4033 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4034 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4035 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4036 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4037 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4038 | } |
| 4039 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4040 | /** |
| 4041 | * nfs4_proc_setclientid - Negotiate client ID |
| 4042 | * @clp: state data structure |
| 4043 | * @program: RPC program for NFSv4 callback service |
| 4044 | * @port: IP port number for NFS4 callback service |
| 4045 | * @cred: RPC credential to use for this call |
| 4046 | * @res: where to place the result |
| 4047 | * |
| 4048 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4049 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4050 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4051 | unsigned short port, struct rpc_cred *cred, |
| 4052 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | { |
| 4054 | nfs4_verifier sc_verifier; |
| 4055 | struct nfs4_setclientid setclientid = { |
| 4056 | .sc_verifier = &sc_verifier, |
| 4057 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4058 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | }; |
| 4060 | struct rpc_message msg = { |
| 4061 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4062 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4063 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4064 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4066 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4068 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4069 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4070 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4071 | setclientid.sc_name_len = |
| 4072 | nfs4_init_uniform_client_string(clp, |
| 4073 | setclientid.sc_name, |
| 4074 | sizeof(setclientid.sc_name)); |
| 4075 | else |
| 4076 | setclientid.sc_name_len = |
| 4077 | nfs4_init_nonuniform_client_string(clp, |
| 4078 | setclientid.sc_name, |
| 4079 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4080 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4081 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4082 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4083 | sizeof(setclientid.sc_netid), |
| 4084 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4085 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4086 | rcu_read_unlock(); |
| 4087 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4088 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4090 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4091 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4092 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4093 | setclientid.sc_name_len, setclientid.sc_name); |
| 4094 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4095 | dprintk("NFS reply setclientid: %d\n", status); |
| 4096 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4099 | /** |
| 4100 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4101 | * @clp: state data structure |
| 4102 | * @res: result of a previous SETCLIENTID |
| 4103 | * @cred: RPC credential to use for this call |
| 4104 | * |
| 4105 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4106 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4107 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4108 | struct nfs4_setclientid_res *arg, |
| 4109 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | { |
| 4111 | struct nfs_fsinfo fsinfo; |
| 4112 | struct rpc_message msg = { |
| 4113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4114 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4116 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | }; |
| 4118 | unsigned long now; |
| 4119 | int status; |
| 4120 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4121 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4122 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4123 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4125 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | if (status == 0) { |
| 4127 | spin_lock(&clp->cl_lock); |
| 4128 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4129 | clp->cl_last_renewal = now; |
| 4130 | spin_unlock(&clp->cl_lock); |
| 4131 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4132 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | return status; |
| 4134 | } |
| 4135 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4136 | struct nfs4_delegreturndata { |
| 4137 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4138 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4139 | struct nfs_fh fh; |
| 4140 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4141 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4142 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4143 | int rpc_status; |
| 4144 | }; |
| 4145 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4146 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4147 | { |
| 4148 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4149 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4150 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4151 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4152 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4153 | switch (task->tk_status) { |
| 4154 | case -NFS4ERR_STALE_STATEID: |
| 4155 | case -NFS4ERR_EXPIRED: |
| 4156 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4157 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4158 | break; |
| 4159 | default: |
| 4160 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4161 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4162 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4163 | return; |
| 4164 | } |
| 4165 | } |
| 4166 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | static void nfs4_delegreturn_release(void *calldata) |
| 4170 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4171 | kfree(calldata); |
| 4172 | } |
| 4173 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4174 | #if defined(CONFIG_NFS_V4_1) |
| 4175 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4176 | { |
| 4177 | struct nfs4_delegreturndata *d_data; |
| 4178 | |
| 4179 | d_data = (struct nfs4_delegreturndata *)data; |
| 4180 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4181 | nfs4_setup_sequence(d_data->res.server, |
| 4182 | &d_data->args.seq_args, |
| 4183 | &d_data->res.seq_res, |
| 4184 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4185 | } |
| 4186 | #endif /* CONFIG_NFS_V4_1 */ |
| 4187 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4188 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4189 | #if defined(CONFIG_NFS_V4_1) |
| 4190 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4191 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4192 | .rpc_call_done = nfs4_delegreturn_done, |
| 4193 | .rpc_release = nfs4_delegreturn_release, |
| 4194 | }; |
| 4195 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4196 | 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] | 4197 | { |
| 4198 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4199 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4200 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4201 | struct rpc_message msg = { |
| 4202 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4203 | .rpc_cred = cred, |
| 4204 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4205 | struct rpc_task_setup task_setup_data = { |
| 4206 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4207 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4208 | .callback_ops = &nfs4_delegreturn_ops, |
| 4209 | .flags = RPC_TASK_ASYNC, |
| 4210 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4211 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4212 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4213 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4214 | if (data == NULL) |
| 4215 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4216 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4217 | data->args.fhandle = &data->fh; |
| 4218 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4219 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4220 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4221 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4222 | data->res.fattr = &data->fattr; |
| 4223 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4224 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4225 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4226 | data->rpc_status = 0; |
| 4227 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4228 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4229 | msg.rpc_argp = &data->args; |
| 4230 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4231 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4232 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4233 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4234 | if (!issync) |
| 4235 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4236 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4237 | if (status != 0) |
| 4238 | goto out; |
| 4239 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4240 | if (status == 0) |
| 4241 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4242 | else |
| 4243 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4244 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4245 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4246 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4249 | 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] | 4250 | { |
| 4251 | struct nfs_server *server = NFS_SERVER(inode); |
| 4252 | struct nfs4_exception exception = { }; |
| 4253 | int err; |
| 4254 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4255 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | switch (err) { |
| 4257 | case -NFS4ERR_STALE_STATEID: |
| 4258 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | case 0: |
| 4260 | return 0; |
| 4261 | } |
| 4262 | err = nfs4_handle_exception(server, err, &exception); |
| 4263 | } while (exception.retry); |
| 4264 | return err; |
| 4265 | } |
| 4266 | |
| 4267 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4268 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4269 | |
| 4270 | /* |
| 4271 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4272 | */ |
| 4273 | static unsigned long |
| 4274 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4275 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4276 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | timeout <<= 1; |
| 4278 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4279 | return NFS4_LOCK_MAXTIMEOUT; |
| 4280 | return timeout; |
| 4281 | } |
| 4282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4284 | { |
| 4285 | struct inode *inode = state->inode; |
| 4286 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4287 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4288 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4290 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4292 | struct nfs_lockt_res res = { |
| 4293 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | }; |
| 4295 | struct rpc_message msg = { |
| 4296 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4297 | .rpc_argp = &arg, |
| 4298 | .rpc_resp = &res, |
| 4299 | .rpc_cred = state->owner->so_cred, |
| 4300 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | struct nfs4_lock_state *lsp; |
| 4302 | int status; |
| 4303 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4304 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4305 | status = nfs4_set_lock_state(state, request); |
| 4306 | if (status != 0) |
| 4307 | goto out; |
| 4308 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4309 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4310 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4311 | 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] | 4312 | switch (status) { |
| 4313 | case 0: |
| 4314 | request->fl_type = F_UNLCK; |
| 4315 | break; |
| 4316 | case -NFS4ERR_DENIED: |
| 4317 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4319 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4320 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | return status; |
| 4322 | } |
| 4323 | |
| 4324 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4325 | { |
| 4326 | struct nfs4_exception exception = { }; |
| 4327 | int err; |
| 4328 | |
| 4329 | do { |
| 4330 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4331 | _nfs4_proc_getlk(state, cmd, request), |
| 4332 | &exception); |
| 4333 | } while (exception.retry); |
| 4334 | return err; |
| 4335 | } |
| 4336 | |
| 4337 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4338 | { |
| 4339 | int res = 0; |
| 4340 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4341 | case FL_POSIX: |
| 4342 | res = posix_lock_file_wait(file, fl); |
| 4343 | break; |
| 4344 | case FL_FLOCK: |
| 4345 | res = flock_lock_file_wait(file, fl); |
| 4346 | break; |
| 4347 | default: |
| 4348 | BUG(); |
| 4349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | return res; |
| 4351 | } |
| 4352 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4353 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4354 | struct nfs_locku_args arg; |
| 4355 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4356 | struct nfs4_lock_state *lsp; |
| 4357 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4358 | struct file_lock fl; |
| 4359 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4360 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4361 | }; |
| 4362 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4363 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4364 | struct nfs_open_context *ctx, |
| 4365 | struct nfs4_lock_state *lsp, |
| 4366 | struct nfs_seqid *seqid) |
| 4367 | { |
| 4368 | struct nfs4_unlockdata *p; |
| 4369 | struct inode *inode = lsp->ls_state->inode; |
| 4370 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4371 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4372 | if (p == NULL) |
| 4373 | return NULL; |
| 4374 | p->arg.fh = NFS_FH(inode); |
| 4375 | p->arg.fl = &p->fl; |
| 4376 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4377 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4378 | p->arg.stateid = &lsp->ls_stateid; |
| 4379 | p->lsp = lsp; |
| 4380 | atomic_inc(&lsp->ls_count); |
| 4381 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4382 | p->ctx = get_nfs_open_context(ctx); |
| 4383 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4384 | p->server = NFS_SERVER(inode); |
| 4385 | return p; |
| 4386 | } |
| 4387 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4388 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4389 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4390 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4391 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4392 | nfs4_put_lock_state(calldata->lsp); |
| 4393 | put_nfs_open_context(calldata->ctx); |
| 4394 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4395 | } |
| 4396 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4397 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4398 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4399 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4400 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4401 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4402 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4403 | switch (task->tk_status) { |
| 4404 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4405 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4406 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4407 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4408 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4409 | case -NFS4ERR_BAD_STATEID: |
| 4410 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4411 | case -NFS4ERR_STALE_STATEID: |
| 4412 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4413 | break; |
| 4414 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4415 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4416 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4417 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4418 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4419 | } |
| 4420 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4421 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4422 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4423 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4425 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4426 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4427 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4428 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4429 | task->tk_action = NULL; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 4430 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4431 | return; |
| 4432 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4433 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4434 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4435 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4436 | &calldata->res.seq_res, |
| 4437 | task) != 0) |
| 4438 | nfs_release_seqid(calldata->arg.seqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | } |
| 4440 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4441 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4442 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4443 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4444 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4445 | }; |
| 4446 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4447 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4448 | struct nfs_open_context *ctx, |
| 4449 | struct nfs4_lock_state *lsp, |
| 4450 | struct nfs_seqid *seqid) |
| 4451 | { |
| 4452 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4453 | struct rpc_message msg = { |
| 4454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4455 | .rpc_cred = ctx->cred, |
| 4456 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4457 | struct rpc_task_setup task_setup_data = { |
| 4458 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4459 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4460 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4461 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4462 | .flags = RPC_TASK_ASYNC, |
| 4463 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4464 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4465 | /* Ensure this is an unlock - when canceling a lock, the |
| 4466 | * canceled lock is passed in, and it won't be an unlock. |
| 4467 | */ |
| 4468 | fl->fl_type = F_UNLCK; |
| 4469 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4470 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4471 | if (data == NULL) { |
| 4472 | nfs_free_seqid(seqid); |
| 4473 | return ERR_PTR(-ENOMEM); |
| 4474 | } |
| 4475 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4476 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4477 | msg.rpc_argp = &data->arg; |
| 4478 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4479 | task_setup_data.callback_data = data; |
| 4480 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4481 | } |
| 4482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4484 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4485 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4486 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4487 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4488 | struct rpc_task *task; |
| 4489 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4490 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4492 | status = nfs4_set_lock_state(state, request); |
| 4493 | /* Unlock _before_ we do the RPC call */ |
| 4494 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4495 | down_read(&nfsi->rwsem); |
| 4496 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4497 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4498 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4499 | } |
| 4500 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4501 | if (status != 0) |
| 4502 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4503 | /* Is this a delegated lock? */ |
| 4504 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4505 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4506 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4507 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4508 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4509 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4510 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4511 | 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] | 4512 | status = PTR_ERR(task); |
| 4513 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4514 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4515 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4516 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4517 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4518 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4519 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4522 | struct nfs4_lockdata { |
| 4523 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4524 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4525 | struct nfs4_lock_state *lsp; |
| 4526 | struct nfs_open_context *ctx; |
| 4527 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4528 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4529 | int rpc_status; |
| 4530 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4531 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4532 | }; |
| 4533 | |
| 4534 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4535 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4536 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4537 | { |
| 4538 | struct nfs4_lockdata *p; |
| 4539 | struct inode *inode = lsp->ls_state->inode; |
| 4540 | struct nfs_server *server = NFS_SERVER(inode); |
| 4541 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4542 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4543 | if (p == NULL) |
| 4544 | return NULL; |
| 4545 | |
| 4546 | p->arg.fh = NFS_FH(inode); |
| 4547 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4548 | 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] | 4549 | if (p->arg.open_seqid == NULL) |
| 4550 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4551 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4552 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4553 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4554 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4555 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4556 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4557 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4558 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4559 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4560 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4561 | atomic_inc(&lsp->ls_count); |
| 4562 | p->ctx = get_nfs_open_context(ctx); |
| 4563 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4564 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4565 | out_free_seqid: |
| 4566 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4567 | out_free: |
| 4568 | kfree(p); |
| 4569 | return NULL; |
| 4570 | } |
| 4571 | |
| 4572 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4573 | { |
| 4574 | struct nfs4_lockdata *data = calldata; |
| 4575 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4577 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4578 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4579 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4580 | /* Do we need to do an open_to_lock_owner? */ |
| 4581 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4582 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4583 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4584 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4585 | data->arg.open_stateid = &state->stateid; |
| 4586 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4587 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4588 | } else |
| 4589 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4590 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4591 | if (nfs4_setup_sequence(data->server, |
| 4592 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4593 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4594 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4595 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4596 | nfs_release_seqid(data->arg.open_seqid); |
| 4597 | out_release_lock_seqid: |
| 4598 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4599 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4602 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4603 | { |
| 4604 | struct nfs4_lockdata *data = calldata; |
| 4605 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4606 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4607 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4608 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4609 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4610 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4611 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4612 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4613 | if (data->rpc_status == 0) |
| 4614 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4615 | else |
| 4616 | goto out; |
| 4617 | } |
| 4618 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4619 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4620 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4621 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4622 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4623 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4624 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | static void nfs4_lock_release(void *calldata) |
| 4628 | { |
| 4629 | struct nfs4_lockdata *data = calldata; |
| 4630 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4631 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4632 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4633 | if (data->cancelled != 0) { |
| 4634 | struct rpc_task *task; |
| 4635 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4636 | data->arg.lock_seqid); |
| 4637 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4638 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4639 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4640 | } else |
| 4641 | nfs_free_seqid(data->arg.lock_seqid); |
| 4642 | nfs4_put_lock_state(data->lsp); |
| 4643 | put_nfs_open_context(data->ctx); |
| 4644 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4645 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4649 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4650 | .rpc_call_done = nfs4_lock_done, |
| 4651 | .rpc_release = nfs4_lock_release, |
| 4652 | }; |
| 4653 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4654 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4655 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4656 | switch (error) { |
| 4657 | case -NFS4ERR_ADMIN_REVOKED: |
| 4658 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4659 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4660 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4661 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4662 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4663 | break; |
| 4664 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4665 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4666 | case -NFS4ERR_EXPIRED: |
| 4667 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4668 | }; |
| 4669 | } |
| 4670 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4671 | 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] | 4672 | { |
| 4673 | struct nfs4_lockdata *data; |
| 4674 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4675 | struct rpc_message msg = { |
| 4676 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4677 | .rpc_cred = state->owner->so_cred, |
| 4678 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4679 | struct rpc_task_setup task_setup_data = { |
| 4680 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4681 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4682 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4683 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4684 | .flags = RPC_TASK_ASYNC, |
| 4685 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4686 | int ret; |
| 4687 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4688 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4689 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4690 | fl->fl_u.nfs4_fl.owner, |
| 4691 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4692 | if (data == NULL) |
| 4693 | return -ENOMEM; |
| 4694 | if (IS_SETLKW(cmd)) |
| 4695 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4696 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4697 | msg.rpc_argp = &data->arg; |
| 4698 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4699 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4700 | if (recovery_type > NFS_LOCK_NEW) { |
| 4701 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4702 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4703 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4704 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4705 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4706 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4707 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4708 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4709 | if (ret == 0) { |
| 4710 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4711 | if (ret) |
| 4712 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4713 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4714 | } else |
| 4715 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4716 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4717 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4718 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4722 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4723 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4724 | struct nfs4_exception exception = { |
| 4725 | .inode = state->inode, |
| 4726 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4727 | int err; |
| 4728 | |
| 4729 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4730 | /* Cache the lock if possible... */ |
| 4731 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4732 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4733 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4734 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4735 | break; |
| 4736 | nfs4_handle_exception(server, err, &exception); |
| 4737 | } while (exception.retry); |
| 4738 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4742 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4743 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4744 | struct nfs4_exception exception = { |
| 4745 | .inode = state->inode, |
| 4746 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4747 | int err; |
| 4748 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4749 | err = nfs4_set_lock_state(state, request); |
| 4750 | if (err != 0) |
| 4751 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4752 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4753 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4754 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4755 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4756 | switch (err) { |
| 4757 | default: |
| 4758 | goto out; |
| 4759 | case -NFS4ERR_GRACE: |
| 4760 | case -NFS4ERR_DELAY: |
| 4761 | nfs4_handle_exception(server, err, &exception); |
| 4762 | err = 0; |
| 4763 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4764 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4765 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4766 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | } |
| 4768 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4769 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4770 | /** |
| 4771 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4772 | * |
| 4773 | * @state: NFSv4 state for an inode |
| 4774 | * |
| 4775 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4776 | * Otherwise a negative NFS4ERR value is returned. |
| 4777 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4778 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4779 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4780 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4781 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4782 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4783 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4784 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4785 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4786 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4787 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4788 | /* Free the stateid unless the server |
| 4789 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4790 | if (status != -NFS4ERR_BAD_STATEID) |
| 4791 | nfs41_free_stateid(server, |
| 4792 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4793 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4794 | ret = status; |
| 4795 | } |
| 4796 | } |
| 4797 | }; |
| 4798 | |
| 4799 | return ret; |
| 4800 | } |
| 4801 | |
| 4802 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4803 | { |
| 4804 | int status = NFS_OK; |
| 4805 | |
| 4806 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4807 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4808 | if (status != NFS_OK) |
| 4809 | status = nfs4_lock_expired(state, request); |
| 4810 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4811 | } |
| 4812 | #endif |
| 4813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4815 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4816 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4817 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4818 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4820 | if ((fl_flags & FL_POSIX) && |
| 4821 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4822 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4823 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4824 | status = nfs4_set_lock_state(state, request); |
| 4825 | if (status != 0) |
| 4826 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4827 | request->fl_flags |= FL_ACCESS; |
| 4828 | status = do_vfs_lock(request->fl_file, request); |
| 4829 | if (status < 0) |
| 4830 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4831 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4832 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4833 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4834 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4835 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4836 | status = do_vfs_lock(request->fl_file, request); |
| 4837 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4838 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4839 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4840 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4841 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4842 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4843 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4844 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4845 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4846 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4847 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4848 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4849 | out: |
| 4850 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | return status; |
| 4852 | } |
| 4853 | |
| 4854 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4855 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4856 | struct nfs4_exception exception = { |
| 4857 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4858 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4859 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | int err; |
| 4861 | |
| 4862 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4863 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4864 | if (err == -NFS4ERR_DENIED) |
| 4865 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4867 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | } while (exception.retry); |
| 4869 | return err; |
| 4870 | } |
| 4871 | |
| 4872 | static int |
| 4873 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4874 | { |
| 4875 | struct nfs_open_context *ctx; |
| 4876 | struct nfs4_state *state; |
| 4877 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4878 | int status; |
| 4879 | |
| 4880 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4881 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | state = ctx->state; |
| 4883 | |
| 4884 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4885 | return -EINVAL; |
| 4886 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4887 | if (IS_GETLK(cmd)) { |
| 4888 | if (state != NULL) |
| 4889 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4890 | return 0; |
| 4891 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | |
| 4893 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4894 | return -EINVAL; |
| 4895 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4896 | if (request->fl_type == F_UNLCK) { |
| 4897 | if (state != NULL) |
| 4898 | return nfs4_proc_unlck(state, cmd, request); |
| 4899 | return 0; |
| 4900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4902 | if (state == NULL) |
| 4903 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4904 | /* |
| 4905 | * Don't rely on the VFS having checked the file open mode, |
| 4906 | * since it won't do this for flock() locks. |
| 4907 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4908 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4909 | case F_RDLCK: |
| 4910 | if (!(filp->f_mode & FMODE_READ)) |
| 4911 | return -EBADF; |
| 4912 | break; |
| 4913 | case F_WRLCK: |
| 4914 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4915 | return -EBADF; |
| 4916 | } |
| 4917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | do { |
| 4919 | status = nfs4_proc_setlk(state, cmd, request); |
| 4920 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4921 | break; |
| 4922 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4923 | status = -ERESTARTSYS; |
| 4924 | if (signalled()) |
| 4925 | break; |
| 4926 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | return status; |
| 4928 | } |
| 4929 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4930 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4931 | { |
| 4932 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4933 | struct nfs4_exception exception = { }; |
| 4934 | int err; |
| 4935 | |
| 4936 | err = nfs4_set_lock_state(state, fl); |
| 4937 | if (err != 0) |
| 4938 | goto out; |
| 4939 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4940 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4941 | switch (err) { |
| 4942 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4943 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4944 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4945 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4946 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4947 | goto out; |
| 4948 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4949 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4950 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4951 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4952 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4953 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4954 | case -NFS4ERR_BADSESSION: |
| 4955 | case -NFS4ERR_BADSLOT: |
| 4956 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4957 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4958 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4959 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4960 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4961 | case -ERESTARTSYS: |
| 4962 | /* |
| 4963 | * The show must go on: exit, but mark the |
| 4964 | * stateid as needing recovery. |
| 4965 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4966 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4967 | case -NFS4ERR_ADMIN_REVOKED: |
| 4968 | case -NFS4ERR_BAD_STATEID: |
| 4969 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4970 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4971 | err = 0; |
| 4972 | goto out; |
| 4973 | case -ENOMEM: |
| 4974 | case -NFS4ERR_DENIED: |
| 4975 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4976 | err = 0; |
| 4977 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4978 | case -NFS4ERR_DELAY: |
| 4979 | break; |
| 4980 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4981 | err = nfs4_handle_exception(server, err, &exception); |
| 4982 | } while (exception.retry); |
| 4983 | out: |
| 4984 | return err; |
| 4985 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4986 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4987 | struct nfs_release_lockowner_data { |
| 4988 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4989 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4990 | struct nfs_release_lockowner_args args; |
| 4991 | }; |
| 4992 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4993 | static void nfs4_release_lockowner_release(void *calldata) |
| 4994 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4995 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4996 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4997 | kfree(calldata); |
| 4998 | } |
| 4999 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5000 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5001 | .rpc_release = nfs4_release_lockowner_release, |
| 5002 | }; |
| 5003 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5004 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5005 | { |
| 5006 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5007 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5008 | struct rpc_message msg = { |
| 5009 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5010 | }; |
| 5011 | |
| 5012 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5013 | return -EINVAL; |
| 5014 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5015 | if (!data) |
| 5016 | return -ENOMEM; |
| 5017 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5018 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5019 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5020 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5021 | data->args.lock_owner.s_dev = server->s_dev; |
| 5022 | msg.rpc_argp = &data->args; |
| 5023 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5024 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5025 | } |
| 5026 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5027 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5028 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5029 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5030 | const void *buf, size_t buflen, |
| 5031 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5032 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5033 | if (strcmp(key, "") != 0) |
| 5034 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5035 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5036 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5039 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5040 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5041 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5042 | if (strcmp(key, "") != 0) |
| 5043 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5044 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5045 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5046 | } |
| 5047 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5048 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5049 | size_t list_len, const char *name, |
| 5050 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5051 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5052 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5053 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5054 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5055 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5056 | |
| 5057 | if (list && len <= list_len) |
| 5058 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5059 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5060 | } |
| 5061 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5062 | /* |
| 5063 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5064 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5065 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5066 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5067 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5068 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5069 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5070 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5071 | return; |
| 5072 | |
| 5073 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5074 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5075 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5076 | fattr->nlink = 2; |
| 5077 | } |
| 5078 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5079 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5080 | const struct qstr *name, |
| 5081 | struct nfs4_fs_locations *fs_locations, |
| 5082 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5083 | { |
| 5084 | struct nfs_server *server = NFS_SERVER(dir); |
| 5085 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5086 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5087 | }; |
| 5088 | struct nfs4_fs_locations_arg args = { |
| 5089 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5090 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5091 | .page = page, |
| 5092 | .bitmask = bitmask, |
| 5093 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5094 | struct nfs4_fs_locations_res res = { |
| 5095 | .fs_locations = fs_locations, |
| 5096 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5097 | struct rpc_message msg = { |
| 5098 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5099 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5100 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5101 | }; |
| 5102 | int status; |
| 5103 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5104 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5105 | |
| 5106 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5107 | * is not supported */ |
| 5108 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5109 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5110 | else |
| 5111 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5112 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5113 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5114 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5115 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5116 | 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] | 5117 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5118 | return status; |
| 5119 | } |
| 5120 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5121 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5122 | const struct qstr *name, |
| 5123 | struct nfs4_fs_locations *fs_locations, |
| 5124 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5125 | { |
| 5126 | struct nfs4_exception exception = { }; |
| 5127 | int err; |
| 5128 | do { |
| 5129 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5130 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5131 | &exception); |
| 5132 | } while (exception.retry); |
| 5133 | return err; |
| 5134 | } |
| 5135 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5136 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5137 | { |
| 5138 | int status; |
| 5139 | struct nfs4_secinfo_arg args = { |
| 5140 | .dir_fh = NFS_FH(dir), |
| 5141 | .name = name, |
| 5142 | }; |
| 5143 | struct nfs4_secinfo_res res = { |
| 5144 | .flavors = flavors, |
| 5145 | }; |
| 5146 | struct rpc_message msg = { |
| 5147 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5148 | .rpc_argp = &args, |
| 5149 | .rpc_resp = &res, |
| 5150 | }; |
| 5151 | |
| 5152 | dprintk("NFS call secinfo %s\n", name->name); |
| 5153 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5154 | dprintk("NFS reply secinfo: %d\n", status); |
| 5155 | return status; |
| 5156 | } |
| 5157 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5158 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5159 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5160 | { |
| 5161 | struct nfs4_exception exception = { }; |
| 5162 | int err; |
| 5163 | do { |
| 5164 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5165 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5166 | &exception); |
| 5167 | } while (exception.retry); |
| 5168 | return err; |
| 5169 | } |
| 5170 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5171 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5172 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5173 | * Check the exchange flags returned by the server for invalid flags, having |
| 5174 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5175 | * DS flags set. |
| 5176 | */ |
| 5177 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5178 | { |
| 5179 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5180 | goto out_inval; |
| 5181 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5182 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5183 | goto out_inval; |
| 5184 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5185 | goto out_inval; |
| 5186 | return NFS_OK; |
| 5187 | out_inval: |
| 5188 | return -NFS4ERR_INVAL; |
| 5189 | } |
| 5190 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5191 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5192 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5193 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5194 | { |
| 5195 | if (a->server_scope_sz == b->server_scope_sz && |
| 5196 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5197 | return true; |
| 5198 | |
| 5199 | return false; |
| 5200 | } |
| 5201 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5202 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5203 | * nfs4_proc_bind_conn_to_session() |
| 5204 | * |
| 5205 | * The 4.1 client currently uses the same TCP connection for the |
| 5206 | * fore and backchannel. |
| 5207 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5208 | 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] | 5209 | { |
| 5210 | int status; |
| 5211 | struct nfs41_bind_conn_to_session_res res; |
| 5212 | struct rpc_message msg = { |
| 5213 | .rpc_proc = |
| 5214 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5215 | .rpc_argp = clp, |
| 5216 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5217 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5218 | }; |
| 5219 | |
| 5220 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5221 | |
| 5222 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5223 | if (unlikely(res.session == NULL)) { |
| 5224 | status = -ENOMEM; |
| 5225 | goto out; |
| 5226 | } |
| 5227 | |
| 5228 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5229 | if (status == 0) { |
| 5230 | if (memcmp(res.session->sess_id.data, |
| 5231 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5232 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5233 | status = -EIO; |
| 5234 | goto out_session; |
| 5235 | } |
| 5236 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5237 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5238 | __func__); |
| 5239 | status = -EIO; |
| 5240 | goto out_session; |
| 5241 | } |
| 5242 | if (res.use_conn_in_rdma_mode) { |
| 5243 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5244 | __func__); |
| 5245 | status = -EIO; |
| 5246 | goto out_session; |
| 5247 | } |
| 5248 | } |
| 5249 | out_session: |
| 5250 | kfree(res.session); |
| 5251 | out: |
| 5252 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5253 | return status; |
| 5254 | } |
| 5255 | |
| 5256 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5257 | * nfs4_proc_exchange_id() |
| 5258 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5259 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5260 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5261 | * Since the clientid has expired, all compounds using sessions |
| 5262 | * associated with the stale clientid will be returning |
| 5263 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5264 | * be in some phase of session reset. |
| 5265 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5266 | 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] | 5267 | { |
| 5268 | nfs4_verifier verifier; |
| 5269 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5270 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5271 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5272 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5273 | }; |
| 5274 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5275 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5276 | }; |
| 5277 | int status; |
| 5278 | struct rpc_message msg = { |
| 5279 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5280 | .rpc_argp = &args, |
| 5281 | .rpc_resp = &res, |
| 5282 | .rpc_cred = cred, |
| 5283 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5284 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5285 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5286 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5287 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5288 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5289 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5290 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5291 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5292 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5293 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5294 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5295 | status = -ENOMEM; |
| 5296 | goto out; |
| 5297 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5298 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5299 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5300 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5301 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5302 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5303 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5304 | } |
| 5305 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5306 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5307 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5308 | status = -ENOMEM; |
| 5309 | goto out_server_scope; |
| 5310 | } |
| 5311 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5312 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5313 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5314 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5315 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5316 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5317 | clp->cl_clientid = res.clientid; |
| 5318 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5319 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5320 | clp->cl_seqid = res.seqid; |
| 5321 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5322 | kfree(clp->cl_serverowner); |
| 5323 | clp->cl_serverowner = res.server_owner; |
| 5324 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5325 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5326 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5327 | kfree(clp->cl_implid); |
| 5328 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5329 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5330 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5331 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5332 | res.server_scope)) { |
| 5333 | dprintk("%s: server_scope mismatch detected\n", |
| 5334 | __func__); |
| 5335 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5336 | kfree(clp->cl_serverscope); |
| 5337 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5338 | } |
| 5339 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5340 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5341 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5342 | goto out; |
| 5343 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5344 | } else |
| 5345 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5346 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5347 | out_server_owner: |
| 5348 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5349 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5350 | kfree(res.server_scope); |
| 5351 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5352 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5353 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5354 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5355 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5356 | clp->cl_implid->date.seconds, |
| 5357 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5358 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5359 | return status; |
| 5360 | } |
| 5361 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5362 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5363 | struct rpc_cred *cred) |
| 5364 | { |
| 5365 | struct rpc_message msg = { |
| 5366 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5367 | .rpc_argp = clp, |
| 5368 | .rpc_cred = cred, |
| 5369 | }; |
| 5370 | int status; |
| 5371 | |
| 5372 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5373 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5374 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5375 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5376 | return status; |
| 5377 | } |
| 5378 | |
| 5379 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5380 | struct rpc_cred *cred) |
| 5381 | { |
| 5382 | unsigned int loop; |
| 5383 | int ret; |
| 5384 | |
| 5385 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5386 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5387 | switch (ret) { |
| 5388 | case -NFS4ERR_DELAY: |
| 5389 | case -NFS4ERR_CLIENTID_BUSY: |
| 5390 | ssleep(1); |
| 5391 | break; |
| 5392 | default: |
| 5393 | return ret; |
| 5394 | } |
| 5395 | } |
| 5396 | return 0; |
| 5397 | } |
| 5398 | |
| 5399 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5400 | { |
| 5401 | struct rpc_cred *cred; |
| 5402 | int ret = 0; |
| 5403 | |
| 5404 | if (clp->cl_mvops->minor_version < 1) |
| 5405 | goto out; |
| 5406 | if (clp->cl_exchange_flags == 0) |
| 5407 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5408 | if (clp->cl_preserve_clid) |
| 5409 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5410 | cred = nfs4_get_exchange_id_cred(clp); |
| 5411 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5412 | if (cred) |
| 5413 | put_rpccred(cred); |
| 5414 | switch (ret) { |
| 5415 | case 0: |
| 5416 | case -NFS4ERR_STALE_CLIENTID: |
| 5417 | clp->cl_exchange_flags = 0; |
| 5418 | } |
| 5419 | out: |
| 5420 | return ret; |
| 5421 | } |
| 5422 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5423 | struct nfs4_get_lease_time_data { |
| 5424 | struct nfs4_get_lease_time_args *args; |
| 5425 | struct nfs4_get_lease_time_res *res; |
| 5426 | struct nfs_client *clp; |
| 5427 | }; |
| 5428 | |
| 5429 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5430 | void *calldata) |
| 5431 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5432 | struct nfs4_get_lease_time_data *data = |
| 5433 | (struct nfs4_get_lease_time_data *)calldata; |
| 5434 | |
| 5435 | dprintk("--> %s\n", __func__); |
| 5436 | /* just setup sequence, do not trigger session recovery |
| 5437 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5438 | nfs41_setup_sequence(data->clp->cl_session, |
| 5439 | &data->args->la_seq_args, |
| 5440 | &data->res->lr_seq_res, |
| 5441 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5442 | dprintk("<-- %s\n", __func__); |
| 5443 | } |
| 5444 | |
| 5445 | /* |
| 5446 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5447 | * from sequence operation or clientid errors. |
| 5448 | */ |
| 5449 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5450 | { |
| 5451 | struct nfs4_get_lease_time_data *data = |
| 5452 | (struct nfs4_get_lease_time_data *)calldata; |
| 5453 | |
| 5454 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5455 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5456 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5457 | switch (task->tk_status) { |
| 5458 | case -NFS4ERR_DELAY: |
| 5459 | case -NFS4ERR_GRACE: |
| 5460 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5461 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5462 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5463 | /* fall through */ |
| 5464 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5465 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5466 | return; |
| 5467 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5468 | dprintk("<-- %s\n", __func__); |
| 5469 | } |
| 5470 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5471 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5472 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5473 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5474 | }; |
| 5475 | |
| 5476 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5477 | { |
| 5478 | struct rpc_task *task; |
| 5479 | struct nfs4_get_lease_time_args args; |
| 5480 | struct nfs4_get_lease_time_res res = { |
| 5481 | .lr_fsinfo = fsinfo, |
| 5482 | }; |
| 5483 | struct nfs4_get_lease_time_data data = { |
| 5484 | .args = &args, |
| 5485 | .res = &res, |
| 5486 | .clp = clp, |
| 5487 | }; |
| 5488 | struct rpc_message msg = { |
| 5489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5490 | .rpc_argp = &args, |
| 5491 | .rpc_resp = &res, |
| 5492 | }; |
| 5493 | struct rpc_task_setup task_setup = { |
| 5494 | .rpc_client = clp->cl_rpcclient, |
| 5495 | .rpc_message = &msg, |
| 5496 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5497 | .callback_data = &data, |
| 5498 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5499 | }; |
| 5500 | int status; |
| 5501 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5502 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5503 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5504 | dprintk("--> %s\n", __func__); |
| 5505 | task = rpc_run_task(&task_setup); |
| 5506 | |
| 5507 | if (IS_ERR(task)) |
| 5508 | status = PTR_ERR(task); |
| 5509 | else { |
| 5510 | status = task->tk_status; |
| 5511 | rpc_put_task(task); |
| 5512 | } |
| 5513 | dprintk("<-- %s return %d\n", __func__, status); |
| 5514 | |
| 5515 | return status; |
| 5516 | } |
| 5517 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5518 | /* |
| 5519 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5520 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5521 | * use them. |
| 5522 | * |
| 5523 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5524 | * always set csa_cachethis to FALSE because the current implementation |
| 5525 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5526 | */ |
| 5527 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5528 | { |
| 5529 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5530 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5531 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5532 | |
| 5533 | if (mxrqst_sz == 0) |
| 5534 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5535 | if (mxresp_sz == 0) |
| 5536 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5537 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5538 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5539 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5540 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5541 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5542 | |
| 5543 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5544 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5545 | __func__, |
| 5546 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5547 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5548 | |
| 5549 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5550 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5551 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5552 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5553 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5554 | args->bc_attrs.max_reqs = 1; |
| 5555 | |
| 5556 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5557 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5558 | __func__, |
| 5559 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5560 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5561 | args->bc_attrs.max_reqs); |
| 5562 | } |
| 5563 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5564 | 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] | 5565 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5566 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5567 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5568 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5569 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5570 | return -EINVAL; |
| 5571 | /* |
| 5572 | * Our requested max_ops is the minimum we need; we're not |
| 5573 | * prepared to break up compounds into smaller pieces than that. |
| 5574 | * So, no point even trying to continue if the server won't |
| 5575 | * cooperate: |
| 5576 | */ |
| 5577 | if (rcvd->max_ops < sent->max_ops) |
| 5578 | return -EINVAL; |
| 5579 | if (rcvd->max_reqs == 0) |
| 5580 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5581 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5582 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5583 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5584 | } |
| 5585 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5586 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5587 | { |
| 5588 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5589 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5590 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5591 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5592 | return -EINVAL; |
| 5593 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5594 | return -EINVAL; |
| 5595 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5596 | return -EINVAL; |
| 5597 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5598 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5599 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5600 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5601 | return -EINVAL; |
| 5602 | return 0; |
| 5603 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5604 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5605 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5606 | struct nfs4_session *session) |
| 5607 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5608 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5609 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5610 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5611 | if (ret) |
| 5612 | return ret; |
| 5613 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5614 | } |
| 5615 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5616 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5617 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5618 | { |
| 5619 | struct nfs4_session *session = clp->cl_session; |
| 5620 | struct nfs41_create_session_args args = { |
| 5621 | .client = clp, |
| 5622 | .cb_program = NFS4_CALLBACK, |
| 5623 | }; |
| 5624 | struct nfs41_create_session_res res = { |
| 5625 | .client = clp, |
| 5626 | }; |
| 5627 | struct rpc_message msg = { |
| 5628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5629 | .rpc_argp = &args, |
| 5630 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5631 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5632 | }; |
| 5633 | int status; |
| 5634 | |
| 5635 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5636 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5637 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5638 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5639 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5640 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5641 | /* Verify the session's negotiated channel_attrs values */ |
| 5642 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5643 | /* Increment the clientid slot sequence id */ |
| 5644 | clp->cl_seqid++; |
| 5645 | } |
| 5646 | |
| 5647 | return status; |
| 5648 | } |
| 5649 | |
| 5650 | /* |
| 5651 | * Issues a CREATE_SESSION operation to the server. |
| 5652 | * It is the responsibility of the caller to verify the session is |
| 5653 | * expired before calling this routine. |
| 5654 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5655 | 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] | 5656 | { |
| 5657 | int status; |
| 5658 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5659 | struct nfs4_session *session = clp->cl_session; |
| 5660 | |
| 5661 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5662 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5663 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5664 | if (status) |
| 5665 | goto out; |
| 5666 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5667 | /* Init or reset the session slot tables */ |
| 5668 | status = nfs4_setup_session_slot_tables(session); |
| 5669 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5670 | if (status) |
| 5671 | goto out; |
| 5672 | |
| 5673 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5674 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5675 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5676 | out: |
| 5677 | dprintk("<-- %s\n", __func__); |
| 5678 | return status; |
| 5679 | } |
| 5680 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5681 | /* |
| 5682 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5683 | * The caller must serialize access to this routine. |
| 5684 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5685 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5686 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5687 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5688 | struct rpc_message msg = { |
| 5689 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5690 | .rpc_argp = session, |
| 5691 | .rpc_cred = cred, |
| 5692 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5693 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5694 | |
| 5695 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5696 | |
| 5697 | /* session is still being setup */ |
| 5698 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5699 | return status; |
| 5700 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5701 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5702 | |
| 5703 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5704 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5705 | "Session has been destroyed regardless...\n", status); |
| 5706 | |
| 5707 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5708 | return status; |
| 5709 | } |
| 5710 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5711 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5712 | * Renew the cl_session lease. |
| 5713 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5714 | struct nfs4_sequence_data { |
| 5715 | struct nfs_client *clp; |
| 5716 | struct nfs4_sequence_args args; |
| 5717 | struct nfs4_sequence_res res; |
| 5718 | }; |
| 5719 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5720 | static void nfs41_sequence_release(void *data) |
| 5721 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5722 | struct nfs4_sequence_data *calldata = data; |
| 5723 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5724 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5725 | if (atomic_read(&clp->cl_count) > 1) |
| 5726 | nfs4_schedule_state_renewal(clp); |
| 5727 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5728 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5729 | } |
| 5730 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5731 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5732 | { |
| 5733 | switch(task->tk_status) { |
| 5734 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5735 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5736 | return -EAGAIN; |
| 5737 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5738 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5739 | } |
| 5740 | return 0; |
| 5741 | } |
| 5742 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5743 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5744 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5745 | struct nfs4_sequence_data *calldata = data; |
| 5746 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5747 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5748 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5749 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5750 | |
| 5751 | if (task->tk_status < 0) { |
| 5752 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5753 | if (atomic_read(&clp->cl_count) == 1) |
| 5754 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5755 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5756 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5757 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5758 | return; |
| 5759 | } |
| 5760 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5761 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5762 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5763 | dprintk("<-- %s\n", __func__); |
| 5764 | } |
| 5765 | |
| 5766 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5767 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5768 | struct nfs4_sequence_data *calldata = data; |
| 5769 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5770 | struct nfs4_sequence_args *args; |
| 5771 | struct nfs4_sequence_res *res; |
| 5772 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5773 | args = task->tk_msg.rpc_argp; |
| 5774 | res = task->tk_msg.rpc_resp; |
| 5775 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5776 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5780 | .rpc_call_done = nfs41_sequence_call_done, |
| 5781 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5782 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5783 | }; |
| 5784 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5785 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5786 | struct rpc_cred *cred, |
| 5787 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5788 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5789 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5790 | struct rpc_message msg = { |
| 5791 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5792 | .rpc_cred = cred, |
| 5793 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5794 | struct rpc_task_setup task_setup_data = { |
| 5795 | .rpc_client = clp->cl_rpcclient, |
| 5796 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5797 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5798 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5799 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5800 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5801 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5802 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5803 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5804 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5805 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5806 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5807 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5808 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5809 | if (is_privileged) |
| 5810 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5811 | msg.rpc_argp = &calldata->args; |
| 5812 | msg.rpc_resp = &calldata->res; |
| 5813 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5814 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5815 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5816 | return rpc_run_task(&task_setup_data); |
| 5817 | } |
| 5818 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5819 | 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] | 5820 | { |
| 5821 | struct rpc_task *task; |
| 5822 | int ret = 0; |
| 5823 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5824 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5825 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5826 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5827 | if (IS_ERR(task)) |
| 5828 | ret = PTR_ERR(task); |
| 5829 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5830 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5831 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5832 | return ret; |
| 5833 | } |
| 5834 | |
| 5835 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5836 | { |
| 5837 | struct rpc_task *task; |
| 5838 | int ret; |
| 5839 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5840 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5841 | if (IS_ERR(task)) { |
| 5842 | ret = PTR_ERR(task); |
| 5843 | goto out; |
| 5844 | } |
| 5845 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5846 | if (!ret) { |
| 5847 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5848 | |
| 5849 | if (task->tk_status == 0) |
| 5850 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5851 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5852 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5853 | rpc_put_task(task); |
| 5854 | out: |
| 5855 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5856 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5857 | } |
| 5858 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5859 | struct nfs4_reclaim_complete_data { |
| 5860 | struct nfs_client *clp; |
| 5861 | struct nfs41_reclaim_complete_args arg; |
| 5862 | struct nfs41_reclaim_complete_res res; |
| 5863 | }; |
| 5864 | |
| 5865 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5866 | { |
| 5867 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5868 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5869 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 5870 | &calldata->arg.seq_args, |
| 5871 | &calldata->res.seq_res, |
| 5872 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5873 | } |
| 5874 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5875 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5876 | { |
| 5877 | switch(task->tk_status) { |
| 5878 | case 0: |
| 5879 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5880 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5881 | break; |
| 5882 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5883 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5884 | /* fall through */ |
| 5885 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5886 | return -EAGAIN; |
| 5887 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5888 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5889 | } |
| 5890 | return 0; |
| 5891 | } |
| 5892 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5893 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5894 | { |
| 5895 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5896 | struct nfs_client *clp = calldata->clp; |
| 5897 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5898 | |
| 5899 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5900 | if (!nfs41_sequence_done(task, res)) |
| 5901 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5902 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5903 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5904 | rpc_restart_call_prepare(task); |
| 5905 | return; |
| 5906 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5907 | dprintk("<-- %s\n", __func__); |
| 5908 | } |
| 5909 | |
| 5910 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5911 | { |
| 5912 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5913 | |
| 5914 | kfree(calldata); |
| 5915 | } |
| 5916 | |
| 5917 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5918 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5919 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5920 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5921 | }; |
| 5922 | |
| 5923 | /* |
| 5924 | * Issue a global reclaim complete. |
| 5925 | */ |
| 5926 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5927 | { |
| 5928 | struct nfs4_reclaim_complete_data *calldata; |
| 5929 | struct rpc_task *task; |
| 5930 | struct rpc_message msg = { |
| 5931 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5932 | }; |
| 5933 | struct rpc_task_setup task_setup_data = { |
| 5934 | .rpc_client = clp->cl_rpcclient, |
| 5935 | .rpc_message = &msg, |
| 5936 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5937 | .flags = RPC_TASK_ASYNC, |
| 5938 | }; |
| 5939 | int status = -ENOMEM; |
| 5940 | |
| 5941 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5942 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5943 | if (calldata == NULL) |
| 5944 | goto out; |
| 5945 | calldata->clp = clp; |
| 5946 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5947 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5948 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5949 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5950 | msg.rpc_argp = &calldata->arg; |
| 5951 | msg.rpc_resp = &calldata->res; |
| 5952 | task_setup_data.callback_data = calldata; |
| 5953 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5954 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5955 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5956 | goto out; |
| 5957 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5958 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5959 | if (status == 0) |
| 5960 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5961 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5962 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5963 | out: |
| 5964 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5965 | return status; |
| 5966 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5967 | |
| 5968 | static void |
| 5969 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5970 | { |
| 5971 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5972 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 5973 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5974 | |
| 5975 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5976 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5977 | * right now covering the LAYOUTGET we are about to send. |
| 5978 | * However, that is not so catastrophic, and there seems |
| 5979 | * to be no way to prevent it completely. |
| 5980 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 5981 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5982 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5983 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5984 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5985 | NFS_I(lgp->args.inode)->layout, |
| 5986 | lgp->args.ctx->state)) { |
| 5987 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5988 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5989 | } |
| 5990 | |
| 5991 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5992 | { |
| 5993 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 5994 | struct inode *inode = lgp->args.inode; |
| 5995 | struct nfs_server *server = NFS_SERVER(inode); |
| 5996 | struct pnfs_layout_hdr *lo; |
| 5997 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5998 | |
| 5999 | dprintk("--> %s\n", __func__); |
| 6000 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6001 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
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 | |
| 6004 | switch (task->tk_status) { |
| 6005 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6006 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6007 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6008 | case -NFS4ERR_RECALLCONFLICT: |
| 6009 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6010 | break; |
| 6011 | case -NFS4ERR_EXPIRED: |
| 6012 | case -NFS4ERR_BAD_STATEID: |
| 6013 | spin_lock(&inode->i_lock); |
| 6014 | lo = NFS_I(inode)->layout; |
| 6015 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6016 | spin_unlock(&inode->i_lock); |
| 6017 | /* If the open stateid was bad, then recover it. */ |
| 6018 | state = lgp->args.ctx->state; |
| 6019 | } else { |
| 6020 | LIST_HEAD(head); |
| 6021 | |
| 6022 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6023 | spin_unlock(&inode->i_lock); |
| 6024 | /* Mark the bad layout state as invalid, then |
| 6025 | * retry using the open stateid. */ |
| 6026 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6027 | } |
| 6028 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6029 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6030 | rpc_restart_call_prepare(task); |
| 6031 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6032 | dprintk("<-- %s\n", __func__); |
| 6033 | } |
| 6034 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6035 | static size_t max_response_pages(struct nfs_server *server) |
| 6036 | { |
| 6037 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6038 | return nfs_page_array_len(0, max_resp_sz); |
| 6039 | } |
| 6040 | |
| 6041 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6042 | { |
| 6043 | int i; |
| 6044 | |
| 6045 | if (!pages) |
| 6046 | return; |
| 6047 | |
| 6048 | for (i = 0; i < size; i++) { |
| 6049 | if (!pages[i]) |
| 6050 | break; |
| 6051 | __free_page(pages[i]); |
| 6052 | } |
| 6053 | kfree(pages); |
| 6054 | } |
| 6055 | |
| 6056 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6057 | { |
| 6058 | struct page **pages; |
| 6059 | int i; |
| 6060 | |
| 6061 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6062 | if (!pages) { |
| 6063 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6064 | return NULL; |
| 6065 | } |
| 6066 | |
| 6067 | for (i = 0; i < size; i++) { |
| 6068 | pages[i] = alloc_page(gfp_flags); |
| 6069 | if (!pages[i]) { |
| 6070 | dprintk("%s: failed to allocate page\n", __func__); |
| 6071 | nfs4_free_pages(pages, size); |
| 6072 | return NULL; |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | return pages; |
| 6077 | } |
| 6078 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6079 | static void nfs4_layoutget_release(void *calldata) |
| 6080 | { |
| 6081 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6082 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6083 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6084 | |
| 6085 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6086 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6087 | put_nfs_open_context(lgp->args.ctx); |
| 6088 | kfree(calldata); |
| 6089 | dprintk("<-- %s\n", __func__); |
| 6090 | } |
| 6091 | |
| 6092 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6093 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6094 | .rpc_call_done = nfs4_layoutget_done, |
| 6095 | .rpc_release = nfs4_layoutget_release, |
| 6096 | }; |
| 6097 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6098 | struct pnfs_layout_segment * |
| 6099 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6100 | { |
| 6101 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6102 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6103 | struct rpc_task *task; |
| 6104 | struct rpc_message msg = { |
| 6105 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6106 | .rpc_argp = &lgp->args, |
| 6107 | .rpc_resp = &lgp->res, |
| 6108 | }; |
| 6109 | struct rpc_task_setup task_setup_data = { |
| 6110 | .rpc_client = server->client, |
| 6111 | .rpc_message = &msg, |
| 6112 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6113 | .callback_data = lgp, |
| 6114 | .flags = RPC_TASK_ASYNC, |
| 6115 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6116 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6117 | int status = 0; |
| 6118 | |
| 6119 | dprintk("--> %s\n", __func__); |
| 6120 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6121 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6122 | if (!lgp->args.layout.pages) { |
| 6123 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6124 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6125 | } |
| 6126 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6127 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6128 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6129 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6130 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6131 | task = rpc_run_task(&task_setup_data); |
| 6132 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6133 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6134 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6135 | if (status == 0) |
| 6136 | status = task->tk_status; |
| 6137 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6138 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6139 | rpc_put_task(task); |
| 6140 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6141 | if (status) |
| 6142 | return ERR_PTR(status); |
| 6143 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6144 | } |
| 6145 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6146 | static void |
| 6147 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6148 | { |
| 6149 | struct nfs4_layoutreturn *lrp = calldata; |
| 6150 | |
| 6151 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6152 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6153 | &lrp->args.seq_args, |
| 6154 | &lrp->res.seq_res, |
| 6155 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6159 | { |
| 6160 | struct nfs4_layoutreturn *lrp = calldata; |
| 6161 | struct nfs_server *server; |
| 6162 | |
| 6163 | dprintk("--> %s\n", __func__); |
| 6164 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6165 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6166 | return; |
| 6167 | |
| 6168 | server = NFS_SERVER(lrp->args.inode); |
| 6169 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6170 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6171 | return; |
| 6172 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6173 | dprintk("<-- %s\n", __func__); |
| 6174 | } |
| 6175 | |
| 6176 | static void nfs4_layoutreturn_release(void *calldata) |
| 6177 | { |
| 6178 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6179 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6180 | |
| 6181 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6182 | spin_lock(&lo->plh_inode->i_lock); |
| 6183 | if (lrp->res.lrs_present) |
| 6184 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6185 | lo->plh_block_lgets--; |
| 6186 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6187 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6188 | kfree(calldata); |
| 6189 | dprintk("<-- %s\n", __func__); |
| 6190 | } |
| 6191 | |
| 6192 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6193 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6194 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6195 | .rpc_release = nfs4_layoutreturn_release, |
| 6196 | }; |
| 6197 | |
| 6198 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6199 | { |
| 6200 | struct rpc_task *task; |
| 6201 | struct rpc_message msg = { |
| 6202 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6203 | .rpc_argp = &lrp->args, |
| 6204 | .rpc_resp = &lrp->res, |
| 6205 | }; |
| 6206 | struct rpc_task_setup task_setup_data = { |
| 6207 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6208 | .rpc_message = &msg, |
| 6209 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6210 | .callback_data = lrp, |
| 6211 | }; |
| 6212 | int status; |
| 6213 | |
| 6214 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6215 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6216 | task = rpc_run_task(&task_setup_data); |
| 6217 | if (IS_ERR(task)) |
| 6218 | return PTR_ERR(task); |
| 6219 | status = task->tk_status; |
| 6220 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6221 | rpc_put_task(task); |
| 6222 | return status; |
| 6223 | } |
| 6224 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6225 | /* |
| 6226 | * Retrieve the list of Data Server devices from the MDS. |
| 6227 | */ |
| 6228 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6229 | const struct nfs_fh *fh, |
| 6230 | struct pnfs_devicelist *devlist) |
| 6231 | { |
| 6232 | struct nfs4_getdevicelist_args args = { |
| 6233 | .fh = fh, |
| 6234 | .layoutclass = server->pnfs_curr_ld->id, |
| 6235 | }; |
| 6236 | struct nfs4_getdevicelist_res res = { |
| 6237 | .devlist = devlist, |
| 6238 | }; |
| 6239 | struct rpc_message msg = { |
| 6240 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6241 | .rpc_argp = &args, |
| 6242 | .rpc_resp = &res, |
| 6243 | }; |
| 6244 | int status; |
| 6245 | |
| 6246 | dprintk("--> %s\n", __func__); |
| 6247 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6248 | &res.seq_res, 0); |
| 6249 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6250 | return status; |
| 6251 | } |
| 6252 | |
| 6253 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6254 | const struct nfs_fh *fh, |
| 6255 | struct pnfs_devicelist *devlist) |
| 6256 | { |
| 6257 | struct nfs4_exception exception = { }; |
| 6258 | int err; |
| 6259 | |
| 6260 | do { |
| 6261 | err = nfs4_handle_exception(server, |
| 6262 | _nfs4_getdevicelist(server, fh, devlist), |
| 6263 | &exception); |
| 6264 | } while (exception.retry); |
| 6265 | |
| 6266 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6267 | err, devlist->num_devs); |
| 6268 | |
| 6269 | return err; |
| 6270 | } |
| 6271 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6272 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6273 | static int |
| 6274 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6275 | { |
| 6276 | struct nfs4_getdeviceinfo_args args = { |
| 6277 | .pdev = pdev, |
| 6278 | }; |
| 6279 | struct nfs4_getdeviceinfo_res res = { |
| 6280 | .pdev = pdev, |
| 6281 | }; |
| 6282 | struct rpc_message msg = { |
| 6283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6284 | .rpc_argp = &args, |
| 6285 | .rpc_resp = &res, |
| 6286 | }; |
| 6287 | int status; |
| 6288 | |
| 6289 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6290 | 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] | 6291 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6292 | |
| 6293 | return status; |
| 6294 | } |
| 6295 | |
| 6296 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6297 | { |
| 6298 | struct nfs4_exception exception = { }; |
| 6299 | int err; |
| 6300 | |
| 6301 | do { |
| 6302 | err = nfs4_handle_exception(server, |
| 6303 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6304 | &exception); |
| 6305 | } while (exception.retry); |
| 6306 | return err; |
| 6307 | } |
| 6308 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6309 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6310 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6311 | { |
| 6312 | struct nfs4_layoutcommit_data *data = calldata; |
| 6313 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6314 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6315 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6316 | nfs41_setup_sequence(session, |
| 6317 | &data->args.seq_args, |
| 6318 | &data->res.seq_res, |
| 6319 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | static void |
| 6323 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6324 | { |
| 6325 | struct nfs4_layoutcommit_data *data = calldata; |
| 6326 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6327 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6328 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6329 | return; |
| 6330 | |
| 6331 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6332 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6333 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6334 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6335 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6336 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6337 | break; |
| 6338 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6339 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6340 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6341 | break; |
| 6342 | default: |
| 6343 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6344 | rpc_restart_call_prepare(task); |
| 6345 | return; |
| 6346 | } |
| 6347 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | static void nfs4_layoutcommit_release(void *calldata) |
| 6351 | { |
| 6352 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6353 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6354 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6355 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6356 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6357 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6358 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6359 | list_del_init(&lseg->pls_lc_list); |
| 6360 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6361 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6362 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6363 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6364 | |
| 6365 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6366 | smp_mb__after_clear_bit(); |
| 6367 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6368 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6369 | put_rpccred(data->cred); |
| 6370 | kfree(data); |
| 6371 | } |
| 6372 | |
| 6373 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6374 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6375 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6376 | .rpc_release = nfs4_layoutcommit_release, |
| 6377 | }; |
| 6378 | |
| 6379 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6380 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6381 | { |
| 6382 | struct rpc_message msg = { |
| 6383 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6384 | .rpc_argp = &data->args, |
| 6385 | .rpc_resp = &data->res, |
| 6386 | .rpc_cred = data->cred, |
| 6387 | }; |
| 6388 | struct rpc_task_setup task_setup_data = { |
| 6389 | .task = &data->task, |
| 6390 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6391 | .rpc_message = &msg, |
| 6392 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6393 | .callback_data = data, |
| 6394 | .flags = RPC_TASK_ASYNC, |
| 6395 | }; |
| 6396 | struct rpc_task *task; |
| 6397 | int status = 0; |
| 6398 | |
| 6399 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6400 | "lbw: %llu inode %lu\n", |
| 6401 | data->task.tk_pid, sync, |
| 6402 | data->args.lastbytewritten, |
| 6403 | data->args.inode->i_ino); |
| 6404 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6405 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6406 | task = rpc_run_task(&task_setup_data); |
| 6407 | if (IS_ERR(task)) |
| 6408 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6409 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6410 | goto out; |
| 6411 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6412 | if (status != 0) |
| 6413 | goto out; |
| 6414 | status = task->tk_status; |
| 6415 | out: |
| 6416 | dprintk("%s: status %d\n", __func__, status); |
| 6417 | rpc_put_task(task); |
| 6418 | return status; |
| 6419 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6420 | |
| 6421 | static int |
| 6422 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6423 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6424 | { |
| 6425 | struct nfs41_secinfo_no_name_args args = { |
| 6426 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6427 | }; |
| 6428 | struct nfs4_secinfo_res res = { |
| 6429 | .flavors = flavors, |
| 6430 | }; |
| 6431 | struct rpc_message msg = { |
| 6432 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6433 | .rpc_argp = &args, |
| 6434 | .rpc_resp = &res, |
| 6435 | }; |
| 6436 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6437 | } |
| 6438 | |
| 6439 | static int |
| 6440 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6441 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6442 | { |
| 6443 | struct nfs4_exception exception = { }; |
| 6444 | int err; |
| 6445 | do { |
| 6446 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6447 | switch (err) { |
| 6448 | case 0: |
| 6449 | case -NFS4ERR_WRONGSEC: |
| 6450 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6451 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6452 | default: |
| 6453 | err = nfs4_handle_exception(server, err, &exception); |
| 6454 | } |
| 6455 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6456 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6457 | return err; |
| 6458 | } |
| 6459 | |
| 6460 | static int |
| 6461 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6462 | struct nfs_fsinfo *info) |
| 6463 | { |
| 6464 | int err; |
| 6465 | struct page *page; |
| 6466 | rpc_authflavor_t flavor; |
| 6467 | struct nfs4_secinfo_flavors *flavors; |
| 6468 | |
| 6469 | page = alloc_page(GFP_KERNEL); |
| 6470 | if (!page) { |
| 6471 | err = -ENOMEM; |
| 6472 | goto out; |
| 6473 | } |
| 6474 | |
| 6475 | flavors = page_address(page); |
| 6476 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6477 | |
| 6478 | /* |
| 6479 | * Fall back on "guess and check" method if |
| 6480 | * the server doesn't support SECINFO_NO_NAME |
| 6481 | */ |
| 6482 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6483 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6484 | goto out_freepage; |
| 6485 | } |
| 6486 | if (err) |
| 6487 | goto out_freepage; |
| 6488 | |
| 6489 | flavor = nfs_find_best_sec(flavors); |
| 6490 | if (err == 0) |
| 6491 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6492 | |
| 6493 | out_freepage: |
| 6494 | put_page(page); |
| 6495 | if (err == -EACCES) |
| 6496 | return -EPERM; |
| 6497 | out: |
| 6498 | return err; |
| 6499 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6500 | |
| 6501 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6502 | { |
| 6503 | int status; |
| 6504 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6505 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6506 | }; |
| 6507 | struct nfs41_test_stateid_res res; |
| 6508 | struct rpc_message msg = { |
| 6509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6510 | .rpc_argp = &args, |
| 6511 | .rpc_resp = &res, |
| 6512 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6513 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6514 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6515 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6516 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6517 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6518 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6519 | if (status != NFS_OK) { |
| 6520 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6521 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6522 | } |
| 6523 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6524 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6525 | } |
| 6526 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6527 | /** |
| 6528 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6529 | * |
| 6530 | * @server: server / transport on which to perform the operation |
| 6531 | * @stateid: state ID to test |
| 6532 | * |
| 6533 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6534 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6535 | * failed or the state ID is not currently valid. |
| 6536 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6537 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6538 | { |
| 6539 | struct nfs4_exception exception = { }; |
| 6540 | int err; |
| 6541 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6542 | err = _nfs41_test_stateid(server, stateid); |
| 6543 | if (err != -NFS4ERR_DELAY) |
| 6544 | break; |
| 6545 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6546 | } while (exception.retry); |
| 6547 | return err; |
| 6548 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6549 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6550 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6551 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6552 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6553 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6554 | }; |
| 6555 | struct nfs41_free_stateid_res res; |
| 6556 | struct rpc_message msg = { |
| 6557 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6558 | .rpc_argp = &args, |
| 6559 | .rpc_resp = &res, |
| 6560 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6561 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6562 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6563 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6564 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6565 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6566 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6567 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6568 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6569 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6570 | } |
| 6571 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6572 | /** |
| 6573 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6574 | * |
| 6575 | * @server: server / transport on which to perform the operation |
| 6576 | * @stateid: state ID to release |
| 6577 | * |
| 6578 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6579 | * negative NFS4ERR value is returned. |
| 6580 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6581 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6582 | { |
| 6583 | struct nfs4_exception exception = { }; |
| 6584 | int err; |
| 6585 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6586 | err = _nfs4_free_stateid(server, stateid); |
| 6587 | if (err != -NFS4ERR_DELAY) |
| 6588 | break; |
| 6589 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6590 | } while (exception.retry); |
| 6591 | return err; |
| 6592 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6593 | |
| 6594 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6595 | const nfs4_stateid *s2) |
| 6596 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6597 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6598 | return false; |
| 6599 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6600 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6601 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6602 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6603 | return true; |
| 6604 | |
| 6605 | return false; |
| 6606 | } |
| 6607 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6608 | #endif /* CONFIG_NFS_V4_1 */ |
| 6609 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6610 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6611 | const nfs4_stateid *s2) |
| 6612 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6613 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6614 | } |
| 6615 | |
| 6616 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6617 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6618 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6619 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6620 | .recover_open = nfs4_open_reclaim, |
| 6621 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6622 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6623 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6624 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6625 | }; |
| 6626 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6627 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6628 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6629 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6630 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6631 | .recover_open = nfs4_open_reclaim, |
| 6632 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6633 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6634 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6635 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6636 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6637 | }; |
| 6638 | #endif /* CONFIG_NFS_V4_1 */ |
| 6639 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6640 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6641 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6642 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6643 | .recover_open = nfs4_open_expired, |
| 6644 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6645 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6646 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6647 | }; |
| 6648 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6649 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6650 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6651 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6652 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6653 | .recover_open = nfs41_open_expired, |
| 6654 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6655 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6656 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6657 | }; |
| 6658 | #endif /* CONFIG_NFS_V4_1 */ |
| 6659 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6660 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6661 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6662 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6663 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6664 | }; |
| 6665 | |
| 6666 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6667 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6668 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6669 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6670 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6671 | }; |
| 6672 | #endif |
| 6673 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6674 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6675 | .minor_version = 0, |
| 6676 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6677 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6678 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6679 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6680 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6681 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6682 | }; |
| 6683 | |
| 6684 | #if defined(CONFIG_NFS_V4_1) |
| 6685 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6686 | .minor_version = 1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6687 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6688 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6689 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6690 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6691 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6692 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6693 | }; |
| 6694 | #endif |
| 6695 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6696 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6697 | [0] = &nfs_v4_0_minor_ops, |
| 6698 | #if defined(CONFIG_NFS_V4_1) |
| 6699 | [1] = &nfs_v4_1_minor_ops, |
| 6700 | #endif |
| 6701 | }; |
| 6702 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6703 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6704 | .create = nfs_create, |
| 6705 | .lookup = nfs_lookup, |
| 6706 | .atomic_open = nfs_atomic_open, |
| 6707 | .link = nfs_link, |
| 6708 | .unlink = nfs_unlink, |
| 6709 | .symlink = nfs_symlink, |
| 6710 | .mkdir = nfs_mkdir, |
| 6711 | .rmdir = nfs_rmdir, |
| 6712 | .mknod = nfs_mknod, |
| 6713 | .rename = nfs_rename, |
| 6714 | .permission = nfs_permission, |
| 6715 | .getattr = nfs_getattr, |
| 6716 | .setattr = nfs_setattr, |
| 6717 | .getxattr = generic_getxattr, |
| 6718 | .setxattr = generic_setxattr, |
| 6719 | .listxattr = generic_listxattr, |
| 6720 | .removexattr = generic_removexattr, |
| 6721 | }; |
| 6722 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6723 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6724 | .permission = nfs_permission, |
| 6725 | .getattr = nfs_getattr, |
| 6726 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6727 | .getxattr = generic_getxattr, |
| 6728 | .setxattr = generic_setxattr, |
| 6729 | .listxattr = generic_listxattr, |
| 6730 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6731 | }; |
| 6732 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6733 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6734 | .version = 4, /* protocol version */ |
| 6735 | .dentry_ops = &nfs4_dentry_operations, |
| 6736 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6737 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6738 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6739 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6740 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6741 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6742 | .getattr = nfs4_proc_getattr, |
| 6743 | .setattr = nfs4_proc_setattr, |
| 6744 | .lookup = nfs4_proc_lookup, |
| 6745 | .access = nfs4_proc_access, |
| 6746 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6747 | .create = nfs4_proc_create, |
| 6748 | .remove = nfs4_proc_remove, |
| 6749 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6750 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6751 | .unlink_done = nfs4_proc_unlink_done, |
| 6752 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6753 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6754 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6755 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6756 | .link = nfs4_proc_link, |
| 6757 | .symlink = nfs4_proc_symlink, |
| 6758 | .mkdir = nfs4_proc_mkdir, |
| 6759 | .rmdir = nfs4_proc_remove, |
| 6760 | .readdir = nfs4_proc_readdir, |
| 6761 | .mknod = nfs4_proc_mknod, |
| 6762 | .statfs = nfs4_proc_statfs, |
| 6763 | .fsinfo = nfs4_proc_fsinfo, |
| 6764 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6765 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6766 | .decode_dirent = nfs4_decode_dirent, |
| 6767 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6768 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6769 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6770 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6771 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6772 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6773 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6774 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6775 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6776 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6777 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6778 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6779 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6780 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6781 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6782 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6783 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6784 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6785 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6786 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6787 | .create_server = nfs4_create_server, |
| 6788 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6789 | }; |
| 6790 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6791 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6792 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6793 | .list = nfs4_xattr_list_nfs4_acl, |
| 6794 | .get = nfs4_xattr_get_nfs4_acl, |
| 6795 | .set = nfs4_xattr_set_nfs4_acl, |
| 6796 | }; |
| 6797 | |
| 6798 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6799 | &nfs4_xattr_nfs4_acl_handler, |
| 6800 | NULL |
| 6801 | }; |
| 6802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6803 | /* |
| 6804 | * Local variables: |
| 6805 | * c-basic-offset: 8 |
| 6806 | * End: |
| 6807 | */ |