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 | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 899 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 900 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 901 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 902 | return 1; |
| 903 | } |
| 904 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 906 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 907 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 908 | case FMODE_WRITE: |
| 909 | state->n_wronly++; |
| 910 | break; |
| 911 | case FMODE_READ: |
| 912 | state->n_rdonly++; |
| 913 | break; |
| 914 | case FMODE_READ|FMODE_WRITE: |
| 915 | state->n_rdwr++; |
| 916 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | 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] | 921 | { |
| 922 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 923 | nfs4_stateid_copy(&state->stateid, stateid); |
| 924 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 925 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 926 | case FMODE_READ: |
| 927 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 928 | break; |
| 929 | case FMODE_WRITE: |
| 930 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 931 | break; |
| 932 | case FMODE_READ|FMODE_WRITE: |
| 933 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 934 | } |
| 935 | } |
| 936 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | 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] | 938 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 939 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 941 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 942 | } |
| 943 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 944 | 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] | 945 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 946 | /* |
| 947 | * Protect the call to nfs4_state_set_mode_locked and |
| 948 | * serialise the stateid update |
| 949 | */ |
| 950 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 951 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 952 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 953 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 954 | } |
| 955 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 957 | write_sequnlock(&state->seqlock); |
| 958 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 960 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | 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] | 964 | { |
| 965 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 966 | struct nfs_delegation *deleg_cur; |
| 967 | int ret = 0; |
| 968 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 970 | |
| 971 | rcu_read_lock(); |
| 972 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 973 | if (deleg_cur == NULL) |
| 974 | goto no_delegation; |
| 975 | |
| 976 | spin_lock(&deleg_cur->lock); |
| 977 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 978 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 979 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 980 | goto no_delegation_unlock; |
| 981 | |
| 982 | if (delegation == NULL) |
| 983 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 984 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 985 | goto no_delegation_unlock; |
| 986 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 987 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 988 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 989 | ret = 1; |
| 990 | no_delegation_unlock: |
| 991 | spin_unlock(&deleg_cur->lock); |
| 992 | no_delegation: |
| 993 | rcu_read_unlock(); |
| 994 | |
| 995 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 997 | ret = 1; |
| 998 | } |
| 999 | |
| 1000 | return ret; |
| 1001 | } |
| 1002 | |
| 1003 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1004 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1005 | { |
| 1006 | struct nfs_delegation *delegation; |
| 1007 | |
| 1008 | rcu_read_lock(); |
| 1009 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1010 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1011 | rcu_read_unlock(); |
| 1012 | return; |
| 1013 | } |
| 1014 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1015 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1018 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1019 | { |
| 1020 | struct nfs4_state *state = opendata->state; |
| 1021 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1022 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1023 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1024 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | nfs4_stateid stateid; |
| 1026 | int ret = -EAGAIN; |
| 1027 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1028 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1029 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1030 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | if (can_open_cached(state, fmode, open_mode)) { |
| 1032 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1033 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1034 | goto out_return_state; |
| 1035 | } |
| 1036 | spin_unlock(&state->owner->so_lock); |
| 1037 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1038 | rcu_read_lock(); |
| 1039 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1040 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1041 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1042 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1043 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1044 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1045 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1046 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1047 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | if (ret != 0) |
| 1049 | goto out; |
| 1050 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1051 | |
| 1052 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1055 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1056 | out: |
| 1057 | return ERR_PTR(ret); |
| 1058 | out_return_state: |
| 1059 | atomic_inc(&state->count); |
| 1060 | return state; |
| 1061 | } |
| 1062 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1063 | static void |
| 1064 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1065 | { |
| 1066 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1067 | struct nfs_delegation *delegation; |
| 1068 | int delegation_flags = 0; |
| 1069 | |
| 1070 | rcu_read_lock(); |
| 1071 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1072 | if (delegation) |
| 1073 | delegation_flags = delegation->flags; |
| 1074 | rcu_read_unlock(); |
| 1075 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1076 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1077 | "returning a delegation for " |
| 1078 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1079 | clp->cl_hostname); |
| 1080 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1081 | nfs_inode_set_delegation(state->inode, |
| 1082 | data->owner->so_cred, |
| 1083 | &data->o_res); |
| 1084 | else |
| 1085 | nfs_inode_reclaim_delegation(state->inode, |
| 1086 | data->owner->so_cred, |
| 1087 | &data->o_res); |
| 1088 | } |
| 1089 | |
| 1090 | /* |
| 1091 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1092 | * and update the nfs4_state. |
| 1093 | */ |
| 1094 | static struct nfs4_state * |
| 1095 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1096 | { |
| 1097 | struct inode *inode = data->state->inode; |
| 1098 | struct nfs4_state *state = data->state; |
| 1099 | int ret; |
| 1100 | |
| 1101 | if (!data->rpc_done) { |
| 1102 | ret = data->rpc_status; |
| 1103 | goto err; |
| 1104 | } |
| 1105 | |
| 1106 | ret = -ESTALE; |
| 1107 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1108 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1109 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1110 | goto err; |
| 1111 | |
| 1112 | ret = -ENOMEM; |
| 1113 | state = nfs4_get_open_state(inode, data->owner); |
| 1114 | if (state == NULL) |
| 1115 | goto err; |
| 1116 | |
| 1117 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1118 | if (ret) |
| 1119 | goto err; |
| 1120 | |
| 1121 | if (data->o_res.delegation_type != 0) |
| 1122 | nfs4_opendata_check_deleg(data, state); |
| 1123 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1124 | data->o_arg.fmode); |
| 1125 | |
| 1126 | return state; |
| 1127 | err: |
| 1128 | return ERR_PTR(ret); |
| 1129 | |
| 1130 | } |
| 1131 | |
| 1132 | static struct nfs4_state * |
| 1133 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1134 | { |
| 1135 | struct inode *inode; |
| 1136 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1137 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1138 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1139 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1140 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1141 | goto out; |
| 1142 | } |
| 1143 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1144 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1145 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1146 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1147 | 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] | 1148 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1149 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1150 | goto err; |
| 1151 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1152 | state = nfs4_get_open_state(inode, data->owner); |
| 1153 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1154 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1155 | if (data->o_res.delegation_type != 0) |
| 1156 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1157 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1158 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1159 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1160 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1161 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1162 | err_put_inode: |
| 1163 | iput(inode); |
| 1164 | err: |
| 1165 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1166 | } |
| 1167 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1168 | static struct nfs4_state * |
| 1169 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1170 | { |
| 1171 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1172 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1173 | return _nfs4_opendata_to_nfs4_state(data); |
| 1174 | } |
| 1175 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1176 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1177 | { |
| 1178 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1179 | struct nfs_open_context *ctx; |
| 1180 | |
| 1181 | spin_lock(&state->inode->i_lock); |
| 1182 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1183 | if (ctx->state != state) |
| 1184 | continue; |
| 1185 | get_nfs_open_context(ctx); |
| 1186 | spin_unlock(&state->inode->i_lock); |
| 1187 | return ctx; |
| 1188 | } |
| 1189 | spin_unlock(&state->inode->i_lock); |
| 1190 | return ERR_PTR(-ENOENT); |
| 1191 | } |
| 1192 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1193 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1194 | { |
| 1195 | struct nfs4_opendata *opendata; |
| 1196 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1197 | 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] | 1198 | if (opendata == NULL) |
| 1199 | return ERR_PTR(-ENOMEM); |
| 1200 | opendata->state = state; |
| 1201 | atomic_inc(&state->count); |
| 1202 | return opendata; |
| 1203 | } |
| 1204 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1205 | 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] | 1206 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1207 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1208 | int ret; |
| 1209 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1210 | opendata->o_arg.open_flags = 0; |
| 1211 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1212 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1213 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1214 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1215 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1216 | if (ret != 0) |
| 1217 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1218 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1219 | if (IS_ERR(newstate)) |
| 1220 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1221 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1222 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1227 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1228 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | int ret; |
| 1230 | |
| 1231 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1232 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1233 | smp_rmb(); |
| 1234 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1235 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1236 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1237 | if (ret != 0) |
| 1238 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1239 | if (newstate != state) |
| 1240 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1241 | } |
| 1242 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1243 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1244 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1245 | if (ret != 0) |
| 1246 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1247 | if (newstate != state) |
| 1248 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1249 | } |
| 1250 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1251 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1252 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1253 | if (ret != 0) |
| 1254 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1255 | if (newstate != state) |
| 1256 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1257 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1258 | /* |
| 1259 | * We may have performed cached opens for all three recoveries. |
| 1260 | * Check if we need to update the current stateid. |
| 1261 | */ |
| 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_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1264 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1265 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1266 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1267 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1268 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1269 | return 0; |
| 1270 | } |
| 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | /* |
| 1273 | * OPEN_RECLAIM: |
| 1274 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1276 | 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] | 1277 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1278 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1279 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1280 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | int status; |
| 1282 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1283 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1284 | if (IS_ERR(opendata)) |
| 1285 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1286 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1287 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1288 | rcu_read_lock(); |
| 1289 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1290 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1291 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1292 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1293 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1294 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1295 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | return status; |
| 1297 | } |
| 1298 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1299 | 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] | 1300 | { |
| 1301 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1302 | struct nfs4_exception exception = { }; |
| 1303 | int err; |
| 1304 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1305 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1306 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1307 | break; |
| 1308 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | } while (exception.retry); |
| 1310 | return err; |
| 1311 | } |
| 1312 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1313 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1314 | { |
| 1315 | struct nfs_open_context *ctx; |
| 1316 | int ret; |
| 1317 | |
| 1318 | ctx = nfs4_state_find_open_context(state); |
| 1319 | if (IS_ERR(ctx)) |
| 1320 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1321 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1322 | put_nfs_open_context(ctx); |
| 1323 | return ret; |
| 1324 | } |
| 1325 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1326 | 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] | 1327 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1328 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1329 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1331 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1332 | if (IS_ERR(opendata)) |
| 1333 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1334 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1335 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1336 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1337 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1338 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1341 | 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] | 1342 | { |
| 1343 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1344 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | int err; |
| 1346 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1347 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | switch (err) { |
| 1349 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1350 | case -ENOENT: |
| 1351 | case -ESTALE: |
| 1352 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1353 | case -NFS4ERR_BADSESSION: |
| 1354 | case -NFS4ERR_BADSLOT: |
| 1355 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1356 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1357 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1358 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1359 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1360 | err = -EAGAIN; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1361 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | case -NFS4ERR_STALE_CLIENTID: |
| 1363 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1364 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | case -NFS4ERR_EXPIRED: |
| 1366 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1367 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1368 | err = -EAGAIN; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1369 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1370 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1371 | case -NFS4ERR_ADMIN_REVOKED: |
| 1372 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1373 | nfs_inode_find_state_and_recover(state->inode, |
| 1374 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1375 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1376 | case -ENOMEM: |
| 1377 | err = 0; |
| 1378 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 1380 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | err = nfs4_handle_exception(server, err, &exception); |
| 1382 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1383 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | return err; |
| 1385 | } |
| 1386 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1387 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1388 | { |
| 1389 | struct nfs4_opendata *data = calldata; |
| 1390 | |
| 1391 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1392 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1393 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1394 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1395 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1396 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1397 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | static void nfs4_open_confirm_release(void *calldata) |
| 1401 | { |
| 1402 | struct nfs4_opendata *data = calldata; |
| 1403 | struct nfs4_state *state = NULL; |
| 1404 | |
| 1405 | /* If this request hasn't been cancelled, do nothing */ |
| 1406 | if (data->cancelled == 0) |
| 1407 | goto out_free; |
| 1408 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1409 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1410 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1411 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1412 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1413 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1414 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1415 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1419 | .rpc_call_done = nfs4_open_confirm_done, |
| 1420 | .rpc_release = nfs4_open_confirm_release, |
| 1421 | }; |
| 1422 | |
| 1423 | /* |
| 1424 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1425 | */ |
| 1426 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1427 | { |
| 1428 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1429 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1430 | struct rpc_message msg = { |
| 1431 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1432 | .rpc_argp = &data->c_arg, |
| 1433 | .rpc_resp = &data->c_res, |
| 1434 | .rpc_cred = data->owner->so_cred, |
| 1435 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1436 | struct rpc_task_setup task_setup_data = { |
| 1437 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1438 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1439 | .callback_ops = &nfs4_open_confirm_ops, |
| 1440 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1441 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1442 | .flags = RPC_TASK_ASYNC, |
| 1443 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | int status; |
| 1445 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1446 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1447 | data->rpc_done = 0; |
| 1448 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1449 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1450 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1451 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1452 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1453 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1454 | if (status != 0) { |
| 1455 | data->cancelled = 1; |
| 1456 | smp_wmb(); |
| 1457 | } else |
| 1458 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1459 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | return status; |
| 1461 | } |
| 1462 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1463 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | struct nfs4_opendata *data = calldata; |
| 1466 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1467 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1468 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1469 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1470 | /* |
| 1471 | * Check if we still need to send an OPEN call, or if we can use |
| 1472 | * a delegation instead. |
| 1473 | */ |
| 1474 | if (data->state != NULL) { |
| 1475 | struct nfs_delegation *delegation; |
| 1476 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1477 | 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] | 1478 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1479 | rcu_read_lock(); |
| 1480 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1481 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1482 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1483 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1484 | rcu_read_unlock(); |
| 1485 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1486 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1487 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1488 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1489 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1490 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1491 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1492 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1493 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1494 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1495 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1496 | &data->o_res.seq_res, |
| 1497 | task) != 0) |
| 1498 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1499 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1500 | unlock_no_action: |
| 1501 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1502 | out_no_action: |
| 1503 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1504 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1505 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1506 | } |
| 1507 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1508 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1509 | { |
| 1510 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1512 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1513 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1514 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1515 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1516 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1517 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1518 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1519 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1520 | case S_IFREG: |
| 1521 | break; |
| 1522 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1523 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1524 | break; |
| 1525 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1526 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1527 | break; |
| 1528 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1529 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1530 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1531 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1532 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1533 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1534 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1535 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1536 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1537 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1538 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1539 | static void nfs4_open_release(void *calldata) |
| 1540 | { |
| 1541 | struct nfs4_opendata *data = calldata; |
| 1542 | struct nfs4_state *state = NULL; |
| 1543 | |
| 1544 | /* If this request hasn't been cancelled, do nothing */ |
| 1545 | if (data->cancelled == 0) |
| 1546 | goto out_free; |
| 1547 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1548 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1549 | goto out_free; |
| 1550 | /* In case we need an open_confirm, no cleanup! */ |
| 1551 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1552 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1553 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1554 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1555 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1556 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1557 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1561 | .rpc_call_prepare = nfs4_open_prepare, |
| 1562 | .rpc_call_done = nfs4_open_done, |
| 1563 | .rpc_release = nfs4_open_release, |
| 1564 | }; |
| 1565 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1566 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1567 | { |
| 1568 | struct inode *dir = data->dir->d_inode; |
| 1569 | struct nfs_server *server = NFS_SERVER(dir); |
| 1570 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1571 | struct nfs_openres *o_res = &data->o_res; |
| 1572 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1573 | struct rpc_message msg = { |
| 1574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1575 | .rpc_argp = o_arg, |
| 1576 | .rpc_resp = o_res, |
| 1577 | .rpc_cred = data->owner->so_cred, |
| 1578 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1579 | struct rpc_task_setup task_setup_data = { |
| 1580 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1581 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1582 | .callback_ops = &nfs4_open_ops, |
| 1583 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1584 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1585 | .flags = RPC_TASK_ASYNC, |
| 1586 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1587 | int status; |
| 1588 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1589 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1590 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1591 | data->rpc_done = 0; |
| 1592 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1593 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1594 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1595 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1596 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1597 | if (IS_ERR(task)) |
| 1598 | return PTR_ERR(task); |
| 1599 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1600 | if (status != 0) { |
| 1601 | data->cancelled = 1; |
| 1602 | smp_wmb(); |
| 1603 | } else |
| 1604 | status = data->rpc_status; |
| 1605 | rpc_put_task(task); |
| 1606 | |
| 1607 | return status; |
| 1608 | } |
| 1609 | |
| 1610 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1611 | { |
| 1612 | struct inode *dir = data->dir->d_inode; |
| 1613 | struct nfs_openres *o_res = &data->o_res; |
| 1614 | int status; |
| 1615 | |
| 1616 | status = nfs4_run_open_task(data, 1); |
| 1617 | if (status != 0 || !data->rpc_done) |
| 1618 | return status; |
| 1619 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1620 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1621 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1622 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1623 | status = _nfs4_proc_open_confirm(data); |
| 1624 | if (status != 0) |
| 1625 | return status; |
| 1626 | } |
| 1627 | |
| 1628 | return status; |
| 1629 | } |
| 1630 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1631 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1632 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1633 | struct nfs4_state *state, fmode_t fmode, |
| 1634 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1635 | { |
| 1636 | struct nfs_access_entry cache; |
| 1637 | u32 mask; |
| 1638 | |
| 1639 | /* access call failed or for some reason the server doesn't |
| 1640 | * support any access modes -- defer access call until later */ |
| 1641 | if (opendata->o_res.access_supported == 0) |
| 1642 | return 0; |
| 1643 | |
| 1644 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1645 | /* 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] | 1646 | * write mode bits, but POSIX allows the creating process to write. |
| 1647 | * use openflags to check for exec, because fmode won't |
| 1648 | * always have FMODE_EXEC set when file open for exec. */ |
| 1649 | if (openflags & __FMODE_EXEC) { |
| 1650 | /* ONLY check for exec rights */ |
| 1651 | mask = MAY_EXEC; |
| 1652 | } else if (fmode & FMODE_READ) |
| 1653 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1654 | |
| 1655 | cache.cred = cred; |
| 1656 | cache.jiffies = jiffies; |
| 1657 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1658 | nfs_access_add_cache(state->inode, &cache); |
| 1659 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1660 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1661 | return 0; |
| 1662 | |
| 1663 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1664 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1665 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1666 | } |
| 1667 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1668 | /* |
| 1669 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1670 | */ |
| 1671 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1672 | { |
| 1673 | struct inode *dir = data->dir->d_inode; |
| 1674 | struct nfs_server *server = NFS_SERVER(dir); |
| 1675 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1676 | struct nfs_openres *o_res = &data->o_res; |
| 1677 | int status; |
| 1678 | |
| 1679 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1680 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1681 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1682 | if (status != 0) { |
| 1683 | if (status == -NFS4ERR_BADNAME && |
| 1684 | !(o_arg->open_flags & O_CREAT)) |
| 1685 | return -ENOENT; |
| 1686 | return status; |
| 1687 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1688 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1689 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1690 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1691 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1692 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1693 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1694 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1696 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1698 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } |
| 1700 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1701 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1702 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1705 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1706 | { |
| 1707 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1708 | } |
| 1709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | /* |
| 1711 | * OPEN_EXPIRED: |
| 1712 | * reclaim state on the server after a network partition. |
| 1713 | * Assumes caller holds the appropriate lock |
| 1714 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1715 | 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] | 1716 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1717 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1718 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1720 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1721 | if (IS_ERR(opendata)) |
| 1722 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1723 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1724 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1725 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1726 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1727 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1730 | 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] | 1731 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1732 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1733 | struct nfs4_exception exception = { }; |
| 1734 | int err; |
| 1735 | |
| 1736 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1737 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1738 | switch (err) { |
| 1739 | default: |
| 1740 | goto out; |
| 1741 | case -NFS4ERR_GRACE: |
| 1742 | case -NFS4ERR_DELAY: |
| 1743 | nfs4_handle_exception(server, err, &exception); |
| 1744 | err = 0; |
| 1745 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1746 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1747 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1748 | return err; |
| 1749 | } |
| 1750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1752 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1754 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1756 | ctx = nfs4_state_find_open_context(state); |
| 1757 | if (IS_ERR(ctx)) |
| 1758 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1759 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1760 | put_nfs_open_context(ctx); |
| 1761 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1764 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1765 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1766 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1767 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1768 | nfs4_stateid *stateid = &state->stateid; |
| 1769 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1770 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1771 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1772 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1773 | return; |
| 1774 | |
| 1775 | status = nfs41_test_stateid(server, stateid); |
| 1776 | if (status != NFS_OK) { |
| 1777 | /* Free the stateid unless the server explicitly |
| 1778 | * informs us the stateid is unrecognized. */ |
| 1779 | if (status != -NFS4ERR_BAD_STATEID) |
| 1780 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1781 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1782 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1783 | write_seqlock(&state->seqlock); |
| 1784 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1785 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1786 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | /** |
| 1791 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1792 | * |
| 1793 | * @state: NFSv4 state for an inode |
| 1794 | * |
| 1795 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1796 | * Otherwise a negative NFS4ERR value is returned. |
| 1797 | */ |
| 1798 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1799 | { |
| 1800 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1801 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1802 | int status; |
| 1803 | |
| 1804 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1805 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1806 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1807 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1808 | return -NFS4ERR_BAD_STATEID; |
| 1809 | |
| 1810 | status = nfs41_test_stateid(server, stateid); |
| 1811 | if (status != NFS_OK) { |
| 1812 | /* Free the stateid unless the server explicitly |
| 1813 | * informs us the stateid is unrecognized. */ |
| 1814 | if (status != -NFS4ERR_BAD_STATEID) |
| 1815 | nfs41_free_stateid(server, stateid); |
| 1816 | |
| 1817 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1818 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1819 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1820 | } |
| 1821 | return status; |
| 1822 | } |
| 1823 | |
| 1824 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1825 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1826 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1827 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1828 | nfs41_clear_delegation_stateid(state); |
| 1829 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1830 | if (status != NFS_OK) |
| 1831 | status = nfs4_open_expired(sp, state); |
| 1832 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1833 | } |
| 1834 | #endif |
| 1835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1837 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1838 | * fields corresponding to attributes that were used to store the verifier. |
| 1839 | * Make sure we clobber those fields in the later setattr call |
| 1840 | */ |
| 1841 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1842 | { |
| 1843 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1844 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1845 | sattr->ia_valid |= ATTR_ATIME; |
| 1846 | |
| 1847 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1848 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1849 | sattr->ia_valid |= ATTR_MTIME; |
| 1850 | } |
| 1851 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1852 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1853 | fmode_t fmode, |
| 1854 | int flags, |
| 1855 | struct nfs4_state **res) |
| 1856 | { |
| 1857 | struct nfs4_state_owner *sp = opendata->owner; |
| 1858 | struct nfs_server *server = sp->so_server; |
| 1859 | struct nfs4_state *state; |
| 1860 | unsigned int seq; |
| 1861 | int ret; |
| 1862 | |
| 1863 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1864 | |
| 1865 | ret = _nfs4_proc_open(opendata); |
| 1866 | if (ret != 0) |
| 1867 | goto out; |
| 1868 | |
| 1869 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1870 | ret = PTR_ERR(state); |
| 1871 | if (IS_ERR(state)) |
| 1872 | goto out; |
| 1873 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1874 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1875 | |
| 1876 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 1877 | if (ret != 0) |
| 1878 | goto out; |
| 1879 | |
| 1880 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 1881 | nfs4_schedule_stateid_recovery(server, state); |
| 1882 | nfs4_wait_clnt_recover(server->nfs_client); |
| 1883 | } |
| 1884 | *res = state; |
| 1885 | out: |
| 1886 | return ret; |
| 1887 | } |
| 1888 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1889 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1890 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1892 | static int _nfs4_do_open(struct inode *dir, |
| 1893 | struct dentry *dentry, |
| 1894 | fmode_t fmode, |
| 1895 | int flags, |
| 1896 | struct iattr *sattr, |
| 1897 | struct rpc_cred *cred, |
| 1898 | struct nfs4_state **res, |
| 1899 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | { |
| 1901 | struct nfs4_state_owner *sp; |
| 1902 | struct nfs4_state *state = NULL; |
| 1903 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1904 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1905 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | |
| 1907 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1909 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1910 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1912 | goto out_err; |
| 1913 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1914 | status = nfs4_recover_expired_lease(server); |
| 1915 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1916 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1917 | if (dentry->d_inode != NULL) |
| 1918 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1919 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1920 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1921 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1922 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1924 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1925 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1926 | if (!opendata->f_attr.mdsthreshold) |
| 1927 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1928 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1929 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1930 | if (dentry->d_inode != NULL) |
| 1931 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1932 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1933 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1934 | if (status != 0) |
| 1935 | goto err_opendata_put; |
| 1936 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1937 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1938 | nfs4_exclusive_attrset(opendata, sattr); |
| 1939 | |
| 1940 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1941 | status = nfs4_do_setattr(state->inode, cred, |
| 1942 | opendata->o_res.f_attr, sattr, |
| 1943 | state); |
| 1944 | if (status == 0) |
| 1945 | nfs_setattr_update_inode(state->inode, sattr); |
| 1946 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1947 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1948 | |
| 1949 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1950 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1951 | else |
| 1952 | kfree(opendata->f_attr.mdsthreshold); |
| 1953 | opendata->f_attr.mdsthreshold = NULL; |
| 1954 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1955 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | *res = state; |
| 1958 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1959 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1960 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1961 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1962 | err_put_state_owner: |
| 1963 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | *res = NULL; |
| 1966 | return status; |
| 1967 | } |
| 1968 | |
| 1969 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1970 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1971 | struct dentry *dentry, |
| 1972 | fmode_t fmode, |
| 1973 | int flags, |
| 1974 | struct iattr *sattr, |
| 1975 | struct rpc_cred *cred, |
| 1976 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | { |
| 1978 | struct nfs4_exception exception = { }; |
| 1979 | struct nfs4_state *res; |
| 1980 | int status; |
| 1981 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1982 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1984 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1985 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | if (status == 0) |
| 1987 | break; |
| 1988 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1989 | * book-keeping w.r.t. state-changing operations |
| 1990 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1991 | * It is actually a sign of a bug on the client or on the server. |
| 1992 | * |
| 1993 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1994 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | * have unhashed the old state_owner for us, and that we can |
| 1996 | * therefore safely retry using a new one. We should still warn |
| 1997 | * the user though... |
| 1998 | */ |
| 1999 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2000 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2001 | " returned a bad sequence-id error!\n", |
| 2002 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | exception.retry = 1; |
| 2004 | continue; |
| 2005 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2006 | /* |
| 2007 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2008 | * state before it received the OPEN_CONFIRM. |
| 2009 | * Recover by retrying the request as per the discussion |
| 2010 | * on Page 181 of RFC3530. |
| 2011 | */ |
| 2012 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2013 | exception.retry = 1; |
| 2014 | continue; |
| 2015 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2016 | if (status == -EAGAIN) { |
| 2017 | /* We must have found a delegation */ |
| 2018 | exception.retry = 1; |
| 2019 | continue; |
| 2020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2022 | status, &exception)); |
| 2023 | } while (exception.retry); |
| 2024 | return res; |
| 2025 | } |
| 2026 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2027 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2028 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2029 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2031 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2033 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | .iap = sattr, |
| 2035 | .server = server, |
| 2036 | .bitmask = server->attr_bitmask, |
| 2037 | }; |
| 2038 | struct nfs_setattrres res = { |
| 2039 | .fattr = fattr, |
| 2040 | .server = server, |
| 2041 | }; |
| 2042 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2043 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2044 | .rpc_argp = &arg, |
| 2045 | .rpc_resp = &res, |
| 2046 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2048 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2049 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2051 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2053 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2054 | struct nfs_lockowner lockowner = { |
| 2055 | .l_owner = current->files, |
| 2056 | .l_pid = current->tgid, |
| 2057 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2058 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2059 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2060 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2061 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2062 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2063 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2064 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2066 | 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] | 2067 | if (status == 0 && state != NULL) |
| 2068 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2069 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2072 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2073 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2074 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2076 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2077 | struct nfs4_exception exception = { |
| 2078 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2079 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2080 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | int err; |
| 2082 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2083 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2084 | switch (err) { |
| 2085 | case -NFS4ERR_OPENMODE: |
| 2086 | if (state && !(state->state & FMODE_WRITE)) { |
| 2087 | err = -EBADF; |
| 2088 | if (sattr->ia_valid & ATTR_OPEN) |
| 2089 | err = -EACCES; |
| 2090 | goto out; |
| 2091 | } |
| 2092 | } |
| 2093 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2095 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | return err; |
| 2097 | } |
| 2098 | |
| 2099 | struct nfs4_closedata { |
| 2100 | struct inode *inode; |
| 2101 | struct nfs4_state *state; |
| 2102 | struct nfs_closeargs arg; |
| 2103 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2104 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2105 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2106 | bool roc; |
| 2107 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | }; |
| 2109 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2110 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2111 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2112 | struct nfs4_closedata *calldata = data; |
| 2113 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2114 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2115 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2116 | if (calldata->roc) |
| 2117 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2118 | nfs4_put_open_state(calldata->state); |
| 2119 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2120 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2121 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2122 | kfree(calldata); |
| 2123 | } |
| 2124 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2125 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2126 | fmode_t fmode) |
| 2127 | { |
| 2128 | spin_lock(&state->owner->so_lock); |
| 2129 | if (!(fmode & FMODE_READ)) |
| 2130 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2131 | if (!(fmode & FMODE_WRITE)) |
| 2132 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2133 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2134 | spin_unlock(&state->owner->so_lock); |
| 2135 | } |
| 2136 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2137 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2139 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2142 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2143 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2144 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2145 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | /* hmm. we are done with the inode, and in the process of freeing |
| 2147 | * the state_owner. we keep this around to process errors |
| 2148 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | switch (task->tk_status) { |
| 2150 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2151 | if (calldata->roc) |
| 2152 | pnfs_roc_set_barrier(state->inode, |
| 2153 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2154 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2155 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2156 | nfs4_close_clear_stateid_flags(state, |
| 2157 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | break; |
| 2159 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2160 | case -NFS4ERR_OLD_STATEID: |
| 2161 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2163 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2164 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2166 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2167 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2169 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2170 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2171 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2174 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2176 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2177 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2178 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2179 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2180 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2181 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2182 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2183 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2184 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2185 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2186 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2187 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2188 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2189 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2190 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2191 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2192 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2193 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2194 | } |
| 2195 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2196 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2197 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2198 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2199 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2200 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2201 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2202 | |
| 2203 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2204 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2205 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2206 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2207 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2208 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2209 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2210 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2211 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2212 | goto out_wait; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2213 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2214 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2215 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2216 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2217 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2218 | &calldata->arg.seq_args, |
| 2219 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2220 | task) != 0) |
| 2221 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2222 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2223 | return; |
| 2224 | out_no_action: |
| 2225 | task->tk_action = NULL; |
| 2226 | out_wait: |
| 2227 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2230 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2231 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2232 | .rpc_call_done = nfs4_close_done, |
| 2233 | .rpc_release = nfs4_free_closedata, |
| 2234 | }; |
| 2235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | /* |
| 2237 | * It is possible for data to be read/written from a mem-mapped file |
| 2238 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2239 | * This means that we can't safely call nfsv4 close on a file until |
| 2240 | * the inode is cleared. This in turn means that we are not good |
| 2241 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2242 | * share state even when we are done with one of the three share |
| 2243 | * stateid's in the inode. |
| 2244 | * |
| 2245 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2246 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2247 | 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] | 2248 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2249 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2251 | struct nfs4_state_owner *sp = state->owner; |
| 2252 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2253 | struct rpc_message msg = { |
| 2254 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2255 | .rpc_cred = state->owner->so_cred, |
| 2256 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2257 | struct rpc_task_setup task_setup_data = { |
| 2258 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2259 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2260 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2261 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2262 | .flags = RPC_TASK_ASYNC, |
| 2263 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2264 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2266 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2268 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2269 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2270 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2272 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2273 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2275 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2276 | if (calldata->arg.seqid == NULL) |
| 2277 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2278 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2279 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2280 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2281 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2282 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2283 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2284 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2285 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2286 | msg.rpc_argp = &calldata->arg; |
| 2287 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2288 | task_setup_data.callback_data = calldata; |
| 2289 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2290 | if (IS_ERR(task)) |
| 2291 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2292 | status = 0; |
| 2293 | if (wait) |
| 2294 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2295 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2296 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2297 | out_free_calldata: |
| 2298 | kfree(calldata); |
| 2299 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2300 | nfs4_put_open_state(state); |
| 2301 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2302 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2305 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2306 | 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] | 2307 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | struct nfs4_state *state; |
| 2309 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2310 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2311 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2312 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2313 | if (IS_ERR(state)) |
| 2314 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2315 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2316 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2319 | 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] | 2320 | { |
| 2321 | if (ctx->state == NULL) |
| 2322 | return; |
| 2323 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2324 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2325 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2326 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
| 2329 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2330 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2331 | struct nfs4_server_caps_arg args = { |
| 2332 | .fhandle = fhandle, |
| 2333 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | struct nfs4_server_caps_res res = {}; |
| 2335 | struct rpc_message msg = { |
| 2336 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2337 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | .rpc_resp = &res, |
| 2339 | }; |
| 2340 | int status; |
| 2341 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2342 | 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] | 2343 | if (status == 0) { |
| 2344 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2345 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2346 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2347 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2348 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2349 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2351 | server->caps |= NFS_CAP_ACLS; |
| 2352 | if (res.has_links != 0) |
| 2353 | server->caps |= NFS_CAP_HARDLINKS; |
| 2354 | if (res.has_symlinks != 0) |
| 2355 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2356 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2357 | server->caps |= NFS_CAP_FILEID; |
| 2358 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2359 | server->caps |= NFS_CAP_MODE; |
| 2360 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2361 | server->caps |= NFS_CAP_NLINK; |
| 2362 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2363 | server->caps |= NFS_CAP_OWNER; |
| 2364 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2365 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2366 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2367 | server->caps |= NFS_CAP_ATIME; |
| 2368 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2369 | server->caps |= NFS_CAP_CTIME; |
| 2370 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2371 | server->caps |= NFS_CAP_MTIME; |
| 2372 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2373 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2374 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2375 | 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] | 2376 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2377 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | return status; |
| 2381 | } |
| 2382 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2383 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | { |
| 2385 | struct nfs4_exception exception = { }; |
| 2386 | int err; |
| 2387 | do { |
| 2388 | err = nfs4_handle_exception(server, |
| 2389 | _nfs4_server_capabilities(server, fhandle), |
| 2390 | &exception); |
| 2391 | } while (exception.retry); |
| 2392 | return err; |
| 2393 | } |
| 2394 | |
| 2395 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2396 | struct nfs_fsinfo *info) |
| 2397 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | struct nfs4_lookup_root_arg args = { |
| 2399 | .bitmask = nfs4_fattr_bitmap, |
| 2400 | }; |
| 2401 | struct nfs4_lookup_res res = { |
| 2402 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2403 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | .fh = fhandle, |
| 2405 | }; |
| 2406 | struct rpc_message msg = { |
| 2407 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2408 | .rpc_argp = &args, |
| 2409 | .rpc_resp = &res, |
| 2410 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2411 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2412 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2413 | 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] | 2414 | } |
| 2415 | |
| 2416 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2417 | struct nfs_fsinfo *info) |
| 2418 | { |
| 2419 | struct nfs4_exception exception = { }; |
| 2420 | int err; |
| 2421 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2422 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2423 | switch (err) { |
| 2424 | case 0: |
| 2425 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2426 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2427 | default: |
| 2428 | err = nfs4_handle_exception(server, err, &exception); |
| 2429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2431 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | return err; |
| 2433 | } |
| 2434 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2435 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2436 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2437 | { |
| 2438 | struct rpc_auth *auth; |
| 2439 | int ret; |
| 2440 | |
| 2441 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2442 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2443 | ret = -EIO; |
| 2444 | goto out; |
| 2445 | } |
| 2446 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2447 | out: |
| 2448 | return ret; |
| 2449 | } |
| 2450 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2451 | 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] | 2452 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2454 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2455 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2457 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2458 | if (len < 0) |
| 2459 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2460 | |
| 2461 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2462 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2463 | * thus has already been tried. */ |
| 2464 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2465 | continue; |
| 2466 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2467 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2468 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2469 | continue; |
| 2470 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2471 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2472 | /* |
| 2473 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2474 | * to access the mount. It could also mean that we tried to mount |
| 2475 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2476 | * existing mount programs don't handle -EACCES very well so it should |
| 2477 | * be mapped to -EPERM instead. |
| 2478 | */ |
| 2479 | if (status == -EACCES) |
| 2480 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2481 | return status; |
| 2482 | } |
| 2483 | |
| 2484 | /* |
| 2485 | * get the file handle for the "/" directory on the server |
| 2486 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2487 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2488 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2489 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2490 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2491 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2492 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2493 | /* |
| 2494 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2495 | * by nfs4_map_errors() as this function exits. |
| 2496 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2497 | 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] | 2498 | if (status == 0) |
| 2499 | status = nfs4_server_capabilities(server, fhandle); |
| 2500 | if (status == 0) |
| 2501 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2502 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2505 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2506 | struct nfs_fsinfo *info) |
| 2507 | { |
| 2508 | int error; |
| 2509 | struct nfs_fattr *fattr = info->fattr; |
| 2510 | |
| 2511 | error = nfs4_server_capabilities(server, mntfh); |
| 2512 | if (error < 0) { |
| 2513 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2514 | return error; |
| 2515 | } |
| 2516 | |
| 2517 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2518 | if (error < 0) { |
| 2519 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2520 | return error; |
| 2521 | } |
| 2522 | |
| 2523 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2524 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2525 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2526 | |
| 2527 | return error; |
| 2528 | } |
| 2529 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2530 | /* |
| 2531 | * Get locations and (maybe) other attributes of a referral. |
| 2532 | * Note that we'll actually follow the referral later when |
| 2533 | * we detect fsid mismatch in inode revalidation |
| 2534 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2535 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2536 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2537 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2538 | { |
| 2539 | int status = -ENOMEM; |
| 2540 | struct page *page = NULL; |
| 2541 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2542 | |
| 2543 | page = alloc_page(GFP_KERNEL); |
| 2544 | if (page == NULL) |
| 2545 | goto out; |
| 2546 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2547 | if (locations == NULL) |
| 2548 | goto out; |
| 2549 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2550 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2551 | if (status != 0) |
| 2552 | goto out; |
| 2553 | /* Make sure server returned a different fsid for the referral */ |
| 2554 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2555 | dprintk("%s: server did not return a different fsid for" |
| 2556 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2557 | status = -EIO; |
| 2558 | goto out; |
| 2559 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2560 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2561 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2562 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2563 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2564 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2565 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2566 | out: |
| 2567 | if (page) |
| 2568 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2569 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2570 | return status; |
| 2571 | } |
| 2572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2574 | { |
| 2575 | struct nfs4_getattr_arg args = { |
| 2576 | .fh = fhandle, |
| 2577 | .bitmask = server->attr_bitmask, |
| 2578 | }; |
| 2579 | struct nfs4_getattr_res res = { |
| 2580 | .fattr = fattr, |
| 2581 | .server = server, |
| 2582 | }; |
| 2583 | struct rpc_message msg = { |
| 2584 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2585 | .rpc_argp = &args, |
| 2586 | .rpc_resp = &res, |
| 2587 | }; |
| 2588 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2589 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2590 | 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] | 2591 | } |
| 2592 | |
| 2593 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2594 | { |
| 2595 | struct nfs4_exception exception = { }; |
| 2596 | int err; |
| 2597 | do { |
| 2598 | err = nfs4_handle_exception(server, |
| 2599 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2600 | &exception); |
| 2601 | } while (exception.retry); |
| 2602 | return err; |
| 2603 | } |
| 2604 | |
| 2605 | /* |
| 2606 | * The file is not closed if it is opened due to the a request to change |
| 2607 | * the size of the file. The open call will not be needed once the |
| 2608 | * VFS layer lookup-intents are implemented. |
| 2609 | * |
| 2610 | * Close is called when the inode is destroyed. |
| 2611 | * If we haven't opened the file for O_WRONLY, we |
| 2612 | * need to in the size_change case to obtain a stateid. |
| 2613 | * |
| 2614 | * Got race? |
| 2615 | * Because OPEN is always done by name in nfsv4, it is |
| 2616 | * possible that we opened a different file by the same |
| 2617 | * name. We can recognize this race condition, but we |
| 2618 | * can't do anything about it besides returning an error. |
| 2619 | * |
| 2620 | * This will be fixed with VFS changes (lookup-intent). |
| 2621 | */ |
| 2622 | static int |
| 2623 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2624 | struct iattr *sattr) |
| 2625 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2626 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2627 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2628 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | int status; |
| 2630 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2631 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2632 | pnfs_return_layout(inode); |
| 2633 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2634 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2636 | /* Deal with open(O_TRUNC) */ |
| 2637 | if (sattr->ia_valid & ATTR_OPEN) |
| 2638 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2639 | |
| 2640 | /* Optimization: if the end result is no change, don't RPC */ |
| 2641 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2642 | return 0; |
| 2643 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2644 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2645 | if (sattr->ia_valid & ATTR_FILE) { |
| 2646 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2647 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2648 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2649 | if (ctx) { |
| 2650 | cred = ctx->cred; |
| 2651 | state = ctx->state; |
| 2652 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2656 | if (status == 0) |
| 2657 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | return status; |
| 2659 | } |
| 2660 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2661 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2662 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2663 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2664 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2665 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2666 | int status; |
| 2667 | struct nfs4_lookup_arg args = { |
| 2668 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2669 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2670 | .name = name, |
| 2671 | }; |
| 2672 | struct nfs4_lookup_res res = { |
| 2673 | .server = server, |
| 2674 | .fattr = fattr, |
| 2675 | .fh = fhandle, |
| 2676 | }; |
| 2677 | struct rpc_message msg = { |
| 2678 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2679 | .rpc_argp = &args, |
| 2680 | .rpc_resp = &res, |
| 2681 | }; |
| 2682 | |
| 2683 | nfs_fattr_init(fattr); |
| 2684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2686 | 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] | 2687 | dprintk("NFS reply lookup: %d\n", status); |
| 2688 | return status; |
| 2689 | } |
| 2690 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2691 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2692 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2693 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2694 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2695 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2696 | fattr->nlink = 2; |
| 2697 | } |
| 2698 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2699 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2700 | struct qstr *name, struct nfs_fh *fhandle, |
| 2701 | struct nfs_fattr *fattr) |
| 2702 | { |
| 2703 | struct nfs4_exception exception = { }; |
| 2704 | struct rpc_clnt *client = *clnt; |
| 2705 | int err; |
| 2706 | do { |
| 2707 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2708 | switch (err) { |
| 2709 | case -NFS4ERR_BADNAME: |
| 2710 | err = -ENOENT; |
| 2711 | goto out; |
| 2712 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2713 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2714 | goto out; |
| 2715 | case -NFS4ERR_WRONGSEC: |
| 2716 | err = -EPERM; |
| 2717 | if (client != *clnt) |
| 2718 | goto out; |
| 2719 | |
| 2720 | client = nfs4_create_sec_client(client, dir, name); |
| 2721 | if (IS_ERR(client)) |
| 2722 | return PTR_ERR(client); |
| 2723 | |
| 2724 | exception.retry = 1; |
| 2725 | break; |
| 2726 | default: |
| 2727 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2728 | } |
| 2729 | } while (exception.retry); |
| 2730 | |
| 2731 | out: |
| 2732 | if (err == 0) |
| 2733 | *clnt = client; |
| 2734 | else if (client != *clnt) |
| 2735 | rpc_shutdown_client(client); |
| 2736 | |
| 2737 | return err; |
| 2738 | } |
| 2739 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2740 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2741 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2743 | int status; |
| 2744 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2745 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2746 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2747 | if (client != NFS_CLIENT(dir)) { |
| 2748 | rpc_shutdown_client(client); |
| 2749 | nfs_fixup_secinfo_attributes(fattr); |
| 2750 | } |
| 2751 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2754 | struct rpc_clnt * |
| 2755 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2756 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2757 | { |
| 2758 | int status; |
| 2759 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2760 | |
| 2761 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2762 | if (status < 0) { |
| 2763 | rpc_shutdown_client(client); |
| 2764 | return ERR_PTR(status); |
| 2765 | } |
| 2766 | return client; |
| 2767 | } |
| 2768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2770 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2771 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | struct nfs4_accessargs args = { |
| 2773 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2774 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2776 | struct nfs4_accessres res = { |
| 2777 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2778 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | struct rpc_message msg = { |
| 2780 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2781 | .rpc_argp = &args, |
| 2782 | .rpc_resp = &res, |
| 2783 | .rpc_cred = entry->cred, |
| 2784 | }; |
| 2785 | int mode = entry->mask; |
| 2786 | int status; |
| 2787 | |
| 2788 | /* |
| 2789 | * Determine which access bits we want to ask for... |
| 2790 | */ |
| 2791 | if (mode & MAY_READ) |
| 2792 | args.access |= NFS4_ACCESS_READ; |
| 2793 | if (S_ISDIR(inode->i_mode)) { |
| 2794 | if (mode & MAY_WRITE) |
| 2795 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2796 | if (mode & MAY_EXEC) |
| 2797 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2798 | } else { |
| 2799 | if (mode & MAY_WRITE) |
| 2800 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2801 | if (mode & MAY_EXEC) |
| 2802 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2803 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2804 | |
| 2805 | res.fattr = nfs_alloc_fattr(); |
| 2806 | if (res.fattr == NULL) |
| 2807 | return -ENOMEM; |
| 2808 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2809 | 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] | 2810 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2811 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2812 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2814 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | return status; |
| 2816 | } |
| 2817 | |
| 2818 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2819 | { |
| 2820 | struct nfs4_exception exception = { }; |
| 2821 | int err; |
| 2822 | do { |
| 2823 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2824 | _nfs4_proc_access(inode, entry), |
| 2825 | &exception); |
| 2826 | } while (exception.retry); |
| 2827 | return err; |
| 2828 | } |
| 2829 | |
| 2830 | /* |
| 2831 | * TODO: For the time being, we don't try to get any attributes |
| 2832 | * along with any of the zero-copy operations READ, READDIR, |
| 2833 | * READLINK, WRITE. |
| 2834 | * |
| 2835 | * In the case of the first three, we want to put the GETATTR |
| 2836 | * after the read-type operation -- this is because it is hard |
| 2837 | * to predict the length of a GETATTR response in v4, and thus |
| 2838 | * align the READ data correctly. This means that the GETATTR |
| 2839 | * may end up partially falling into the page cache, and we should |
| 2840 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2841 | * To do this efficiently, we need to know the total length |
| 2842 | * of data received, which doesn't seem to be available outside |
| 2843 | * of the RPC layer. |
| 2844 | * |
| 2845 | * In the case of WRITE, we also want to put the GETATTR after |
| 2846 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2847 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | * |
| 2849 | * Both of these changes to the XDR layer would in fact be quite |
| 2850 | * minor, but I decided to leave them for a subsequent patch. |
| 2851 | */ |
| 2852 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2853 | unsigned int pgbase, unsigned int pglen) |
| 2854 | { |
| 2855 | struct nfs4_readlink args = { |
| 2856 | .fh = NFS_FH(inode), |
| 2857 | .pgbase = pgbase, |
| 2858 | .pglen = pglen, |
| 2859 | .pages = &page, |
| 2860 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2861 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | struct rpc_message msg = { |
| 2863 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2864 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2865 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | }; |
| 2867 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2868 | 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] | 2869 | } |
| 2870 | |
| 2871 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2872 | unsigned int pgbase, unsigned int pglen) |
| 2873 | { |
| 2874 | struct nfs4_exception exception = { }; |
| 2875 | int err; |
| 2876 | do { |
| 2877 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2878 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2879 | &exception); |
| 2880 | } while (exception.retry); |
| 2881 | return err; |
| 2882 | } |
| 2883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2885 | * 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] | 2886 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | static int |
| 2888 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2889 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2891 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | int status = 0; |
| 2894 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2895 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2896 | if (IS_ERR(ctx)) |
| 2897 | return PTR_ERR(ctx); |
| 2898 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2899 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2900 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2901 | flags, sattr, ctx->cred, |
| 2902 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2903 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | if (IS_ERR(state)) { |
| 2905 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2906 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2908 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2909 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2910 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2912 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | return status; |
| 2914 | } |
| 2915 | |
| 2916 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2917 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2918 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2919 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2921 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2923 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2924 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2925 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2927 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2928 | .rpc_argp = &args, |
| 2929 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2931 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2932 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2933 | 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] | 2934 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2935 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | return status; |
| 2937 | } |
| 2938 | |
| 2939 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2940 | { |
| 2941 | struct nfs4_exception exception = { }; |
| 2942 | int err; |
| 2943 | do { |
| 2944 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2945 | _nfs4_proc_remove(dir, name), |
| 2946 | &exception); |
| 2947 | } while (exception.retry); |
| 2948 | return err; |
| 2949 | } |
| 2950 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2951 | 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] | 2952 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2953 | struct nfs_server *server = NFS_SERVER(dir); |
| 2954 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2955 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2957 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2959 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | } |
| 2961 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2962 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2963 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2964 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2965 | &data->args.seq_args, |
| 2966 | &data->res.seq_res, |
| 2967 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2970 | 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] | 2971 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2972 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2973 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2974 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2975 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2976 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2977 | return 0; |
| 2978 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2979 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2982 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2983 | { |
| 2984 | struct nfs_server *server = NFS_SERVER(dir); |
| 2985 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2986 | struct nfs_renameres *res = msg->rpc_resp; |
| 2987 | |
| 2988 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2989 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2990 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2991 | } |
| 2992 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2993 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2994 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 2995 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2996 | &data->args.seq_args, |
| 2997 | &data->res.seq_res, |
| 2998 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3002 | struct inode *new_dir) |
| 3003 | { |
| 3004 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3005 | |
| 3006 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3007 | return 0; |
| 3008 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3009 | return 0; |
| 3010 | |
| 3011 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3012 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3013 | return 1; |
| 3014 | } |
| 3015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3017 | struct inode *new_dir, struct qstr *new_name) |
| 3018 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3019 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3020 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | .old_dir = NFS_FH(old_dir), |
| 3022 | .new_dir = NFS_FH(new_dir), |
| 3023 | .old_name = old_name, |
| 3024 | .new_name = new_name, |
| 3025 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3026 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3027 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3028 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | struct rpc_message msg = { |
| 3030 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3031 | .rpc_argp = &arg, |
| 3032 | .rpc_resp = &res, |
| 3033 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3034 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3036 | 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] | 3037 | if (!status) { |
| 3038 | update_changeattr(old_dir, &res.old_cinfo); |
| 3039 | update_changeattr(new_dir, &res.new_cinfo); |
| 3040 | } |
| 3041 | return status; |
| 3042 | } |
| 3043 | |
| 3044 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3045 | struct inode *new_dir, struct qstr *new_name) |
| 3046 | { |
| 3047 | struct nfs4_exception exception = { }; |
| 3048 | int err; |
| 3049 | do { |
| 3050 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3051 | _nfs4_proc_rename(old_dir, old_name, |
| 3052 | new_dir, new_name), |
| 3053 | &exception); |
| 3054 | } while (exception.retry); |
| 3055 | return err; |
| 3056 | } |
| 3057 | |
| 3058 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3059 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3060 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | struct nfs4_link_arg arg = { |
| 3062 | .fh = NFS_FH(inode), |
| 3063 | .dir_fh = NFS_FH(dir), |
| 3064 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3065 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3067 | struct nfs4_link_res res = { |
| 3068 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3069 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | struct rpc_message msg = { |
| 3071 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3072 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3073 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3075 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3077 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3078 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3079 | goto out; |
| 3080 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3081 | 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] | 3082 | if (!status) { |
| 3083 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3084 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3085 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3086 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3087 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | return status; |
| 3089 | } |
| 3090 | |
| 3091 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3092 | { |
| 3093 | struct nfs4_exception exception = { }; |
| 3094 | int err; |
| 3095 | do { |
| 3096 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3097 | _nfs4_proc_link(inode, dir, name), |
| 3098 | &exception); |
| 3099 | } while (exception.retry); |
| 3100 | return err; |
| 3101 | } |
| 3102 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3103 | struct nfs4_createdata { |
| 3104 | struct rpc_message msg; |
| 3105 | struct nfs4_create_arg arg; |
| 3106 | struct nfs4_create_res res; |
| 3107 | struct nfs_fh fh; |
| 3108 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3109 | }; |
| 3110 | |
| 3111 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3112 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3113 | { |
| 3114 | struct nfs4_createdata *data; |
| 3115 | |
| 3116 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3117 | if (data != NULL) { |
| 3118 | struct nfs_server *server = NFS_SERVER(dir); |
| 3119 | |
| 3120 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3121 | data->msg.rpc_argp = &data->arg; |
| 3122 | data->msg.rpc_resp = &data->res; |
| 3123 | data->arg.dir_fh = NFS_FH(dir); |
| 3124 | data->arg.server = server; |
| 3125 | data->arg.name = name; |
| 3126 | data->arg.attrs = sattr; |
| 3127 | data->arg.ftype = ftype; |
| 3128 | data->arg.bitmask = server->attr_bitmask; |
| 3129 | data->res.server = server; |
| 3130 | data->res.fh = &data->fh; |
| 3131 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3132 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3133 | } |
| 3134 | return data; |
| 3135 | } |
| 3136 | |
| 3137 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3138 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3139 | 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] | 3140 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3141 | if (status == 0) { |
| 3142 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3143 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3144 | } |
| 3145 | return status; |
| 3146 | } |
| 3147 | |
| 3148 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3149 | { |
| 3150 | kfree(data); |
| 3151 | } |
| 3152 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3153 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3154 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3156 | struct nfs4_createdata *data; |
| 3157 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3159 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3160 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3161 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3162 | status = -ENOMEM; |
| 3163 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3164 | if (data == NULL) |
| 3165 | goto out; |
| 3166 | |
| 3167 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3168 | data->arg.u.symlink.pages = &page; |
| 3169 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3171 | status = nfs4_do_create(dir, dentry, data); |
| 3172 | |
| 3173 | nfs4_free_createdata(data); |
| 3174 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | return status; |
| 3176 | } |
| 3177 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3178 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3179 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | { |
| 3181 | struct nfs4_exception exception = { }; |
| 3182 | int err; |
| 3183 | do { |
| 3184 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3185 | _nfs4_proc_symlink(dir, dentry, page, |
| 3186 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | &exception); |
| 3188 | } while (exception.retry); |
| 3189 | return err; |
| 3190 | } |
| 3191 | |
| 3192 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3193 | struct iattr *sattr) |
| 3194 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3195 | struct nfs4_createdata *data; |
| 3196 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3198 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3199 | if (data == NULL) |
| 3200 | goto out; |
| 3201 | |
| 3202 | status = nfs4_do_create(dir, dentry, data); |
| 3203 | |
| 3204 | nfs4_free_createdata(data); |
| 3205 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | return status; |
| 3207 | } |
| 3208 | |
| 3209 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3210 | struct iattr *sattr) |
| 3211 | { |
| 3212 | struct nfs4_exception exception = { }; |
| 3213 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3214 | |
| 3215 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | do { |
| 3217 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3218 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3219 | &exception); |
| 3220 | } while (exception.retry); |
| 3221 | return err; |
| 3222 | } |
| 3223 | |
| 3224 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3225 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | { |
| 3227 | struct inode *dir = dentry->d_inode; |
| 3228 | struct nfs4_readdir_arg args = { |
| 3229 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3230 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | .pgbase = 0, |
| 3232 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3233 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3234 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | }; |
| 3236 | struct nfs4_readdir_res res; |
| 3237 | struct rpc_message msg = { |
| 3238 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3239 | .rpc_argp = &args, |
| 3240 | .rpc_resp = &res, |
| 3241 | .rpc_cred = cred, |
| 3242 | }; |
| 3243 | int status; |
| 3244 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3245 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3246 | dentry->d_parent->d_name.name, |
| 3247 | dentry->d_name.name, |
| 3248 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3249 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3251 | 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] | 3252 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3253 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3254 | status += args.pgbase; |
| 3255 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3256 | |
| 3257 | nfs_invalidate_atime(dir); |
| 3258 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3259 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return status; |
| 3261 | } |
| 3262 | |
| 3263 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3264 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | { |
| 3266 | struct nfs4_exception exception = { }; |
| 3267 | int err; |
| 3268 | do { |
| 3269 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3270 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3271 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | &exception); |
| 3273 | } while (exception.retry); |
| 3274 | return err; |
| 3275 | } |
| 3276 | |
| 3277 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3278 | struct iattr *sattr, dev_t rdev) |
| 3279 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3280 | struct nfs4_createdata *data; |
| 3281 | int mode = sattr->ia_mode; |
| 3282 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3284 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3285 | if (data == NULL) |
| 3286 | goto out; |
| 3287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3289 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3291 | data->arg.ftype = NF4BLK; |
| 3292 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3293 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | } |
| 3295 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3296 | data->arg.ftype = NF4CHR; |
| 3297 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3298 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3299 | } else if (!S_ISSOCK(mode)) { |
| 3300 | status = -EINVAL; |
| 3301 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3304 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3305 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3306 | nfs4_free_createdata(data); |
| 3307 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | return status; |
| 3309 | } |
| 3310 | |
| 3311 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3312 | struct iattr *sattr, dev_t rdev) |
| 3313 | { |
| 3314 | struct nfs4_exception exception = { }; |
| 3315 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3316 | |
| 3317 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | do { |
| 3319 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3320 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3321 | &exception); |
| 3322 | } while (exception.retry); |
| 3323 | return err; |
| 3324 | } |
| 3325 | |
| 3326 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3327 | struct nfs_fsstat *fsstat) |
| 3328 | { |
| 3329 | struct nfs4_statfs_arg args = { |
| 3330 | .fh = fhandle, |
| 3331 | .bitmask = server->attr_bitmask, |
| 3332 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3333 | struct nfs4_statfs_res res = { |
| 3334 | .fsstat = fsstat, |
| 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_STATFS], |
| 3338 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3339 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | }; |
| 3341 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3342 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3343 | 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] | 3344 | } |
| 3345 | |
| 3346 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3347 | { |
| 3348 | struct nfs4_exception exception = { }; |
| 3349 | int err; |
| 3350 | do { |
| 3351 | err = nfs4_handle_exception(server, |
| 3352 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3353 | &exception); |
| 3354 | } while (exception.retry); |
| 3355 | return err; |
| 3356 | } |
| 3357 | |
| 3358 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3359 | struct nfs_fsinfo *fsinfo) |
| 3360 | { |
| 3361 | struct nfs4_fsinfo_arg args = { |
| 3362 | .fh = fhandle, |
| 3363 | .bitmask = server->attr_bitmask, |
| 3364 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3365 | struct nfs4_fsinfo_res res = { |
| 3366 | .fsinfo = fsinfo, |
| 3367 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | struct rpc_message msg = { |
| 3369 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3370 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3371 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | }; |
| 3373 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3374 | 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] | 3375 | } |
| 3376 | |
| 3377 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3378 | { |
| 3379 | struct nfs4_exception exception = { }; |
| 3380 | int err; |
| 3381 | |
| 3382 | do { |
| 3383 | err = nfs4_handle_exception(server, |
| 3384 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3385 | &exception); |
| 3386 | } while (exception.retry); |
| 3387 | return err; |
| 3388 | } |
| 3389 | |
| 3390 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3391 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3392 | int error; |
| 3393 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3394 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3395 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3396 | if (error == 0) { |
| 3397 | /* block layout checks this! */ |
| 3398 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3399 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3400 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3401 | |
| 3402 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3406 | struct nfs_pathconf *pathconf) |
| 3407 | { |
| 3408 | struct nfs4_pathconf_arg args = { |
| 3409 | .fh = fhandle, |
| 3410 | .bitmask = server->attr_bitmask, |
| 3411 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3412 | struct nfs4_pathconf_res res = { |
| 3413 | .pathconf = pathconf, |
| 3414 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | struct rpc_message msg = { |
| 3416 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3417 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3418 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | }; |
| 3420 | |
| 3421 | /* None of the pathconf attributes are mandatory to implement */ |
| 3422 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3423 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3424 | return 0; |
| 3425 | } |
| 3426 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3427 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3428 | 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] | 3429 | } |
| 3430 | |
| 3431 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3432 | struct nfs_pathconf *pathconf) |
| 3433 | { |
| 3434 | struct nfs4_exception exception = { }; |
| 3435 | int err; |
| 3436 | |
| 3437 | do { |
| 3438 | err = nfs4_handle_exception(server, |
| 3439 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3440 | &exception); |
| 3441 | } while (exception.retry); |
| 3442 | return err; |
| 3443 | } |
| 3444 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3445 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3446 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3447 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3448 | } |
| 3449 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3450 | 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] | 3451 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3452 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3454 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3455 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3456 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3458 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3459 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3461 | renew_lease(server, data->timestamp); |
| 3462 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3465 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3466 | { |
| 3467 | |
| 3468 | dprintk("--> %s\n", __func__); |
| 3469 | |
| 3470 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3471 | return -EAGAIN; |
| 3472 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3473 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3474 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3477 | 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] | 3478 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3480 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3481 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3482 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3485 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3486 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3487 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3488 | &data->args.seq_args, |
| 3489 | &data->res.seq_res, |
| 3490 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3493 | 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] | 3494 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3495 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3497 | 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] | 3498 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3499 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3501 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3503 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3504 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3505 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3508 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3509 | { |
| 3510 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3511 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3512 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3513 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3516 | static |
| 3517 | 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] | 3518 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3519 | const struct nfs_pgio_header *hdr = data->header; |
| 3520 | |
| 3521 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3522 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3523 | return false; |
| 3524 | /* Otherwise, request attributes if and only if we don't hold |
| 3525 | * a delegation |
| 3526 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3527 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3528 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3529 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3530 | 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] | 3531 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3532 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3533 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3534 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3535 | data->args.bitmask = NULL; |
| 3536 | data->res.fattr = NULL; |
| 3537 | } else |
| 3538 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3539 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3540 | if (!data->write_done_cb) |
| 3541 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3542 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | data->timestamp = jiffies; |
| 3544 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3545 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3546 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3549 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3550 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3551 | nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
| 3552 | &data->args.seq_args, |
| 3553 | &data->res.seq_res, |
| 3554 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3557 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3558 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3559 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3560 | &data->args.seq_args, |
| 3561 | &data->res.seq_res, |
| 3562 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | } |
| 3564 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3565 | 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] | 3566 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3568 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3569 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3570 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3571 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3573 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3576 | 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] | 3577 | { |
| 3578 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3579 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3580 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3581 | } |
| 3582 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3583 | 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] | 3584 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3585 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3586 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3587 | if (data->commit_done_cb == NULL) |
| 3588 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3589 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3590 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3591 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3594 | struct nfs4_renewdata { |
| 3595 | struct nfs_client *client; |
| 3596 | unsigned long timestamp; |
| 3597 | }; |
| 3598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | /* |
| 3600 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3601 | * standalone procedure for queueing an asynchronous RENEW. |
| 3602 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3603 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3604 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3605 | struct nfs4_renewdata *data = calldata; |
| 3606 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3607 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3608 | if (atomic_read(&clp->cl_count) > 1) |
| 3609 | nfs4_schedule_state_renewal(clp); |
| 3610 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3611 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3612 | } |
| 3613 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3614 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3616 | struct nfs4_renewdata *data = calldata; |
| 3617 | struct nfs_client *clp = data->client; |
| 3618 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | |
| 3620 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3621 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3622 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3623 | return; |
| 3624 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3625 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3626 | return; |
| 3627 | } |
| 3628 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3630 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3633 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3634 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3635 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3636 | }; |
| 3637 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3638 | 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] | 3639 | { |
| 3640 | struct rpc_message msg = { |
| 3641 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3642 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3643 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3645 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3647 | if (renew_flags == 0) |
| 3648 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3649 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3650 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3651 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3652 | if (data == NULL) |
| 3653 | return -ENOMEM; |
| 3654 | data->client = clp; |
| 3655 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3657 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3660 | 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] | 3661 | { |
| 3662 | struct rpc_message msg = { |
| 3663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3664 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3665 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | }; |
| 3667 | unsigned long now = jiffies; |
| 3668 | int status; |
| 3669 | |
| 3670 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3671 | if (status < 0) |
| 3672 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3673 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | return 0; |
| 3675 | } |
| 3676 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3677 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3678 | { |
| 3679 | return (server->caps & NFS_CAP_ACLS) |
| 3680 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3681 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3682 | } |
| 3683 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3684 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3685 | * 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] | 3686 | * the stack. |
| 3687 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3688 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3689 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3690 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3691 | struct page **pages, unsigned int *pgbase) |
| 3692 | { |
| 3693 | struct page *newpage, **spages; |
| 3694 | int rc = 0; |
| 3695 | size_t len; |
| 3696 | spages = pages; |
| 3697 | |
| 3698 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3699 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3700 | newpage = alloc_page(GFP_KERNEL); |
| 3701 | |
| 3702 | if (newpage == NULL) |
| 3703 | goto unwind; |
| 3704 | memcpy(page_address(newpage), buf, len); |
| 3705 | buf += len; |
| 3706 | buflen -= len; |
| 3707 | *pages++ = newpage; |
| 3708 | rc++; |
| 3709 | } while (buflen != 0); |
| 3710 | |
| 3711 | return rc; |
| 3712 | |
| 3713 | unwind: |
| 3714 | for(; rc > 0; rc--) |
| 3715 | __free_page(spages[rc-1]); |
| 3716 | return -ENOMEM; |
| 3717 | } |
| 3718 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3719 | struct nfs4_cached_acl { |
| 3720 | int cached; |
| 3721 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3722 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3723 | }; |
| 3724 | |
| 3725 | 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] | 3726 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3727 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3728 | |
| 3729 | spin_lock(&inode->i_lock); |
| 3730 | kfree(nfsi->nfs4_acl); |
| 3731 | nfsi->nfs4_acl = acl; |
| 3732 | spin_unlock(&inode->i_lock); |
| 3733 | } |
| 3734 | |
| 3735 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3736 | { |
| 3737 | nfs4_set_cached_acl(inode, NULL); |
| 3738 | } |
| 3739 | |
| 3740 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3741 | { |
| 3742 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3743 | struct nfs4_cached_acl *acl; |
| 3744 | int ret = -ENOENT; |
| 3745 | |
| 3746 | spin_lock(&inode->i_lock); |
| 3747 | acl = nfsi->nfs4_acl; |
| 3748 | if (acl == NULL) |
| 3749 | goto out; |
| 3750 | if (buf == NULL) /* user is just asking for length */ |
| 3751 | goto out_len; |
| 3752 | if (acl->cached == 0) |
| 3753 | goto out; |
| 3754 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3755 | if (acl->len > buflen) |
| 3756 | goto out; |
| 3757 | memcpy(buf, acl->data, acl->len); |
| 3758 | out_len: |
| 3759 | ret = acl->len; |
| 3760 | out: |
| 3761 | spin_unlock(&inode->i_lock); |
| 3762 | return ret; |
| 3763 | } |
| 3764 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3765 | 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] | 3766 | { |
| 3767 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3768 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3769 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3770 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3771 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3772 | if (acl == NULL) |
| 3773 | goto out; |
| 3774 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3775 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3776 | } else { |
| 3777 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3778 | if (acl == NULL) |
| 3779 | goto out; |
| 3780 | acl->cached = 0; |
| 3781 | } |
| 3782 | acl->len = acl_len; |
| 3783 | out: |
| 3784 | nfs4_set_cached_acl(inode, acl); |
| 3785 | } |
| 3786 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3787 | /* |
| 3788 | * The getxattr API returns the required buffer length when called with a |
| 3789 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3790 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3791 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3792 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3793 | * the cache. If not so, we throw away the page, and cache the required |
| 3794 | * length. The next getxattr call will then produce another round trip to |
| 3795 | * the server, this time with the input buf of the required size. |
| 3796 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3797 | 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] | 3798 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3799 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3800 | struct nfs_getaclargs args = { |
| 3801 | .fh = NFS_FH(inode), |
| 3802 | .acl_pages = pages, |
| 3803 | .acl_len = buflen, |
| 3804 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3805 | struct nfs_getaclres res = { |
| 3806 | .acl_len = buflen, |
| 3807 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3808 | struct rpc_message msg = { |
| 3809 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3810 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3811 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3812 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3813 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3814 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3815 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3816 | /* As long as we're doing a round trip to the server anyway, |
| 3817 | * let's be prepared for a page of acl data. */ |
| 3818 | if (npages == 0) |
| 3819 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3820 | if (npages > ARRAY_SIZE(pages)) |
| 3821 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3822 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3823 | for (i = 0; i < npages; i++) { |
| 3824 | pages[i] = alloc_page(GFP_KERNEL); |
| 3825 | if (!pages[i]) |
| 3826 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3827 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3828 | |
| 3829 | /* for decoding across pages */ |
| 3830 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3831 | if (!res.acl_scratch) |
| 3832 | goto out_free; |
| 3833 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3834 | args.acl_len = npages * PAGE_SIZE; |
| 3835 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3836 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3837 | 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] | 3838 | __func__, buf, buflen, npages, args.acl_len); |
| 3839 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3840 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3841 | if (ret) |
| 3842 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3843 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3844 | /* Handle the case where the passed-in buffer is too short */ |
| 3845 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3846 | /* Did the user only issue a request for the acl length? */ |
| 3847 | if (buf == NULL) |
| 3848 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3849 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3850 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3851 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3852 | 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] | 3853 | if (buf) { |
| 3854 | if (res.acl_len > buflen) { |
| 3855 | ret = -ERANGE; |
| 3856 | goto out_free; |
| 3857 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3858 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 3859 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3860 | out_ok: |
| 3861 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3862 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3863 | for (i = 0; i < npages; i++) |
| 3864 | if (pages[i]) |
| 3865 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3866 | if (res.acl_scratch) |
| 3867 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3868 | return ret; |
| 3869 | } |
| 3870 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3871 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3872 | { |
| 3873 | struct nfs4_exception exception = { }; |
| 3874 | ssize_t ret; |
| 3875 | do { |
| 3876 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3877 | if (ret >= 0) |
| 3878 | break; |
| 3879 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3880 | } while (exception.retry); |
| 3881 | return ret; |
| 3882 | } |
| 3883 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3884 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3885 | { |
| 3886 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3887 | int ret; |
| 3888 | |
| 3889 | if (!nfs4_server_supports_acls(server)) |
| 3890 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3891 | ret = nfs_revalidate_inode(server, inode); |
| 3892 | if (ret < 0) |
| 3893 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3894 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3895 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3896 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3897 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3898 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3899 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3900 | return ret; |
| 3901 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3904 | 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] | 3905 | { |
| 3906 | struct nfs_server *server = NFS_SERVER(inode); |
| 3907 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3908 | struct nfs_setaclargs arg = { |
| 3909 | .fh = NFS_FH(inode), |
| 3910 | .acl_pages = pages, |
| 3911 | .acl_len = buflen, |
| 3912 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3913 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3914 | struct rpc_message msg = { |
| 3915 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3916 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3917 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3918 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3919 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3920 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3921 | |
| 3922 | if (!nfs4_server_supports_acls(server)) |
| 3923 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3924 | if (npages > ARRAY_SIZE(pages)) |
| 3925 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3926 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3927 | if (i < 0) |
| 3928 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3929 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3930 | 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] | 3931 | |
| 3932 | /* |
| 3933 | * Free each page after tx, so the only ref left is |
| 3934 | * held by the network stack |
| 3935 | */ |
| 3936 | for (; i > 0; i--) |
| 3937 | put_page(pages[i-1]); |
| 3938 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3939 | /* |
| 3940 | * Acl update can result in inode attribute update. |
| 3941 | * so mark the attribute cache invalid. |
| 3942 | */ |
| 3943 | spin_lock(&inode->i_lock); |
| 3944 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3945 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3946 | nfs_access_zap_cache(inode); |
| 3947 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3948 | return ret; |
| 3949 | } |
| 3950 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3951 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3952 | { |
| 3953 | struct nfs4_exception exception = { }; |
| 3954 | int err; |
| 3955 | do { |
| 3956 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3957 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3958 | &exception); |
| 3959 | } while (exception.retry); |
| 3960 | return err; |
| 3961 | } |
| 3962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3964 | 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] | 3965 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3966 | struct nfs_client *clp = server->nfs_client; |
| 3967 | |
| 3968 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | return 0; |
| 3970 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3971 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3972 | case -NFS4ERR_ADMIN_REVOKED: |
| 3973 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3974 | if (state == NULL) |
| 3975 | break; |
| 3976 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3977 | case -NFS4ERR_OPENMODE: |
| 3978 | if (state == NULL) |
| 3979 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3980 | nfs4_schedule_stateid_recovery(server, state); |
| 3981 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3982 | case -NFS4ERR_EXPIRED: |
| 3983 | if (state != NULL) |
| 3984 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3986 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3987 | nfs4_schedule_lease_recovery(clp); |
| 3988 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3989 | #if defined(CONFIG_NFS_V4_1) |
| 3990 | case -NFS4ERR_BADSESSION: |
| 3991 | case -NFS4ERR_BADSLOT: |
| 3992 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3993 | case -NFS4ERR_DEADSESSION: |
| 3994 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3995 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3996 | case -NFS4ERR_SEQ_MISORDERED: |
| 3997 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3998 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3999 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4000 | task->tk_status = 0; |
| 4001 | return -EAGAIN; |
| 4002 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4004 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4005 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4007 | task->tk_status = 0; |
| 4008 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4009 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | case -NFS4ERR_OLD_STATEID: |
| 4011 | task->tk_status = 0; |
| 4012 | return -EAGAIN; |
| 4013 | } |
| 4014 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4015 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4016 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4017 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4018 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4019 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4020 | task->tk_status = 0; |
| 4021 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4024 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4025 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4026 | { |
| 4027 | __be32 verf[2]; |
| 4028 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4029 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4030 | /* An impossible timestamp guarantees this value |
| 4031 | * will never match a generated boot time. */ |
| 4032 | verf[0] = 0; |
| 4033 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4034 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4035 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4036 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4037 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4038 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4039 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4040 | } |
| 4041 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4042 | static unsigned int |
| 4043 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4044 | char *buf, size_t len) |
| 4045 | { |
| 4046 | unsigned int result; |
| 4047 | |
| 4048 | rcu_read_lock(); |
| 4049 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4050 | clp->cl_ipaddr, |
| 4051 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4052 | RPC_DISPLAY_ADDR), |
| 4053 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4054 | RPC_DISPLAY_PROTO)); |
| 4055 | rcu_read_unlock(); |
| 4056 | return result; |
| 4057 | } |
| 4058 | |
| 4059 | static unsigned int |
| 4060 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4061 | char *buf, size_t len) |
| 4062 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4063 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4064 | |
| 4065 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4066 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4067 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4068 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4069 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4070 | } |
| 4071 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4072 | /** |
| 4073 | * nfs4_proc_setclientid - Negotiate client ID |
| 4074 | * @clp: state data structure |
| 4075 | * @program: RPC program for NFSv4 callback service |
| 4076 | * @port: IP port number for NFS4 callback service |
| 4077 | * @cred: RPC credential to use for this call |
| 4078 | * @res: where to place the result |
| 4079 | * |
| 4080 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4081 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4082 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4083 | unsigned short port, struct rpc_cred *cred, |
| 4084 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | { |
| 4086 | nfs4_verifier sc_verifier; |
| 4087 | struct nfs4_setclientid setclientid = { |
| 4088 | .sc_verifier = &sc_verifier, |
| 4089 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4090 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | }; |
| 4092 | struct rpc_message msg = { |
| 4093 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4094 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4095 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4096 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4098 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4100 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4101 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4102 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4103 | setclientid.sc_name_len = |
| 4104 | nfs4_init_uniform_client_string(clp, |
| 4105 | setclientid.sc_name, |
| 4106 | sizeof(setclientid.sc_name)); |
| 4107 | else |
| 4108 | setclientid.sc_name_len = |
| 4109 | nfs4_init_nonuniform_client_string(clp, |
| 4110 | setclientid.sc_name, |
| 4111 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4112 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4113 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4114 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4115 | sizeof(setclientid.sc_netid), |
| 4116 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4117 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4118 | rcu_read_unlock(); |
| 4119 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4120 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4122 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4123 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4124 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4125 | setclientid.sc_name_len, setclientid.sc_name); |
| 4126 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4127 | dprintk("NFS reply setclientid: %d\n", status); |
| 4128 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | } |
| 4130 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4131 | /** |
| 4132 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4133 | * @clp: state data structure |
| 4134 | * @res: result of a previous SETCLIENTID |
| 4135 | * @cred: RPC credential to use for this call |
| 4136 | * |
| 4137 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4138 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4139 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4140 | struct nfs4_setclientid_res *arg, |
| 4141 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | { |
| 4143 | struct nfs_fsinfo fsinfo; |
| 4144 | struct rpc_message msg = { |
| 4145 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4146 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4148 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | }; |
| 4150 | unsigned long now; |
| 4151 | int status; |
| 4152 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4153 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4154 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4155 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4157 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | if (status == 0) { |
| 4159 | spin_lock(&clp->cl_lock); |
| 4160 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4161 | clp->cl_last_renewal = now; |
| 4162 | spin_unlock(&clp->cl_lock); |
| 4163 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4164 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | return status; |
| 4166 | } |
| 4167 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4168 | struct nfs4_delegreturndata { |
| 4169 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4170 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4171 | struct nfs_fh fh; |
| 4172 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4173 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4174 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4175 | int rpc_status; |
| 4176 | }; |
| 4177 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4178 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4179 | { |
| 4180 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4181 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4182 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4183 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4184 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4185 | switch (task->tk_status) { |
| 4186 | case -NFS4ERR_STALE_STATEID: |
| 4187 | case -NFS4ERR_EXPIRED: |
| 4188 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4189 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4190 | break; |
| 4191 | default: |
| 4192 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4193 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4194 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4195 | return; |
| 4196 | } |
| 4197 | } |
| 4198 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | static void nfs4_delegreturn_release(void *calldata) |
| 4202 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4203 | kfree(calldata); |
| 4204 | } |
| 4205 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4206 | #if defined(CONFIG_NFS_V4_1) |
| 4207 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4208 | { |
| 4209 | struct nfs4_delegreturndata *d_data; |
| 4210 | |
| 4211 | d_data = (struct nfs4_delegreturndata *)data; |
| 4212 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4213 | nfs4_setup_sequence(d_data->res.server, |
| 4214 | &d_data->args.seq_args, |
| 4215 | &d_data->res.seq_res, |
| 4216 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4217 | } |
| 4218 | #endif /* CONFIG_NFS_V4_1 */ |
| 4219 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4220 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4221 | #if defined(CONFIG_NFS_V4_1) |
| 4222 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4223 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4224 | .rpc_call_done = nfs4_delegreturn_done, |
| 4225 | .rpc_release = nfs4_delegreturn_release, |
| 4226 | }; |
| 4227 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4228 | 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] | 4229 | { |
| 4230 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4231 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4232 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4233 | struct rpc_message msg = { |
| 4234 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4235 | .rpc_cred = cred, |
| 4236 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4237 | struct rpc_task_setup task_setup_data = { |
| 4238 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4239 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4240 | .callback_ops = &nfs4_delegreturn_ops, |
| 4241 | .flags = RPC_TASK_ASYNC, |
| 4242 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4243 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4244 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4245 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4246 | if (data == NULL) |
| 4247 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4248 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4249 | data->args.fhandle = &data->fh; |
| 4250 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4251 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4252 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4253 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4254 | data->res.fattr = &data->fattr; |
| 4255 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4256 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4257 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4258 | data->rpc_status = 0; |
| 4259 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4260 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4261 | msg.rpc_argp = &data->args; |
| 4262 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4263 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4264 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4265 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4266 | if (!issync) |
| 4267 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4268 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4269 | if (status != 0) |
| 4270 | goto out; |
| 4271 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4272 | if (status == 0) |
| 4273 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4274 | else |
| 4275 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4276 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4277 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4278 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | } |
| 4280 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4281 | 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] | 4282 | { |
| 4283 | struct nfs_server *server = NFS_SERVER(inode); |
| 4284 | struct nfs4_exception exception = { }; |
| 4285 | int err; |
| 4286 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4287 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | switch (err) { |
| 4289 | case -NFS4ERR_STALE_STATEID: |
| 4290 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | case 0: |
| 4292 | return 0; |
| 4293 | } |
| 4294 | err = nfs4_handle_exception(server, err, &exception); |
| 4295 | } while (exception.retry); |
| 4296 | return err; |
| 4297 | } |
| 4298 | |
| 4299 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4300 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4301 | |
| 4302 | /* |
| 4303 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4304 | */ |
| 4305 | static unsigned long |
| 4306 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4307 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4308 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | timeout <<= 1; |
| 4310 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4311 | return NFS4_LOCK_MAXTIMEOUT; |
| 4312 | return timeout; |
| 4313 | } |
| 4314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4316 | { |
| 4317 | struct inode *inode = state->inode; |
| 4318 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4319 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4320 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4322 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4324 | struct nfs_lockt_res res = { |
| 4325 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | }; |
| 4327 | struct rpc_message msg = { |
| 4328 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4329 | .rpc_argp = &arg, |
| 4330 | .rpc_resp = &res, |
| 4331 | .rpc_cred = state->owner->so_cred, |
| 4332 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | struct nfs4_lock_state *lsp; |
| 4334 | int status; |
| 4335 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4336 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4337 | status = nfs4_set_lock_state(state, request); |
| 4338 | if (status != 0) |
| 4339 | goto out; |
| 4340 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4341 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4342 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4343 | 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] | 4344 | switch (status) { |
| 4345 | case 0: |
| 4346 | request->fl_type = F_UNLCK; |
| 4347 | break; |
| 4348 | case -NFS4ERR_DENIED: |
| 4349 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4351 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4352 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | return status; |
| 4354 | } |
| 4355 | |
| 4356 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4357 | { |
| 4358 | struct nfs4_exception exception = { }; |
| 4359 | int err; |
| 4360 | |
| 4361 | do { |
| 4362 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4363 | _nfs4_proc_getlk(state, cmd, request), |
| 4364 | &exception); |
| 4365 | } while (exception.retry); |
| 4366 | return err; |
| 4367 | } |
| 4368 | |
| 4369 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4370 | { |
| 4371 | int res = 0; |
| 4372 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4373 | case FL_POSIX: |
| 4374 | res = posix_lock_file_wait(file, fl); |
| 4375 | break; |
| 4376 | case FL_FLOCK: |
| 4377 | res = flock_lock_file_wait(file, fl); |
| 4378 | break; |
| 4379 | default: |
| 4380 | BUG(); |
| 4381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | return res; |
| 4383 | } |
| 4384 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4385 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4386 | struct nfs_locku_args arg; |
| 4387 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4388 | struct nfs4_lock_state *lsp; |
| 4389 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4390 | struct file_lock fl; |
| 4391 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4392 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4393 | }; |
| 4394 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4395 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4396 | struct nfs_open_context *ctx, |
| 4397 | struct nfs4_lock_state *lsp, |
| 4398 | struct nfs_seqid *seqid) |
| 4399 | { |
| 4400 | struct nfs4_unlockdata *p; |
| 4401 | struct inode *inode = lsp->ls_state->inode; |
| 4402 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4403 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4404 | if (p == NULL) |
| 4405 | return NULL; |
| 4406 | p->arg.fh = NFS_FH(inode); |
| 4407 | p->arg.fl = &p->fl; |
| 4408 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4409 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4410 | p->arg.stateid = &lsp->ls_stateid; |
| 4411 | p->lsp = lsp; |
| 4412 | atomic_inc(&lsp->ls_count); |
| 4413 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4414 | p->ctx = get_nfs_open_context(ctx); |
| 4415 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4416 | p->server = NFS_SERVER(inode); |
| 4417 | return p; |
| 4418 | } |
| 4419 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4420 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4421 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4422 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4423 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4424 | nfs4_put_lock_state(calldata->lsp); |
| 4425 | put_nfs_open_context(calldata->ctx); |
| 4426 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4427 | } |
| 4428 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4429 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4430 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4431 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4432 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4433 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4434 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4435 | switch (task->tk_status) { |
| 4436 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4437 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4438 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4439 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4440 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4441 | case -NFS4ERR_BAD_STATEID: |
| 4442 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4443 | case -NFS4ERR_STALE_STATEID: |
| 4444 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4445 | break; |
| 4446 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4447 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4448 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4449 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4450 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4451 | } |
| 4452 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4453 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4454 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4455 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4457 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4458 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4459 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4460 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4461 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4462 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4463 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4464 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4465 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4466 | &calldata->res.seq_res, |
| 4467 | task) != 0) |
| 4468 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4469 | return; |
| 4470 | out_no_action: |
| 4471 | task->tk_action = NULL; |
| 4472 | out_wait: |
| 4473 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | } |
| 4475 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4476 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4477 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4478 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4479 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4480 | }; |
| 4481 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4482 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4483 | struct nfs_open_context *ctx, |
| 4484 | struct nfs4_lock_state *lsp, |
| 4485 | struct nfs_seqid *seqid) |
| 4486 | { |
| 4487 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4488 | struct rpc_message msg = { |
| 4489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4490 | .rpc_cred = ctx->cred, |
| 4491 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4492 | struct rpc_task_setup task_setup_data = { |
| 4493 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4494 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4495 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4496 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4497 | .flags = RPC_TASK_ASYNC, |
| 4498 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4499 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4500 | /* Ensure this is an unlock - when canceling a lock, the |
| 4501 | * canceled lock is passed in, and it won't be an unlock. |
| 4502 | */ |
| 4503 | fl->fl_type = F_UNLCK; |
| 4504 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4505 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4506 | if (data == NULL) { |
| 4507 | nfs_free_seqid(seqid); |
| 4508 | return ERR_PTR(-ENOMEM); |
| 4509 | } |
| 4510 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4511 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4512 | msg.rpc_argp = &data->arg; |
| 4513 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4514 | task_setup_data.callback_data = data; |
| 4515 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4516 | } |
| 4517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4519 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4520 | struct inode *inode = state->inode; |
| 4521 | struct nfs4_state_owner *sp = state->owner; |
| 4522 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4523 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4524 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4525 | struct rpc_task *task; |
| 4526 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4527 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4529 | status = nfs4_set_lock_state(state, request); |
| 4530 | /* Unlock _before_ we do the RPC call */ |
| 4531 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4532 | /* Exclude nfs_delegation_claim_locks() */ |
| 4533 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4534 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4535 | down_read(&nfsi->rwsem); |
| 4536 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4537 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4538 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4539 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4540 | } |
| 4541 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4542 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4543 | if (status != 0) |
| 4544 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4545 | /* Is this a delegated lock? */ |
| 4546 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4547 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4548 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4549 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4550 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4551 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4552 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4553 | 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] | 4554 | status = PTR_ERR(task); |
| 4555 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4556 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4557 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4558 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4559 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4560 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4561 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4564 | struct nfs4_lockdata { |
| 4565 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4566 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4567 | struct nfs4_lock_state *lsp; |
| 4568 | struct nfs_open_context *ctx; |
| 4569 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4570 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4571 | int rpc_status; |
| 4572 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4573 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4574 | }; |
| 4575 | |
| 4576 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4577 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4578 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4579 | { |
| 4580 | struct nfs4_lockdata *p; |
| 4581 | struct inode *inode = lsp->ls_state->inode; |
| 4582 | struct nfs_server *server = NFS_SERVER(inode); |
| 4583 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4584 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4585 | if (p == NULL) |
| 4586 | return NULL; |
| 4587 | |
| 4588 | p->arg.fh = NFS_FH(inode); |
| 4589 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4590 | 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] | 4591 | if (p->arg.open_seqid == NULL) |
| 4592 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4593 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4594 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4595 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4596 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4597 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4598 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4599 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4600 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4601 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4602 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4603 | atomic_inc(&lsp->ls_count); |
| 4604 | p->ctx = get_nfs_open_context(ctx); |
| 4605 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4606 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4607 | out_free_seqid: |
| 4608 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4609 | out_free: |
| 4610 | kfree(p); |
| 4611 | return NULL; |
| 4612 | } |
| 4613 | |
| 4614 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4615 | { |
| 4616 | struct nfs4_lockdata *data = calldata; |
| 4617 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4619 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4620 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4621 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4622 | /* Do we need to do an open_to_lock_owner? */ |
| 4623 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4624 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4625 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4626 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4627 | data->arg.open_stateid = &state->stateid; |
| 4628 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4629 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4630 | } else |
| 4631 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4632 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4633 | if (nfs4_setup_sequence(data->server, |
| 4634 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4635 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4636 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4637 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4638 | nfs_release_seqid(data->arg.open_seqid); |
| 4639 | out_release_lock_seqid: |
| 4640 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4641 | out_wait: |
| 4642 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4643 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4644 | } |
| 4645 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4646 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4647 | { |
| 4648 | struct nfs4_lockdata *data = calldata; |
| 4649 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4650 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4651 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4652 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4653 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4654 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4655 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4656 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4657 | if (data->rpc_status == 0) |
| 4658 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4659 | else |
| 4660 | goto out; |
| 4661 | } |
| 4662 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4663 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4664 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4665 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4666 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4667 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4668 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | static void nfs4_lock_release(void *calldata) |
| 4672 | { |
| 4673 | struct nfs4_lockdata *data = calldata; |
| 4674 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4675 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4676 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4677 | if (data->cancelled != 0) { |
| 4678 | struct rpc_task *task; |
| 4679 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4680 | data->arg.lock_seqid); |
| 4681 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4682 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4683 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4684 | } else |
| 4685 | nfs_free_seqid(data->arg.lock_seqid); |
| 4686 | nfs4_put_lock_state(data->lsp); |
| 4687 | put_nfs_open_context(data->ctx); |
| 4688 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4689 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4693 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4694 | .rpc_call_done = nfs4_lock_done, |
| 4695 | .rpc_release = nfs4_lock_release, |
| 4696 | }; |
| 4697 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4698 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4699 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4700 | switch (error) { |
| 4701 | case -NFS4ERR_ADMIN_REVOKED: |
| 4702 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4703 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4704 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4705 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4706 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4707 | break; |
| 4708 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4709 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4710 | case -NFS4ERR_EXPIRED: |
| 4711 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4712 | }; |
| 4713 | } |
| 4714 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4715 | 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] | 4716 | { |
| 4717 | struct nfs4_lockdata *data; |
| 4718 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4719 | struct rpc_message msg = { |
| 4720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4721 | .rpc_cred = state->owner->so_cred, |
| 4722 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4723 | struct rpc_task_setup task_setup_data = { |
| 4724 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4725 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4726 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4727 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4728 | .flags = RPC_TASK_ASYNC, |
| 4729 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4730 | int ret; |
| 4731 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4732 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4733 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4734 | fl->fl_u.nfs4_fl.owner, |
| 4735 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4736 | if (data == NULL) |
| 4737 | return -ENOMEM; |
| 4738 | if (IS_SETLKW(cmd)) |
| 4739 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4740 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4741 | msg.rpc_argp = &data->arg; |
| 4742 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4743 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4744 | if (recovery_type > NFS_LOCK_NEW) { |
| 4745 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4746 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4747 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4748 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4749 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4750 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4751 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4752 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4753 | if (ret == 0) { |
| 4754 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4755 | if (ret) |
| 4756 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4757 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4758 | } else |
| 4759 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4760 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4761 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4762 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4766 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4767 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4768 | struct nfs4_exception exception = { |
| 4769 | .inode = state->inode, |
| 4770 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4771 | int err; |
| 4772 | |
| 4773 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4774 | /* Cache the lock if possible... */ |
| 4775 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4776 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4777 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4778 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4779 | break; |
| 4780 | nfs4_handle_exception(server, err, &exception); |
| 4781 | } while (exception.retry); |
| 4782 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4786 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4787 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4788 | struct nfs4_exception exception = { |
| 4789 | .inode = state->inode, |
| 4790 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4791 | int err; |
| 4792 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4793 | err = nfs4_set_lock_state(state, request); |
| 4794 | if (err != 0) |
| 4795 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4796 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4797 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4798 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4799 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4800 | switch (err) { |
| 4801 | default: |
| 4802 | goto out; |
| 4803 | case -NFS4ERR_GRACE: |
| 4804 | case -NFS4ERR_DELAY: |
| 4805 | nfs4_handle_exception(server, err, &exception); |
| 4806 | err = 0; |
| 4807 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4808 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4809 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4810 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | } |
| 4812 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4813 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4814 | /** |
| 4815 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4816 | * |
| 4817 | * @state: NFSv4 state for an inode |
| 4818 | * |
| 4819 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4820 | * Otherwise a negative NFS4ERR value is returned. |
| 4821 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4822 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4823 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4824 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4825 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4826 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4827 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4828 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4829 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4830 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4831 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4832 | /* Free the stateid unless the server |
| 4833 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4834 | if (status != -NFS4ERR_BAD_STATEID) |
| 4835 | nfs41_free_stateid(server, |
| 4836 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4837 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4838 | ret = status; |
| 4839 | } |
| 4840 | } |
| 4841 | }; |
| 4842 | |
| 4843 | return ret; |
| 4844 | } |
| 4845 | |
| 4846 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4847 | { |
| 4848 | int status = NFS_OK; |
| 4849 | |
| 4850 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4851 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4852 | if (status != NFS_OK) |
| 4853 | status = nfs4_lock_expired(state, request); |
| 4854 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4855 | } |
| 4856 | #endif |
| 4857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4859 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4860 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4861 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4862 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4863 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4864 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4866 | if ((fl_flags & FL_POSIX) && |
| 4867 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4868 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4869 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4870 | status = nfs4_set_lock_state(state, request); |
| 4871 | if (status != 0) |
| 4872 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4873 | request->fl_flags |= FL_ACCESS; |
| 4874 | status = do_vfs_lock(request->fl_file, request); |
| 4875 | if (status < 0) |
| 4876 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4877 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4878 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4879 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4880 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4881 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4882 | status = do_vfs_lock(request->fl_file, request); |
| 4883 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4884 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4885 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 4886 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4887 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4888 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4889 | goto out; |
| 4890 | down_read(&nfsi->rwsem); |
| 4891 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 4892 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4893 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 4894 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4895 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4896 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4897 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4898 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4899 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4900 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4901 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4902 | out: |
| 4903 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4904 | return status; |
| 4905 | } |
| 4906 | |
| 4907 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4908 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4909 | struct nfs4_exception exception = { |
| 4910 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4911 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4912 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | int err; |
| 4914 | |
| 4915 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4916 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4917 | if (err == -NFS4ERR_DENIED) |
| 4918 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4920 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | } while (exception.retry); |
| 4922 | return err; |
| 4923 | } |
| 4924 | |
| 4925 | static int |
| 4926 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4927 | { |
| 4928 | struct nfs_open_context *ctx; |
| 4929 | struct nfs4_state *state; |
| 4930 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4931 | int status; |
| 4932 | |
| 4933 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4934 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | state = ctx->state; |
| 4936 | |
| 4937 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4938 | return -EINVAL; |
| 4939 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4940 | if (IS_GETLK(cmd)) { |
| 4941 | if (state != NULL) |
| 4942 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4943 | return 0; |
| 4944 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | |
| 4946 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4947 | return -EINVAL; |
| 4948 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4949 | if (request->fl_type == F_UNLCK) { |
| 4950 | if (state != NULL) |
| 4951 | return nfs4_proc_unlck(state, cmd, request); |
| 4952 | return 0; |
| 4953 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4955 | if (state == NULL) |
| 4956 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4957 | /* |
| 4958 | * Don't rely on the VFS having checked the file open mode, |
| 4959 | * since it won't do this for flock() locks. |
| 4960 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4961 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4962 | case F_RDLCK: |
| 4963 | if (!(filp->f_mode & FMODE_READ)) |
| 4964 | return -EBADF; |
| 4965 | break; |
| 4966 | case F_WRLCK: |
| 4967 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4968 | return -EBADF; |
| 4969 | } |
| 4970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | do { |
| 4972 | status = nfs4_proc_setlk(state, cmd, request); |
| 4973 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4974 | break; |
| 4975 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4976 | status = -ERESTARTSYS; |
| 4977 | if (signalled()) |
| 4978 | break; |
| 4979 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | return status; |
| 4981 | } |
| 4982 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4983 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4984 | { |
| 4985 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4986 | struct nfs4_exception exception = { }; |
| 4987 | int err; |
| 4988 | |
| 4989 | err = nfs4_set_lock_state(state, fl); |
| 4990 | if (err != 0) |
| 4991 | goto out; |
| 4992 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4993 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4994 | switch (err) { |
| 4995 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4996 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4997 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4998 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4999 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5000 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5001 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5002 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5003 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 5004 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5005 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5006 | err = -EAGAIN; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5007 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5008 | case -NFS4ERR_BADSESSION: |
| 5009 | case -NFS4ERR_BADSLOT: |
| 5010 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5011 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5012 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5013 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5014 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5015 | err = -EAGAIN; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5016 | goto out; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5017 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5018 | case -NFS4ERR_ADMIN_REVOKED: |
| 5019 | case -NFS4ERR_BAD_STATEID: |
| 5020 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5021 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5022 | err = 0; |
| 5023 | goto out; |
| 5024 | case -ENOMEM: |
| 5025 | case -NFS4ERR_DENIED: |
| 5026 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5027 | err = 0; |
| 5028 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5029 | } |
Trond Myklebust | 37380e4 | 2013-02-05 12:35:16 -0500 | [diff] [blame] | 5030 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5031 | err = nfs4_handle_exception(server, err, &exception); |
| 5032 | } while (exception.retry); |
| 5033 | out: |
| 5034 | return err; |
| 5035 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5036 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5037 | struct nfs_release_lockowner_data { |
| 5038 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5039 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5040 | struct nfs_release_lockowner_args args; |
| 5041 | }; |
| 5042 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5043 | static void nfs4_release_lockowner_release(void *calldata) |
| 5044 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5045 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5046 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5047 | kfree(calldata); |
| 5048 | } |
| 5049 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5050 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5051 | .rpc_release = nfs4_release_lockowner_release, |
| 5052 | }; |
| 5053 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5054 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5055 | { |
| 5056 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5057 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5058 | struct rpc_message msg = { |
| 5059 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5060 | }; |
| 5061 | |
| 5062 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5063 | return -EINVAL; |
| 5064 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5065 | if (!data) |
| 5066 | return -ENOMEM; |
| 5067 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5068 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5069 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5070 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5071 | data->args.lock_owner.s_dev = server->s_dev; |
| 5072 | msg.rpc_argp = &data->args; |
| 5073 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5074 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5075 | } |
| 5076 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5077 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5078 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5079 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5080 | const void *buf, size_t buflen, |
| 5081 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5082 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5083 | if (strcmp(key, "") != 0) |
| 5084 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5085 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5086 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5087 | } |
| 5088 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5089 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5090 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5091 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5092 | if (strcmp(key, "") != 0) |
| 5093 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5094 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5095 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5098 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5099 | size_t list_len, const char *name, |
| 5100 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5101 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5102 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5103 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5104 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5105 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5106 | |
| 5107 | if (list && len <= list_len) |
| 5108 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5109 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5110 | } |
| 5111 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5112 | /* |
| 5113 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5114 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5115 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5116 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5117 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5118 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5119 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5120 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5121 | return; |
| 5122 | |
| 5123 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5124 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5125 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5126 | fattr->nlink = 2; |
| 5127 | } |
| 5128 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5129 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5130 | const struct qstr *name, |
| 5131 | struct nfs4_fs_locations *fs_locations, |
| 5132 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5133 | { |
| 5134 | struct nfs_server *server = NFS_SERVER(dir); |
| 5135 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5136 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5137 | }; |
| 5138 | struct nfs4_fs_locations_arg args = { |
| 5139 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5140 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5141 | .page = page, |
| 5142 | .bitmask = bitmask, |
| 5143 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5144 | struct nfs4_fs_locations_res res = { |
| 5145 | .fs_locations = fs_locations, |
| 5146 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5147 | struct rpc_message msg = { |
| 5148 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5149 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5150 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5151 | }; |
| 5152 | int status; |
| 5153 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5154 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5155 | |
| 5156 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5157 | * is not supported */ |
| 5158 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5159 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5160 | else |
| 5161 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5162 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5163 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5164 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5165 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5166 | 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] | 5167 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5168 | return status; |
| 5169 | } |
| 5170 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5171 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5172 | const struct qstr *name, |
| 5173 | struct nfs4_fs_locations *fs_locations, |
| 5174 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5175 | { |
| 5176 | struct nfs4_exception exception = { }; |
| 5177 | int err; |
| 5178 | do { |
| 5179 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5180 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5181 | &exception); |
| 5182 | } while (exception.retry); |
| 5183 | return err; |
| 5184 | } |
| 5185 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5186 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5187 | { |
| 5188 | int status; |
| 5189 | struct nfs4_secinfo_arg args = { |
| 5190 | .dir_fh = NFS_FH(dir), |
| 5191 | .name = name, |
| 5192 | }; |
| 5193 | struct nfs4_secinfo_res res = { |
| 5194 | .flavors = flavors, |
| 5195 | }; |
| 5196 | struct rpc_message msg = { |
| 5197 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5198 | .rpc_argp = &args, |
| 5199 | .rpc_resp = &res, |
| 5200 | }; |
| 5201 | |
| 5202 | dprintk("NFS call secinfo %s\n", name->name); |
| 5203 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5204 | dprintk("NFS reply secinfo: %d\n", status); |
| 5205 | return status; |
| 5206 | } |
| 5207 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5208 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5209 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5210 | { |
| 5211 | struct nfs4_exception exception = { }; |
| 5212 | int err; |
| 5213 | do { |
| 5214 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5215 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5216 | &exception); |
| 5217 | } while (exception.retry); |
| 5218 | return err; |
| 5219 | } |
| 5220 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5221 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5222 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5223 | * Check the exchange flags returned by the server for invalid flags, having |
| 5224 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5225 | * DS flags set. |
| 5226 | */ |
| 5227 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5228 | { |
| 5229 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5230 | goto out_inval; |
| 5231 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5232 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5233 | goto out_inval; |
| 5234 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5235 | goto out_inval; |
| 5236 | return NFS_OK; |
| 5237 | out_inval: |
| 5238 | return -NFS4ERR_INVAL; |
| 5239 | } |
| 5240 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5241 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5242 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5243 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5244 | { |
| 5245 | if (a->server_scope_sz == b->server_scope_sz && |
| 5246 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5247 | return true; |
| 5248 | |
| 5249 | return false; |
| 5250 | } |
| 5251 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5252 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5253 | * nfs4_proc_bind_conn_to_session() |
| 5254 | * |
| 5255 | * The 4.1 client currently uses the same TCP connection for the |
| 5256 | * fore and backchannel. |
| 5257 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5258 | 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] | 5259 | { |
| 5260 | int status; |
| 5261 | struct nfs41_bind_conn_to_session_res res; |
| 5262 | struct rpc_message msg = { |
| 5263 | .rpc_proc = |
| 5264 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5265 | .rpc_argp = clp, |
| 5266 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5267 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5268 | }; |
| 5269 | |
| 5270 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5271 | |
| 5272 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5273 | if (unlikely(res.session == NULL)) { |
| 5274 | status = -ENOMEM; |
| 5275 | goto out; |
| 5276 | } |
| 5277 | |
| 5278 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5279 | if (status == 0) { |
| 5280 | if (memcmp(res.session->sess_id.data, |
| 5281 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5282 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5283 | status = -EIO; |
| 5284 | goto out_session; |
| 5285 | } |
| 5286 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5287 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5288 | __func__); |
| 5289 | status = -EIO; |
| 5290 | goto out_session; |
| 5291 | } |
| 5292 | if (res.use_conn_in_rdma_mode) { |
| 5293 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5294 | __func__); |
| 5295 | status = -EIO; |
| 5296 | goto out_session; |
| 5297 | } |
| 5298 | } |
| 5299 | out_session: |
| 5300 | kfree(res.session); |
| 5301 | out: |
| 5302 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5303 | return status; |
| 5304 | } |
| 5305 | |
| 5306 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5307 | * nfs4_proc_exchange_id() |
| 5308 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5309 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5310 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5311 | * Since the clientid has expired, all compounds using sessions |
| 5312 | * associated with the stale clientid will be returning |
| 5313 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5314 | * be in some phase of session reset. |
| 5315 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5316 | 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] | 5317 | { |
| 5318 | nfs4_verifier verifier; |
| 5319 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5320 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5321 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5322 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5323 | }; |
| 5324 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5325 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5326 | }; |
| 5327 | int status; |
| 5328 | struct rpc_message msg = { |
| 5329 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5330 | .rpc_argp = &args, |
| 5331 | .rpc_resp = &res, |
| 5332 | .rpc_cred = cred, |
| 5333 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5334 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5335 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5336 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5337 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5338 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5339 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5340 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5341 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5342 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5343 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5344 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5345 | status = -ENOMEM; |
| 5346 | goto out; |
| 5347 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5348 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5349 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5350 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5351 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5352 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5353 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5354 | } |
| 5355 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5356 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5357 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5358 | status = -ENOMEM; |
| 5359 | goto out_server_scope; |
| 5360 | } |
| 5361 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5362 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5363 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5364 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5365 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5366 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5367 | clp->cl_clientid = res.clientid; |
| 5368 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5369 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5370 | clp->cl_seqid = res.seqid; |
| 5371 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5372 | kfree(clp->cl_serverowner); |
| 5373 | clp->cl_serverowner = res.server_owner; |
| 5374 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5375 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5376 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5377 | kfree(clp->cl_implid); |
| 5378 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5379 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5380 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5381 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5382 | res.server_scope)) { |
| 5383 | dprintk("%s: server_scope mismatch detected\n", |
| 5384 | __func__); |
| 5385 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5386 | kfree(clp->cl_serverscope); |
| 5387 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5388 | } |
| 5389 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5390 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5391 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5392 | goto out; |
| 5393 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5394 | } else |
| 5395 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5396 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5397 | out_server_owner: |
| 5398 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5399 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5400 | kfree(res.server_scope); |
| 5401 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5402 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5403 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5404 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5405 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5406 | clp->cl_implid->date.seconds, |
| 5407 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5408 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5409 | return status; |
| 5410 | } |
| 5411 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5412 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5413 | struct rpc_cred *cred) |
| 5414 | { |
| 5415 | struct rpc_message msg = { |
| 5416 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5417 | .rpc_argp = clp, |
| 5418 | .rpc_cred = cred, |
| 5419 | }; |
| 5420 | int status; |
| 5421 | |
| 5422 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5423 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5424 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5425 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5426 | return status; |
| 5427 | } |
| 5428 | |
| 5429 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5430 | struct rpc_cred *cred) |
| 5431 | { |
| 5432 | unsigned int loop; |
| 5433 | int ret; |
| 5434 | |
| 5435 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5436 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5437 | switch (ret) { |
| 5438 | case -NFS4ERR_DELAY: |
| 5439 | case -NFS4ERR_CLIENTID_BUSY: |
| 5440 | ssleep(1); |
| 5441 | break; |
| 5442 | default: |
| 5443 | return ret; |
| 5444 | } |
| 5445 | } |
| 5446 | return 0; |
| 5447 | } |
| 5448 | |
| 5449 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5450 | { |
| 5451 | struct rpc_cred *cred; |
| 5452 | int ret = 0; |
| 5453 | |
| 5454 | if (clp->cl_mvops->minor_version < 1) |
| 5455 | goto out; |
| 5456 | if (clp->cl_exchange_flags == 0) |
| 5457 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5458 | if (clp->cl_preserve_clid) |
| 5459 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5460 | cred = nfs4_get_exchange_id_cred(clp); |
| 5461 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5462 | if (cred) |
| 5463 | put_rpccred(cred); |
| 5464 | switch (ret) { |
| 5465 | case 0: |
| 5466 | case -NFS4ERR_STALE_CLIENTID: |
| 5467 | clp->cl_exchange_flags = 0; |
| 5468 | } |
| 5469 | out: |
| 5470 | return ret; |
| 5471 | } |
| 5472 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5473 | struct nfs4_get_lease_time_data { |
| 5474 | struct nfs4_get_lease_time_args *args; |
| 5475 | struct nfs4_get_lease_time_res *res; |
| 5476 | struct nfs_client *clp; |
| 5477 | }; |
| 5478 | |
| 5479 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5480 | void *calldata) |
| 5481 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5482 | struct nfs4_get_lease_time_data *data = |
| 5483 | (struct nfs4_get_lease_time_data *)calldata; |
| 5484 | |
| 5485 | dprintk("--> %s\n", __func__); |
| 5486 | /* just setup sequence, do not trigger session recovery |
| 5487 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5488 | nfs41_setup_sequence(data->clp->cl_session, |
| 5489 | &data->args->la_seq_args, |
| 5490 | &data->res->lr_seq_res, |
| 5491 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5492 | dprintk("<-- %s\n", __func__); |
| 5493 | } |
| 5494 | |
| 5495 | /* |
| 5496 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5497 | * from sequence operation or clientid errors. |
| 5498 | */ |
| 5499 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5500 | { |
| 5501 | struct nfs4_get_lease_time_data *data = |
| 5502 | (struct nfs4_get_lease_time_data *)calldata; |
| 5503 | |
| 5504 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5505 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5506 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5507 | switch (task->tk_status) { |
| 5508 | case -NFS4ERR_DELAY: |
| 5509 | case -NFS4ERR_GRACE: |
| 5510 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5511 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5512 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5513 | /* fall through */ |
| 5514 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5515 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5516 | return; |
| 5517 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5518 | dprintk("<-- %s\n", __func__); |
| 5519 | } |
| 5520 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5521 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5522 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5523 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5524 | }; |
| 5525 | |
| 5526 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5527 | { |
| 5528 | struct rpc_task *task; |
| 5529 | struct nfs4_get_lease_time_args args; |
| 5530 | struct nfs4_get_lease_time_res res = { |
| 5531 | .lr_fsinfo = fsinfo, |
| 5532 | }; |
| 5533 | struct nfs4_get_lease_time_data data = { |
| 5534 | .args = &args, |
| 5535 | .res = &res, |
| 5536 | .clp = clp, |
| 5537 | }; |
| 5538 | struct rpc_message msg = { |
| 5539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5540 | .rpc_argp = &args, |
| 5541 | .rpc_resp = &res, |
| 5542 | }; |
| 5543 | struct rpc_task_setup task_setup = { |
| 5544 | .rpc_client = clp->cl_rpcclient, |
| 5545 | .rpc_message = &msg, |
| 5546 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5547 | .callback_data = &data, |
| 5548 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5549 | }; |
| 5550 | int status; |
| 5551 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5552 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5553 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5554 | dprintk("--> %s\n", __func__); |
| 5555 | task = rpc_run_task(&task_setup); |
| 5556 | |
| 5557 | if (IS_ERR(task)) |
| 5558 | status = PTR_ERR(task); |
| 5559 | else { |
| 5560 | status = task->tk_status; |
| 5561 | rpc_put_task(task); |
| 5562 | } |
| 5563 | dprintk("<-- %s return %d\n", __func__, status); |
| 5564 | |
| 5565 | return status; |
| 5566 | } |
| 5567 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5568 | /* |
| 5569 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5570 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5571 | * use them. |
| 5572 | * |
| 5573 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5574 | * always set csa_cachethis to FALSE because the current implementation |
| 5575 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5576 | */ |
| 5577 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5578 | { |
| 5579 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5580 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5581 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5582 | |
| 5583 | if (mxrqst_sz == 0) |
| 5584 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5585 | if (mxresp_sz == 0) |
| 5586 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5587 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5588 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5589 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5590 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5591 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5592 | |
| 5593 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5594 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5595 | __func__, |
| 5596 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5597 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5598 | |
| 5599 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5600 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5601 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5602 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5603 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5604 | args->bc_attrs.max_reqs = 1; |
| 5605 | |
| 5606 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5607 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5608 | __func__, |
| 5609 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5610 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5611 | args->bc_attrs.max_reqs); |
| 5612 | } |
| 5613 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5614 | 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] | 5615 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5616 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5617 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5618 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5619 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5620 | return -EINVAL; |
| 5621 | /* |
| 5622 | * Our requested max_ops is the minimum we need; we're not |
| 5623 | * prepared to break up compounds into smaller pieces than that. |
| 5624 | * So, no point even trying to continue if the server won't |
| 5625 | * cooperate: |
| 5626 | */ |
| 5627 | if (rcvd->max_ops < sent->max_ops) |
| 5628 | return -EINVAL; |
| 5629 | if (rcvd->max_reqs == 0) |
| 5630 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5631 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5632 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5633 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5634 | } |
| 5635 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5636 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5637 | { |
| 5638 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5639 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5640 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5641 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5642 | return -EINVAL; |
| 5643 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5644 | return -EINVAL; |
| 5645 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5646 | return -EINVAL; |
| 5647 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5648 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5649 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5650 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5651 | return -EINVAL; |
| 5652 | return 0; |
| 5653 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5654 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5655 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5656 | struct nfs4_session *session) |
| 5657 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5658 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5659 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5660 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5661 | if (ret) |
| 5662 | return ret; |
| 5663 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5664 | } |
| 5665 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5666 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5667 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5668 | { |
| 5669 | struct nfs4_session *session = clp->cl_session; |
| 5670 | struct nfs41_create_session_args args = { |
| 5671 | .client = clp, |
| 5672 | .cb_program = NFS4_CALLBACK, |
| 5673 | }; |
| 5674 | struct nfs41_create_session_res res = { |
| 5675 | .client = clp, |
| 5676 | }; |
| 5677 | struct rpc_message msg = { |
| 5678 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5679 | .rpc_argp = &args, |
| 5680 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5681 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5682 | }; |
| 5683 | int status; |
| 5684 | |
| 5685 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5686 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5687 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5688 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5689 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5690 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5691 | /* Verify the session's negotiated channel_attrs values */ |
| 5692 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5693 | /* Increment the clientid slot sequence id */ |
| 5694 | clp->cl_seqid++; |
| 5695 | } |
| 5696 | |
| 5697 | return status; |
| 5698 | } |
| 5699 | |
| 5700 | /* |
| 5701 | * Issues a CREATE_SESSION operation to the server. |
| 5702 | * It is the responsibility of the caller to verify the session is |
| 5703 | * expired before calling this routine. |
| 5704 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5705 | 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] | 5706 | { |
| 5707 | int status; |
| 5708 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5709 | struct nfs4_session *session = clp->cl_session; |
| 5710 | |
| 5711 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5712 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5713 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5714 | if (status) |
| 5715 | goto out; |
| 5716 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5717 | /* Init or reset the session slot tables */ |
| 5718 | status = nfs4_setup_session_slot_tables(session); |
| 5719 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5720 | if (status) |
| 5721 | goto out; |
| 5722 | |
| 5723 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5724 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5725 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5726 | out: |
| 5727 | dprintk("<-- %s\n", __func__); |
| 5728 | return status; |
| 5729 | } |
| 5730 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5731 | /* |
| 5732 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5733 | * The caller must serialize access to this routine. |
| 5734 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5735 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5736 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5737 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5738 | struct rpc_message msg = { |
| 5739 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5740 | .rpc_argp = session, |
| 5741 | .rpc_cred = cred, |
| 5742 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5743 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5744 | |
| 5745 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5746 | |
| 5747 | /* session is still being setup */ |
| 5748 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5749 | return status; |
| 5750 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5751 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5752 | |
| 5753 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5754 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5755 | "Session has been destroyed regardless...\n", status); |
| 5756 | |
| 5757 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5758 | return status; |
| 5759 | } |
| 5760 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5761 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5762 | * Renew the cl_session lease. |
| 5763 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5764 | struct nfs4_sequence_data { |
| 5765 | struct nfs_client *clp; |
| 5766 | struct nfs4_sequence_args args; |
| 5767 | struct nfs4_sequence_res res; |
| 5768 | }; |
| 5769 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5770 | static void nfs41_sequence_release(void *data) |
| 5771 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5772 | struct nfs4_sequence_data *calldata = data; |
| 5773 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5774 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5775 | if (atomic_read(&clp->cl_count) > 1) |
| 5776 | nfs4_schedule_state_renewal(clp); |
| 5777 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5778 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5779 | } |
| 5780 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5781 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5782 | { |
| 5783 | switch(task->tk_status) { |
| 5784 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5785 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5786 | return -EAGAIN; |
| 5787 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5788 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5789 | } |
| 5790 | return 0; |
| 5791 | } |
| 5792 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5793 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5794 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5795 | struct nfs4_sequence_data *calldata = data; |
| 5796 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5797 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5798 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5799 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5800 | |
| 5801 | if (task->tk_status < 0) { |
| 5802 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5803 | if (atomic_read(&clp->cl_count) == 1) |
| 5804 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5805 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5806 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5807 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5808 | return; |
| 5809 | } |
| 5810 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5811 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5812 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5813 | dprintk("<-- %s\n", __func__); |
| 5814 | } |
| 5815 | |
| 5816 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5817 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5818 | struct nfs4_sequence_data *calldata = data; |
| 5819 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5820 | struct nfs4_sequence_args *args; |
| 5821 | struct nfs4_sequence_res *res; |
| 5822 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5823 | args = task->tk_msg.rpc_argp; |
| 5824 | res = task->tk_msg.rpc_resp; |
| 5825 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5826 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5830 | .rpc_call_done = nfs41_sequence_call_done, |
| 5831 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5832 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5833 | }; |
| 5834 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5835 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5836 | struct rpc_cred *cred, |
| 5837 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5838 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5839 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5840 | struct rpc_message msg = { |
| 5841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5842 | .rpc_cred = cred, |
| 5843 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5844 | struct rpc_task_setup task_setup_data = { |
| 5845 | .rpc_client = clp->cl_rpcclient, |
| 5846 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5847 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5848 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5849 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5850 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5851 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5852 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5853 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5854 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5855 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5856 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5857 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5858 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5859 | if (is_privileged) |
| 5860 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5861 | msg.rpc_argp = &calldata->args; |
| 5862 | msg.rpc_resp = &calldata->res; |
| 5863 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5864 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5865 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5866 | return rpc_run_task(&task_setup_data); |
| 5867 | } |
| 5868 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5869 | 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] | 5870 | { |
| 5871 | struct rpc_task *task; |
| 5872 | int ret = 0; |
| 5873 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5874 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5875 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5876 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5877 | if (IS_ERR(task)) |
| 5878 | ret = PTR_ERR(task); |
| 5879 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5880 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5881 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5882 | return ret; |
| 5883 | } |
| 5884 | |
| 5885 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5886 | { |
| 5887 | struct rpc_task *task; |
| 5888 | int ret; |
| 5889 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5890 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5891 | if (IS_ERR(task)) { |
| 5892 | ret = PTR_ERR(task); |
| 5893 | goto out; |
| 5894 | } |
| 5895 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5896 | if (!ret) { |
| 5897 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5898 | |
| 5899 | if (task->tk_status == 0) |
| 5900 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5901 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5902 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5903 | rpc_put_task(task); |
| 5904 | out: |
| 5905 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5906 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5907 | } |
| 5908 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5909 | struct nfs4_reclaim_complete_data { |
| 5910 | struct nfs_client *clp; |
| 5911 | struct nfs41_reclaim_complete_args arg; |
| 5912 | struct nfs41_reclaim_complete_res res; |
| 5913 | }; |
| 5914 | |
| 5915 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5916 | { |
| 5917 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5918 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5919 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 5920 | &calldata->arg.seq_args, |
| 5921 | &calldata->res.seq_res, |
| 5922 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5923 | } |
| 5924 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5925 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5926 | { |
| 5927 | switch(task->tk_status) { |
| 5928 | case 0: |
| 5929 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5930 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5931 | break; |
| 5932 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5933 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5934 | /* fall through */ |
| 5935 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5936 | return -EAGAIN; |
| 5937 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5938 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5939 | } |
| 5940 | return 0; |
| 5941 | } |
| 5942 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5943 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5944 | { |
| 5945 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5946 | struct nfs_client *clp = calldata->clp; |
| 5947 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5948 | |
| 5949 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5950 | if (!nfs41_sequence_done(task, res)) |
| 5951 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5952 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5953 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5954 | rpc_restart_call_prepare(task); |
| 5955 | return; |
| 5956 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5957 | dprintk("<-- %s\n", __func__); |
| 5958 | } |
| 5959 | |
| 5960 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5961 | { |
| 5962 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5963 | |
| 5964 | kfree(calldata); |
| 5965 | } |
| 5966 | |
| 5967 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5968 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5969 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5970 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5971 | }; |
| 5972 | |
| 5973 | /* |
| 5974 | * Issue a global reclaim complete. |
| 5975 | */ |
| 5976 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5977 | { |
| 5978 | struct nfs4_reclaim_complete_data *calldata; |
| 5979 | struct rpc_task *task; |
| 5980 | struct rpc_message msg = { |
| 5981 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5982 | }; |
| 5983 | struct rpc_task_setup task_setup_data = { |
| 5984 | .rpc_client = clp->cl_rpcclient, |
| 5985 | .rpc_message = &msg, |
| 5986 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5987 | .flags = RPC_TASK_ASYNC, |
| 5988 | }; |
| 5989 | int status = -ENOMEM; |
| 5990 | |
| 5991 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5992 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5993 | if (calldata == NULL) |
| 5994 | goto out; |
| 5995 | calldata->clp = clp; |
| 5996 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5997 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5998 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5999 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6000 | msg.rpc_argp = &calldata->arg; |
| 6001 | msg.rpc_resp = &calldata->res; |
| 6002 | task_setup_data.callback_data = calldata; |
| 6003 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6004 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6005 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6006 | goto out; |
| 6007 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6008 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6009 | if (status == 0) |
| 6010 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6011 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6012 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6013 | out: |
| 6014 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6015 | return status; |
| 6016 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6017 | |
| 6018 | static void |
| 6019 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6020 | { |
| 6021 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6022 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6023 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6024 | |
| 6025 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6026 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6027 | * right now covering the LAYOUTGET we are about to send. |
| 6028 | * However, that is not so catastrophic, and there seems |
| 6029 | * to be no way to prevent it completely. |
| 6030 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6031 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6032 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6033 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6034 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6035 | NFS_I(lgp->args.inode)->layout, |
| 6036 | lgp->args.ctx->state)) { |
| 6037 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6038 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6042 | { |
| 6043 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6044 | struct inode *inode = lgp->args.inode; |
| 6045 | struct nfs_server *server = NFS_SERVER(inode); |
| 6046 | struct pnfs_layout_hdr *lo; |
| 6047 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6048 | |
| 6049 | dprintk("--> %s\n", __func__); |
| 6050 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6051 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6052 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6053 | |
| 6054 | switch (task->tk_status) { |
| 6055 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6056 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6057 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6058 | case -NFS4ERR_RECALLCONFLICT: |
| 6059 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6060 | break; |
| 6061 | case -NFS4ERR_EXPIRED: |
| 6062 | case -NFS4ERR_BAD_STATEID: |
| 6063 | spin_lock(&inode->i_lock); |
| 6064 | lo = NFS_I(inode)->layout; |
| 6065 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6066 | spin_unlock(&inode->i_lock); |
| 6067 | /* If the open stateid was bad, then recover it. */ |
| 6068 | state = lgp->args.ctx->state; |
| 6069 | } else { |
| 6070 | LIST_HEAD(head); |
| 6071 | |
| 6072 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6073 | spin_unlock(&inode->i_lock); |
| 6074 | /* Mark the bad layout state as invalid, then |
| 6075 | * retry using the open stateid. */ |
| 6076 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6077 | } |
| 6078 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6079 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6080 | rpc_restart_call_prepare(task); |
| 6081 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6082 | dprintk("<-- %s\n", __func__); |
| 6083 | } |
| 6084 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6085 | static size_t max_response_pages(struct nfs_server *server) |
| 6086 | { |
| 6087 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6088 | return nfs_page_array_len(0, max_resp_sz); |
| 6089 | } |
| 6090 | |
| 6091 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6092 | { |
| 6093 | int i; |
| 6094 | |
| 6095 | if (!pages) |
| 6096 | return; |
| 6097 | |
| 6098 | for (i = 0; i < size; i++) { |
| 6099 | if (!pages[i]) |
| 6100 | break; |
| 6101 | __free_page(pages[i]); |
| 6102 | } |
| 6103 | kfree(pages); |
| 6104 | } |
| 6105 | |
| 6106 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6107 | { |
| 6108 | struct page **pages; |
| 6109 | int i; |
| 6110 | |
| 6111 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6112 | if (!pages) { |
| 6113 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6114 | return NULL; |
| 6115 | } |
| 6116 | |
| 6117 | for (i = 0; i < size; i++) { |
| 6118 | pages[i] = alloc_page(gfp_flags); |
| 6119 | if (!pages[i]) { |
| 6120 | dprintk("%s: failed to allocate page\n", __func__); |
| 6121 | nfs4_free_pages(pages, size); |
| 6122 | return NULL; |
| 6123 | } |
| 6124 | } |
| 6125 | |
| 6126 | return pages; |
| 6127 | } |
| 6128 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6129 | static void nfs4_layoutget_release(void *calldata) |
| 6130 | { |
| 6131 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6132 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6133 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6134 | |
| 6135 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6136 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6137 | put_nfs_open_context(lgp->args.ctx); |
| 6138 | kfree(calldata); |
| 6139 | dprintk("<-- %s\n", __func__); |
| 6140 | } |
| 6141 | |
| 6142 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6143 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6144 | .rpc_call_done = nfs4_layoutget_done, |
| 6145 | .rpc_release = nfs4_layoutget_release, |
| 6146 | }; |
| 6147 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6148 | struct pnfs_layout_segment * |
| 6149 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6150 | { |
| 6151 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6152 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6153 | struct rpc_task *task; |
| 6154 | struct rpc_message msg = { |
| 6155 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6156 | .rpc_argp = &lgp->args, |
| 6157 | .rpc_resp = &lgp->res, |
| 6158 | }; |
| 6159 | struct rpc_task_setup task_setup_data = { |
| 6160 | .rpc_client = server->client, |
| 6161 | .rpc_message = &msg, |
| 6162 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6163 | .callback_data = lgp, |
| 6164 | .flags = RPC_TASK_ASYNC, |
| 6165 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6166 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6167 | int status = 0; |
| 6168 | |
| 6169 | dprintk("--> %s\n", __func__); |
| 6170 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6171 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6172 | if (!lgp->args.layout.pages) { |
| 6173 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6174 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6175 | } |
| 6176 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6177 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6178 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6179 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6180 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6181 | task = rpc_run_task(&task_setup_data); |
| 6182 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6183 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6184 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6185 | if (status == 0) |
| 6186 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame^] | 6187 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6188 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6189 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6190 | rpc_put_task(task); |
| 6191 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6192 | if (status) |
| 6193 | return ERR_PTR(status); |
| 6194 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6195 | } |
| 6196 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6197 | static void |
| 6198 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6199 | { |
| 6200 | struct nfs4_layoutreturn *lrp = calldata; |
| 6201 | |
| 6202 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6203 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6204 | &lrp->args.seq_args, |
| 6205 | &lrp->res.seq_res, |
| 6206 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6207 | } |
| 6208 | |
| 6209 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6210 | { |
| 6211 | struct nfs4_layoutreturn *lrp = calldata; |
| 6212 | struct nfs_server *server; |
| 6213 | |
| 6214 | dprintk("--> %s\n", __func__); |
| 6215 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6216 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6217 | return; |
| 6218 | |
| 6219 | server = NFS_SERVER(lrp->args.inode); |
| 6220 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6221 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6222 | return; |
| 6223 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6224 | dprintk("<-- %s\n", __func__); |
| 6225 | } |
| 6226 | |
| 6227 | static void nfs4_layoutreturn_release(void *calldata) |
| 6228 | { |
| 6229 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6230 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6231 | |
| 6232 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6233 | spin_lock(&lo->plh_inode->i_lock); |
| 6234 | if (lrp->res.lrs_present) |
| 6235 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6236 | lo->plh_block_lgets--; |
| 6237 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6238 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6239 | kfree(calldata); |
| 6240 | dprintk("<-- %s\n", __func__); |
| 6241 | } |
| 6242 | |
| 6243 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6244 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6245 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6246 | .rpc_release = nfs4_layoutreturn_release, |
| 6247 | }; |
| 6248 | |
| 6249 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6250 | { |
| 6251 | struct rpc_task *task; |
| 6252 | struct rpc_message msg = { |
| 6253 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6254 | .rpc_argp = &lrp->args, |
| 6255 | .rpc_resp = &lrp->res, |
| 6256 | }; |
| 6257 | struct rpc_task_setup task_setup_data = { |
| 6258 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6259 | .rpc_message = &msg, |
| 6260 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6261 | .callback_data = lrp, |
| 6262 | }; |
| 6263 | int status; |
| 6264 | |
| 6265 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6266 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6267 | task = rpc_run_task(&task_setup_data); |
| 6268 | if (IS_ERR(task)) |
| 6269 | return PTR_ERR(task); |
| 6270 | status = task->tk_status; |
| 6271 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6272 | rpc_put_task(task); |
| 6273 | return status; |
| 6274 | } |
| 6275 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6276 | /* |
| 6277 | * Retrieve the list of Data Server devices from the MDS. |
| 6278 | */ |
| 6279 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6280 | const struct nfs_fh *fh, |
| 6281 | struct pnfs_devicelist *devlist) |
| 6282 | { |
| 6283 | struct nfs4_getdevicelist_args args = { |
| 6284 | .fh = fh, |
| 6285 | .layoutclass = server->pnfs_curr_ld->id, |
| 6286 | }; |
| 6287 | struct nfs4_getdevicelist_res res = { |
| 6288 | .devlist = devlist, |
| 6289 | }; |
| 6290 | struct rpc_message msg = { |
| 6291 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6292 | .rpc_argp = &args, |
| 6293 | .rpc_resp = &res, |
| 6294 | }; |
| 6295 | int status; |
| 6296 | |
| 6297 | dprintk("--> %s\n", __func__); |
| 6298 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6299 | &res.seq_res, 0); |
| 6300 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6301 | return status; |
| 6302 | } |
| 6303 | |
| 6304 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6305 | const struct nfs_fh *fh, |
| 6306 | struct pnfs_devicelist *devlist) |
| 6307 | { |
| 6308 | struct nfs4_exception exception = { }; |
| 6309 | int err; |
| 6310 | |
| 6311 | do { |
| 6312 | err = nfs4_handle_exception(server, |
| 6313 | _nfs4_getdevicelist(server, fh, devlist), |
| 6314 | &exception); |
| 6315 | } while (exception.retry); |
| 6316 | |
| 6317 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6318 | err, devlist->num_devs); |
| 6319 | |
| 6320 | return err; |
| 6321 | } |
| 6322 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6323 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6324 | static int |
| 6325 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6326 | { |
| 6327 | struct nfs4_getdeviceinfo_args args = { |
| 6328 | .pdev = pdev, |
| 6329 | }; |
| 6330 | struct nfs4_getdeviceinfo_res res = { |
| 6331 | .pdev = pdev, |
| 6332 | }; |
| 6333 | struct rpc_message msg = { |
| 6334 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6335 | .rpc_argp = &args, |
| 6336 | .rpc_resp = &res, |
| 6337 | }; |
| 6338 | int status; |
| 6339 | |
| 6340 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6341 | 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] | 6342 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6343 | |
| 6344 | return status; |
| 6345 | } |
| 6346 | |
| 6347 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6348 | { |
| 6349 | struct nfs4_exception exception = { }; |
| 6350 | int err; |
| 6351 | |
| 6352 | do { |
| 6353 | err = nfs4_handle_exception(server, |
| 6354 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6355 | &exception); |
| 6356 | } while (exception.retry); |
| 6357 | return err; |
| 6358 | } |
| 6359 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6360 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6361 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6362 | { |
| 6363 | struct nfs4_layoutcommit_data *data = calldata; |
| 6364 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6365 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6366 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6367 | nfs41_setup_sequence(session, |
| 6368 | &data->args.seq_args, |
| 6369 | &data->res.seq_res, |
| 6370 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | static void |
| 6374 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6375 | { |
| 6376 | struct nfs4_layoutcommit_data *data = calldata; |
| 6377 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6378 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6379 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6380 | return; |
| 6381 | |
| 6382 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6383 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6384 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6385 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6386 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6387 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6388 | break; |
| 6389 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6390 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6391 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6392 | break; |
| 6393 | default: |
| 6394 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6395 | rpc_restart_call_prepare(task); |
| 6396 | return; |
| 6397 | } |
| 6398 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | static void nfs4_layoutcommit_release(void *calldata) |
| 6402 | { |
| 6403 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6404 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6405 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6406 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6407 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6408 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6409 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6410 | list_del_init(&lseg->pls_lc_list); |
| 6411 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6412 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6413 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6414 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6415 | |
| 6416 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6417 | smp_mb__after_clear_bit(); |
| 6418 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6419 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6420 | put_rpccred(data->cred); |
| 6421 | kfree(data); |
| 6422 | } |
| 6423 | |
| 6424 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6425 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6426 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6427 | .rpc_release = nfs4_layoutcommit_release, |
| 6428 | }; |
| 6429 | |
| 6430 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6431 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6432 | { |
| 6433 | struct rpc_message msg = { |
| 6434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6435 | .rpc_argp = &data->args, |
| 6436 | .rpc_resp = &data->res, |
| 6437 | .rpc_cred = data->cred, |
| 6438 | }; |
| 6439 | struct rpc_task_setup task_setup_data = { |
| 6440 | .task = &data->task, |
| 6441 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6442 | .rpc_message = &msg, |
| 6443 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6444 | .callback_data = data, |
| 6445 | .flags = RPC_TASK_ASYNC, |
| 6446 | }; |
| 6447 | struct rpc_task *task; |
| 6448 | int status = 0; |
| 6449 | |
| 6450 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6451 | "lbw: %llu inode %lu\n", |
| 6452 | data->task.tk_pid, sync, |
| 6453 | data->args.lastbytewritten, |
| 6454 | data->args.inode->i_ino); |
| 6455 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6456 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6457 | task = rpc_run_task(&task_setup_data); |
| 6458 | if (IS_ERR(task)) |
| 6459 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6460 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6461 | goto out; |
| 6462 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6463 | if (status != 0) |
| 6464 | goto out; |
| 6465 | status = task->tk_status; |
| 6466 | out: |
| 6467 | dprintk("%s: status %d\n", __func__, status); |
| 6468 | rpc_put_task(task); |
| 6469 | return status; |
| 6470 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6471 | |
| 6472 | static int |
| 6473 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6474 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6475 | { |
| 6476 | struct nfs41_secinfo_no_name_args args = { |
| 6477 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6478 | }; |
| 6479 | struct nfs4_secinfo_res res = { |
| 6480 | .flavors = flavors, |
| 6481 | }; |
| 6482 | struct rpc_message msg = { |
| 6483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6484 | .rpc_argp = &args, |
| 6485 | .rpc_resp = &res, |
| 6486 | }; |
| 6487 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6488 | } |
| 6489 | |
| 6490 | static int |
| 6491 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6492 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6493 | { |
| 6494 | struct nfs4_exception exception = { }; |
| 6495 | int err; |
| 6496 | do { |
| 6497 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6498 | switch (err) { |
| 6499 | case 0: |
| 6500 | case -NFS4ERR_WRONGSEC: |
| 6501 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6502 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6503 | default: |
| 6504 | err = nfs4_handle_exception(server, err, &exception); |
| 6505 | } |
| 6506 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6507 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6508 | return err; |
| 6509 | } |
| 6510 | |
| 6511 | static int |
| 6512 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6513 | struct nfs_fsinfo *info) |
| 6514 | { |
| 6515 | int err; |
| 6516 | struct page *page; |
| 6517 | rpc_authflavor_t flavor; |
| 6518 | struct nfs4_secinfo_flavors *flavors; |
| 6519 | |
| 6520 | page = alloc_page(GFP_KERNEL); |
| 6521 | if (!page) { |
| 6522 | err = -ENOMEM; |
| 6523 | goto out; |
| 6524 | } |
| 6525 | |
| 6526 | flavors = page_address(page); |
| 6527 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6528 | |
| 6529 | /* |
| 6530 | * Fall back on "guess and check" method if |
| 6531 | * the server doesn't support SECINFO_NO_NAME |
| 6532 | */ |
| 6533 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6534 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6535 | goto out_freepage; |
| 6536 | } |
| 6537 | if (err) |
| 6538 | goto out_freepage; |
| 6539 | |
| 6540 | flavor = nfs_find_best_sec(flavors); |
| 6541 | if (err == 0) |
| 6542 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6543 | |
| 6544 | out_freepage: |
| 6545 | put_page(page); |
| 6546 | if (err == -EACCES) |
| 6547 | return -EPERM; |
| 6548 | out: |
| 6549 | return err; |
| 6550 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6551 | |
| 6552 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6553 | { |
| 6554 | int status; |
| 6555 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6556 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6557 | }; |
| 6558 | struct nfs41_test_stateid_res res; |
| 6559 | struct rpc_message msg = { |
| 6560 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6561 | .rpc_argp = &args, |
| 6562 | .rpc_resp = &res, |
| 6563 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6564 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6565 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6566 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6567 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6568 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6569 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6570 | if (status != NFS_OK) { |
| 6571 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6572 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6573 | } |
| 6574 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6575 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6576 | } |
| 6577 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6578 | /** |
| 6579 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6580 | * |
| 6581 | * @server: server / transport on which to perform the operation |
| 6582 | * @stateid: state ID to test |
| 6583 | * |
| 6584 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6585 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6586 | * failed or the state ID is not currently valid. |
| 6587 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6588 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6589 | { |
| 6590 | struct nfs4_exception exception = { }; |
| 6591 | int err; |
| 6592 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6593 | err = _nfs41_test_stateid(server, stateid); |
| 6594 | if (err != -NFS4ERR_DELAY) |
| 6595 | break; |
| 6596 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6597 | } while (exception.retry); |
| 6598 | return err; |
| 6599 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6600 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6601 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6602 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6603 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6604 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6605 | }; |
| 6606 | struct nfs41_free_stateid_res res; |
| 6607 | struct rpc_message msg = { |
| 6608 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6609 | .rpc_argp = &args, |
| 6610 | .rpc_resp = &res, |
| 6611 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6612 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6613 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6614 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6615 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6616 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6617 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6618 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6619 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6620 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6621 | } |
| 6622 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6623 | /** |
| 6624 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6625 | * |
| 6626 | * @server: server / transport on which to perform the operation |
| 6627 | * @stateid: state ID to release |
| 6628 | * |
| 6629 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6630 | * negative NFS4ERR value is returned. |
| 6631 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6632 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6633 | { |
| 6634 | struct nfs4_exception exception = { }; |
| 6635 | int err; |
| 6636 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6637 | err = _nfs4_free_stateid(server, stateid); |
| 6638 | if (err != -NFS4ERR_DELAY) |
| 6639 | break; |
| 6640 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6641 | } while (exception.retry); |
| 6642 | return err; |
| 6643 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6644 | |
| 6645 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6646 | const nfs4_stateid *s2) |
| 6647 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6648 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6649 | return false; |
| 6650 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6651 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6652 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6653 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6654 | return true; |
| 6655 | |
| 6656 | return false; |
| 6657 | } |
| 6658 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6659 | #endif /* CONFIG_NFS_V4_1 */ |
| 6660 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6661 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6662 | const nfs4_stateid *s2) |
| 6663 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6664 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6665 | } |
| 6666 | |
| 6667 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6668 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6669 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6670 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6671 | .recover_open = nfs4_open_reclaim, |
| 6672 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6673 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6674 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6675 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6676 | }; |
| 6677 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6678 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6679 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6680 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6681 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6682 | .recover_open = nfs4_open_reclaim, |
| 6683 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6684 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6685 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6686 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6687 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6688 | }; |
| 6689 | #endif /* CONFIG_NFS_V4_1 */ |
| 6690 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6691 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6692 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6693 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6694 | .recover_open = nfs4_open_expired, |
| 6695 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6696 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6697 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6698 | }; |
| 6699 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6700 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6701 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6702 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6703 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6704 | .recover_open = nfs41_open_expired, |
| 6705 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6706 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6707 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6708 | }; |
| 6709 | #endif /* CONFIG_NFS_V4_1 */ |
| 6710 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6711 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6712 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6713 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6714 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6715 | }; |
| 6716 | |
| 6717 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6718 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6719 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6720 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6721 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6722 | }; |
| 6723 | #endif |
| 6724 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6725 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6726 | .minor_version = 0, |
| 6727 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6728 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6729 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6730 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6731 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6732 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6733 | }; |
| 6734 | |
| 6735 | #if defined(CONFIG_NFS_V4_1) |
| 6736 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6737 | .minor_version = 1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6738 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6739 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6740 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6741 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6742 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6743 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6744 | }; |
| 6745 | #endif |
| 6746 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6747 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6748 | [0] = &nfs_v4_0_minor_ops, |
| 6749 | #if defined(CONFIG_NFS_V4_1) |
| 6750 | [1] = &nfs_v4_1_minor_ops, |
| 6751 | #endif |
| 6752 | }; |
| 6753 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6754 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6755 | .create = nfs_create, |
| 6756 | .lookup = nfs_lookup, |
| 6757 | .atomic_open = nfs_atomic_open, |
| 6758 | .link = nfs_link, |
| 6759 | .unlink = nfs_unlink, |
| 6760 | .symlink = nfs_symlink, |
| 6761 | .mkdir = nfs_mkdir, |
| 6762 | .rmdir = nfs_rmdir, |
| 6763 | .mknod = nfs_mknod, |
| 6764 | .rename = nfs_rename, |
| 6765 | .permission = nfs_permission, |
| 6766 | .getattr = nfs_getattr, |
| 6767 | .setattr = nfs_setattr, |
| 6768 | .getxattr = generic_getxattr, |
| 6769 | .setxattr = generic_setxattr, |
| 6770 | .listxattr = generic_listxattr, |
| 6771 | .removexattr = generic_removexattr, |
| 6772 | }; |
| 6773 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6774 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6775 | .permission = nfs_permission, |
| 6776 | .getattr = nfs_getattr, |
| 6777 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6778 | .getxattr = generic_getxattr, |
| 6779 | .setxattr = generic_setxattr, |
| 6780 | .listxattr = generic_listxattr, |
| 6781 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6782 | }; |
| 6783 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6784 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6785 | .version = 4, /* protocol version */ |
| 6786 | .dentry_ops = &nfs4_dentry_operations, |
| 6787 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6788 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6789 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6791 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6792 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | .getattr = nfs4_proc_getattr, |
| 6794 | .setattr = nfs4_proc_setattr, |
| 6795 | .lookup = nfs4_proc_lookup, |
| 6796 | .access = nfs4_proc_access, |
| 6797 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6798 | .create = nfs4_proc_create, |
| 6799 | .remove = nfs4_proc_remove, |
| 6800 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6801 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6802 | .unlink_done = nfs4_proc_unlink_done, |
| 6803 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6804 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6805 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6806 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6807 | .link = nfs4_proc_link, |
| 6808 | .symlink = nfs4_proc_symlink, |
| 6809 | .mkdir = nfs4_proc_mkdir, |
| 6810 | .rmdir = nfs4_proc_remove, |
| 6811 | .readdir = nfs4_proc_readdir, |
| 6812 | .mknod = nfs4_proc_mknod, |
| 6813 | .statfs = nfs4_proc_statfs, |
| 6814 | .fsinfo = nfs4_proc_fsinfo, |
| 6815 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6816 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6817 | .decode_dirent = nfs4_decode_dirent, |
| 6818 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6819 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6820 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6821 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6822 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6823 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6824 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6825 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6826 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6827 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6828 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6829 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6830 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6831 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6832 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6833 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6834 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6835 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6836 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6837 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6838 | .create_server = nfs4_create_server, |
| 6839 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6840 | }; |
| 6841 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6842 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6843 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6844 | .list = nfs4_xattr_list_nfs4_acl, |
| 6845 | .get = nfs4_xattr_get_nfs4_acl, |
| 6846 | .set = nfs4_xattr_set_nfs4_acl, |
| 6847 | }; |
| 6848 | |
| 6849 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6850 | &nfs4_xattr_nfs4_acl_handler, |
| 6851 | NULL |
| 6852 | }; |
| 6853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6854 | /* |
| 6855 | * Local variables: |
| 6856 | * c-basic-offset: 8 |
| 6857 | * End: |
| 6858 | */ |