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: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 96 | case -NFS4ERR_LAYOUTTRYLATER: |
| 97 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 98 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 99 | case -NFS4ERR_WRONGSEC: |
| 100 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 101 | case -NFS4ERR_BADOWNER: |
| 102 | case -NFS4ERR_BADNAME: |
| 103 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 104 | case -NFS4ERR_SHARE_DENIED: |
| 105 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 106 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 107 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 108 | case -NFS4ERR_ACCESS: |
| 109 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 110 | case -NFS4ERR_FILE_OPEN: |
| 111 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 112 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 114 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 115 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 117 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* |
| 121 | * This is our standard bitmap for GETATTR requests. |
| 122 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 123 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | FATTR4_WORD0_TYPE |
| 125 | | FATTR4_WORD0_CHANGE |
| 126 | | FATTR4_WORD0_SIZE |
| 127 | | FATTR4_WORD0_FSID |
| 128 | | FATTR4_WORD0_FILEID, |
| 129 | FATTR4_WORD1_MODE |
| 130 | | FATTR4_WORD1_NUMLINKS |
| 131 | | FATTR4_WORD1_OWNER |
| 132 | | FATTR4_WORD1_OWNER_GROUP |
| 133 | | FATTR4_WORD1_RAWDEV |
| 134 | | FATTR4_WORD1_SPACE_USED |
| 135 | | FATTR4_WORD1_TIME_ACCESS |
| 136 | | FATTR4_WORD1_TIME_METADATA |
| 137 | | FATTR4_WORD1_TIME_MODIFY |
| 138 | }; |
| 139 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 140 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 141 | FATTR4_WORD0_TYPE |
| 142 | | FATTR4_WORD0_CHANGE |
| 143 | | FATTR4_WORD0_SIZE |
| 144 | | FATTR4_WORD0_FSID |
| 145 | | FATTR4_WORD0_FILEID, |
| 146 | FATTR4_WORD1_MODE |
| 147 | | FATTR4_WORD1_NUMLINKS |
| 148 | | FATTR4_WORD1_OWNER |
| 149 | | FATTR4_WORD1_OWNER_GROUP |
| 150 | | FATTR4_WORD1_RAWDEV |
| 151 | | FATTR4_WORD1_SPACE_USED |
| 152 | | FATTR4_WORD1_TIME_ACCESS |
| 153 | | FATTR4_WORD1_TIME_METADATA |
| 154 | | FATTR4_WORD1_TIME_MODIFY, |
| 155 | FATTR4_WORD2_MDSTHRESHOLD |
| 156 | }; |
| 157 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 158 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 159 | FATTR4_WORD0_TYPE |
| 160 | | FATTR4_WORD0_CHANGE |
| 161 | | FATTR4_WORD0_FILEID, |
| 162 | }; |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | const u32 nfs4_statfs_bitmap[2] = { |
| 165 | FATTR4_WORD0_FILES_AVAIL |
| 166 | | FATTR4_WORD0_FILES_FREE |
| 167 | | FATTR4_WORD0_FILES_TOTAL, |
| 168 | FATTR4_WORD1_SPACE_AVAIL |
| 169 | | FATTR4_WORD1_SPACE_FREE |
| 170 | | FATTR4_WORD1_SPACE_TOTAL |
| 171 | }; |
| 172 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 173 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | FATTR4_WORD0_MAXLINK |
| 175 | | FATTR4_WORD0_MAXNAME, |
| 176 | 0 |
| 177 | }; |
| 178 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 179 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | | FATTR4_WORD0_MAXREAD |
| 181 | | FATTR4_WORD0_MAXWRITE |
| 182 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 183 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 184 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 185 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 188 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 189 | FATTR4_WORD0_TYPE |
| 190 | | FATTR4_WORD0_CHANGE |
| 191 | | FATTR4_WORD0_SIZE |
| 192 | | FATTR4_WORD0_FSID |
| 193 | | FATTR4_WORD0_FILEID |
| 194 | | FATTR4_WORD0_FS_LOCATIONS, |
| 195 | FATTR4_WORD1_MODE |
| 196 | | FATTR4_WORD1_NUMLINKS |
| 197 | | FATTR4_WORD1_OWNER |
| 198 | | FATTR4_WORD1_OWNER_GROUP |
| 199 | | FATTR4_WORD1_RAWDEV |
| 200 | | FATTR4_WORD1_SPACE_USED |
| 201 | | FATTR4_WORD1_TIME_ACCESS |
| 202 | | FATTR4_WORD1_TIME_METADATA |
| 203 | | FATTR4_WORD1_TIME_MODIFY |
| 204 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 205 | }; |
| 206 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 207 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | struct nfs4_readdir_arg *readdir) |
| 209 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 210 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 213 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | readdir->cookie = 0; |
| 219 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 220 | if (cookie == 2) |
| 221 | return; |
| 222 | |
| 223 | /* |
| 224 | * NFSv4 servers do not return entries for '.' and '..' |
| 225 | * Therefore, we fake these entries here. We let '.' |
| 226 | * have cookie 0 and '..' have cookie 1. Note that |
| 227 | * when talking to the server, we always send cookie 0 |
| 228 | * instead of 1 or 2. |
| 229 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 230 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | if (cookie == 0) { |
| 233 | *p++ = xdr_one; /* next */ |
| 234 | *p++ = xdr_zero; /* cookie, first word */ |
| 235 | *p++ = xdr_one; /* cookie, second word */ |
| 236 | *p++ = xdr_one; /* entry len */ |
| 237 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 238 | p++; |
| 239 | *p++ = xdr_one; /* bitmap length */ |
| 240 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 241 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 242 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | *p++ = xdr_one; /* next */ |
| 246 | *p++ = xdr_zero; /* cookie, first word */ |
| 247 | *p++ = xdr_two; /* cookie, second word */ |
| 248 | *p++ = xdr_two; /* entry len */ |
| 249 | memcpy(p, "..\0\0", 4); /* entry */ |
| 250 | p++; |
| 251 | *p++ = xdr_one; /* bitmap length */ |
| 252 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 253 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 254 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | readdir->pgbase = (char *)p - (char *)start; |
| 257 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 258 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 261 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 262 | { |
| 263 | int res = 0; |
| 264 | |
| 265 | might_sleep(); |
| 266 | |
| 267 | if (*timeout <= 0) |
| 268 | *timeout = NFS4_POLL_RETRY_MIN; |
| 269 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 270 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 271 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 272 | if (fatal_signal_pending(current)) |
| 273 | res = -ERESTARTSYS; |
| 274 | *timeout <<= 1; |
| 275 | return res; |
| 276 | } |
| 277 | |
| 278 | /* This is the error handling routine for processes that are allowed |
| 279 | * to sleep. |
| 280 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 281 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 282 | { |
| 283 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 284 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 285 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 286 | int ret = errorcode; |
| 287 | |
| 288 | exception->retry = 0; |
| 289 | switch(errorcode) { |
| 290 | case 0: |
| 291 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 292 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 293 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 294 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 295 | exception->retry = 1; |
| 296 | return 0; |
| 297 | } |
| 298 | if (state == NULL) |
| 299 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 300 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 301 | if (ret < 0) |
| 302 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 303 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 304 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 305 | case -NFS4ERR_ADMIN_REVOKED: |
| 306 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 307 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 308 | nfs_remove_bad_delegation(inode); |
| 309 | exception->retry = 1; |
| 310 | break; |
| 311 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 312 | if (state == NULL) |
| 313 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 314 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 315 | if (ret < 0) |
| 316 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 317 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 318 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 319 | if (state != NULL) { |
| 320 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 321 | if (ret < 0) |
| 322 | break; |
| 323 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 324 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 325 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 326 | nfs4_schedule_lease_recovery(clp); |
| 327 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 328 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 329 | case -NFS4ERR_BADSESSION: |
| 330 | case -NFS4ERR_BADSLOT: |
| 331 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 332 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 333 | case -NFS4ERR_DEADSESSION: |
| 334 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 335 | case -NFS4ERR_SEQ_MISORDERED: |
| 336 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 337 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 338 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 339 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 340 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 342 | if (exception->timeout > HZ) { |
| 343 | /* We have retried a decent amount, time to |
| 344 | * fail |
| 345 | */ |
| 346 | ret = -EBUSY; |
| 347 | break; |
| 348 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 349 | case -NFS4ERR_GRACE: |
| 350 | case -NFS4ERR_DELAY: |
| 351 | ret = nfs4_delay(server->client, &exception->timeout); |
| 352 | if (ret != 0) |
| 353 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 354 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | case -NFS4ERR_OLD_STATEID: |
| 356 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 357 | break; |
| 358 | case -NFS4ERR_BADOWNER: |
| 359 | /* The following works around a Linux server bug! */ |
| 360 | case -NFS4ERR_BADNAME: |
| 361 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 362 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 363 | exception->retry = 1; |
| 364 | printk(KERN_WARNING "NFS: v4 server %s " |
| 365 | "does not accept raw " |
| 366 | "uid/gids. " |
| 367 | "Reenabling the idmapper.\n", |
| 368 | server->nfs_client->cl_hostname); |
| 369 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 370 | } |
| 371 | /* We failed to handle the error */ |
| 372 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 373 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 374 | ret = nfs4_wait_clnt_recover(clp); |
| 375 | if (ret == 0) |
| 376 | exception->retry = 1; |
| 377 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 381 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | spin_lock(&clp->cl_lock); |
| 384 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 385 | clp->cl_last_renewal = timestamp; |
| 386 | spin_unlock(&clp->cl_lock); |
| 387 | } |
| 388 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 389 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 390 | { |
| 391 | do_renew_lease(server->nfs_client, timestamp); |
| 392 | } |
| 393 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 394 | #if defined(CONFIG_NFS_V4_1) |
| 395 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 396 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 397 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 398 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 399 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 400 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 401 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 402 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 403 | /* just wake up the next guy waiting since |
| 404 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 405 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 406 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 407 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 408 | tbl = res->sr_slot->table; |
| 409 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 410 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 411 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 412 | /* Be nice to the server: try to ensure that the last transmitted |
| 413 | * value for highest_user_slotid <= target_highest_slotid |
| 414 | */ |
| 415 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 416 | send_new_highest_used_slotid = true; |
| 417 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 418 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 419 | send_new_highest_used_slotid = false; |
| 420 | goto out_unlock; |
| 421 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 422 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 423 | |
| 424 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 425 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 426 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 427 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 428 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 429 | if (send_new_highest_used_slotid) |
| 430 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 433 | 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] | 434 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 435 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 436 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 437 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 438 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 439 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 440 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 441 | /* don't increment the sequence number if the task wasn't sent */ |
| 442 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 443 | goto out; |
| 444 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 445 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 446 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 447 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 448 | if (slot->interrupted) { |
| 449 | slot->interrupted = 0; |
| 450 | interrupted = true; |
| 451 | } |
| 452 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 453 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 454 | switch (res->sr_status) { |
| 455 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 456 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 457 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 458 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 459 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 460 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 461 | if (res->sr_status_flags != 0) |
| 462 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 463 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 464 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 465 | case 1: |
| 466 | /* |
| 467 | * sr_status remains 1 if an RPC level error occurred. |
| 468 | * The server may or may not have processed the sequence |
| 469 | * operation.. |
| 470 | * Mark the slot as having hosted an interrupted RPC call. |
| 471 | */ |
| 472 | slot->interrupted = 1; |
| 473 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 474 | case -NFS4ERR_DELAY: |
| 475 | /* The server detected a resend of the RPC call and |
| 476 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 477 | * of RFC5661. |
| 478 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 479 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 480 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 481 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 482 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 483 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 484 | case -NFS4ERR_BADSLOT: |
| 485 | /* |
| 486 | * The slot id we used was probably retired. Try again |
| 487 | * using a different slot id. |
| 488 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 489 | goto retry_nowait; |
| 490 | case -NFS4ERR_SEQ_MISORDERED: |
| 491 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 492 | * Was the last operation on this sequence interrupted? |
| 493 | * If so, retry after bumping the sequence number. |
| 494 | */ |
| 495 | if (interrupted) { |
| 496 | ++slot->seq_nr; |
| 497 | goto retry_nowait; |
| 498 | } |
| 499 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 500 | * Could this slot have been previously retired? |
| 501 | * If so, then the server may be expecting seq_nr = 1! |
| 502 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 503 | if (slot->seq_nr != 1) { |
| 504 | slot->seq_nr = 1; |
| 505 | goto retry_nowait; |
| 506 | } |
| 507 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 508 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 509 | ++slot->seq_nr; |
| 510 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 511 | default: |
| 512 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 513 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 514 | } |
| 515 | out: |
| 516 | /* The session may be reset by one of the error handlers. */ |
| 517 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 518 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 519 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 520 | retry_nowait: |
| 521 | if (rpc_restart_call_prepare(task)) { |
| 522 | task->tk_status = 0; |
| 523 | ret = 0; |
| 524 | } |
| 525 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 526 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 527 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 528 | goto out; |
| 529 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 530 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 531 | } |
| 532 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 533 | static int nfs4_sequence_done(struct rpc_task *task, |
| 534 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 535 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 536 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 537 | return 1; |
| 538 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 541 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 542 | struct nfs4_sequence_res *res, int cache_reply) |
| 543 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 544 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 545 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 546 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 547 | if (cache_reply) |
| 548 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 549 | res->sr_slot = NULL; |
| 550 | } |
| 551 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 552 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 553 | { |
| 554 | args->sa_privileged = 1; |
| 555 | } |
| 556 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 557 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 558 | struct nfs4_sequence_args *args, |
| 559 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 560 | struct rpc_task *task) |
| 561 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 562 | struct nfs4_slot *slot; |
| 563 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 564 | |
| 565 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 566 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 567 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 568 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 569 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 570 | tbl = &session->fc_slot_table; |
| 571 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 572 | task->tk_timeout = 0; |
| 573 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 574 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 575 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 576 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 577 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 578 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 579 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 580 | } |
| 581 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 582 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 583 | if (IS_ERR(slot)) { |
| 584 | /* If out of memory, try again in 1/4 second */ |
| 585 | if (slot == ERR_PTR(-ENOMEM)) |
| 586 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 587 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 588 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 589 | } |
| 590 | spin_unlock(&tbl->slot_tbl_lock); |
| 591 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 592 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 593 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 594 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 595 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 596 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 597 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 598 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 599 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 600 | /* |
| 601 | * sr_status is only set in decode_sequence, and so will remain |
| 602 | * set to 1 if an rpc level failure occurs. |
| 603 | */ |
| 604 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 605 | out_success: |
| 606 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 607 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 608 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 609 | /* Privileged tasks are queued with top priority */ |
| 610 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 611 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 612 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 613 | else |
| 614 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 615 | spin_unlock(&tbl->slot_tbl_lock); |
| 616 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 618 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 620 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 621 | struct nfs4_sequence_args *args, |
| 622 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | struct rpc_task *task) |
| 624 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 625 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 626 | int ret = 0; |
| 627 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 628 | if (session == NULL) { |
| 629 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 631 | } |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 632 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 633 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 634 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 635 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 636 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 637 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 638 | out: |
| 639 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 644 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 645 | struct nfs4_sequence_args *seq_args; |
| 646 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 647 | }; |
| 648 | |
| 649 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 650 | { |
| 651 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 652 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 654 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 655 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 656 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 657 | } |
| 658 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 659 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 660 | { |
| 661 | struct nfs41_call_sync_data *data = calldata; |
| 662 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 663 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 664 | } |
| 665 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 666 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 668 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | }; |
| 670 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 671 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 672 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 673 | struct rpc_message *msg, |
| 674 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 675 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 676 | { |
| 677 | int ret; |
| 678 | struct rpc_task *task; |
| 679 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 680 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 681 | .seq_args = args, |
| 682 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 683 | }; |
| 684 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 685 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | .rpc_message = msg, |
| 687 | .callback_ops = &nfs41_call_sync_ops, |
| 688 | .callback_data = &data |
| 689 | }; |
| 690 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 691 | task = rpc_run_task(&task_setup); |
| 692 | if (IS_ERR(task)) |
| 693 | ret = PTR_ERR(task); |
| 694 | else { |
| 695 | ret = task->tk_status; |
| 696 | rpc_put_task(task); |
| 697 | } |
| 698 | return ret; |
| 699 | } |
| 700 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 701 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 702 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 703 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 704 | struct nfs4_sequence_res *res, int cache_reply) |
| 705 | { |
| 706 | } |
| 707 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 708 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 709 | { |
| 710 | } |
| 711 | |
| 712 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 713 | static int nfs4_sequence_done(struct rpc_task *task, |
| 714 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 715 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 716 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 717 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 718 | #endif /* CONFIG_NFS_V4_1 */ |
| 719 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 720 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 721 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 722 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 723 | struct rpc_message *msg, |
| 724 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 725 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 726 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 727 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 730 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 731 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 732 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 733 | struct rpc_message *msg, |
| 734 | struct nfs4_sequence_args *args, |
| 735 | struct nfs4_sequence_res *res, |
| 736 | int cache_reply) |
| 737 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 738 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 739 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 740 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 741 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 742 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 743 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 745 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 747 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 748 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 749 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 750 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 751 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 752 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 753 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 756 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 757 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct nfs_openargs o_arg; |
| 759 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 760 | struct nfs_open_confirmargs c_arg; |
| 761 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 762 | struct nfs4_string owner_name; |
| 763 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 764 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 766 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 768 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 770 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 771 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 772 | int rpc_status; |
| 773 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 774 | }; |
| 775 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 776 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 777 | int err, struct nfs4_exception *exception) |
| 778 | { |
| 779 | if (err != -EINVAL) |
| 780 | return false; |
| 781 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 782 | return false; |
| 783 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 784 | exception->retry = 1; |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | static enum open_claim_type4 |
| 789 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 790 | enum open_claim_type4 claim) |
| 791 | { |
| 792 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 793 | return claim; |
| 794 | switch (claim) { |
| 795 | default: |
| 796 | return claim; |
| 797 | case NFS4_OPEN_CLAIM_FH: |
| 798 | return NFS4_OPEN_CLAIM_NULL; |
| 799 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 800 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 801 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 802 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 803 | } |
| 804 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 805 | |
| 806 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 807 | { |
| 808 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 809 | p->o_res.seqid = p->o_arg.seqid; |
| 810 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 811 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 812 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 813 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 814 | 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] | 815 | } |
| 816 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 817 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 818 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 819 | const struct iattr *attrs, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 820 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 821 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 823 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | struct inode *dir = parent->d_inode; |
| 825 | struct nfs_server *server = NFS_SERVER(dir); |
| 826 | struct nfs4_opendata *p; |
| 827 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 828 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | if (p == NULL) |
| 830 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 831 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | if (p->o_arg.seqid == NULL) |
| 833 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 834 | nfs_sb_active(dentry->d_sb); |
| 835 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 836 | p->dir = parent; |
| 837 | p->owner = sp; |
| 838 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 839 | p->o_arg.open_flags = flags; |
| 840 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 841 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 842 | * will return permission denied for all bits until close */ |
| 843 | if (!(flags & O_EXCL)) { |
| 844 | /* ask server to check for all possible rights as results |
| 845 | * are cached */ |
| 846 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 847 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 848 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 849 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 850 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 851 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 852 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 853 | p->o_arg.server = server; |
| 854 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 855 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 856 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 857 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 858 | case NFS4_OPEN_CLAIM_NULL: |
| 859 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 860 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 861 | p->o_arg.fh = NFS_FH(dir); |
| 862 | break; |
| 863 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 864 | case NFS4_OPEN_CLAIM_FH: |
| 865 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 866 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 867 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 868 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 869 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 870 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 871 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 872 | p->o_arg.u.attrs = &p->attrs; |
| 873 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 874 | |
| 875 | verf[0] = jiffies; |
| 876 | verf[1] = current->pid; |
| 877 | memcpy(p->o_arg.u.verifier.data, verf, |
| 878 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 879 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 880 | p->c_arg.fh = &p->o_res.fh; |
| 881 | p->c_arg.stateid = &p->o_res.stateid; |
| 882 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 883 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 884 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 885 | return p; |
| 886 | err_free: |
| 887 | kfree(p); |
| 888 | err: |
| 889 | dput(parent); |
| 890 | return NULL; |
| 891 | } |
| 892 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 893 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 894 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 895 | struct nfs4_opendata *p = container_of(kref, |
| 896 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 897 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 898 | |
| 899 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 900 | if (p->state != NULL) |
| 901 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 902 | nfs4_put_state_owner(p->owner); |
| 903 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 904 | dput(p->dentry); |
| 905 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 906 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 907 | kfree(p); |
| 908 | } |
| 909 | |
| 910 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 911 | { |
| 912 | if (p != NULL) |
| 913 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 916 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 917 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 918 | int ret; |
| 919 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 920 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 921 | return ret; |
| 922 | } |
| 923 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | 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] | 925 | { |
| 926 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 928 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 929 | goto out; |
| 930 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 931 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 932 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 933 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 934 | break; |
| 935 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 936 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 937 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 938 | break; |
| 939 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 940 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 941 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 942 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 943 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 944 | return ret; |
| 945 | } |
| 946 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 948 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 949 | if (delegation == NULL) |
| 950 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 952 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 953 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 954 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 955 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 956 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 957 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 958 | return 1; |
| 959 | } |
| 960 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 962 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 964 | case FMODE_WRITE: |
| 965 | state->n_wronly++; |
| 966 | break; |
| 967 | case FMODE_READ: |
| 968 | state->n_rdonly++; |
| 969 | break; |
| 970 | case FMODE_READ|FMODE_WRITE: |
| 971 | state->n_rdwr++; |
| 972 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 974 | } |
| 975 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 976 | 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] | 977 | { |
| 978 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 979 | nfs4_stateid_copy(&state->stateid, stateid); |
| 980 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 981 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 982 | case FMODE_READ: |
| 983 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 984 | break; |
| 985 | case FMODE_WRITE: |
| 986 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 987 | break; |
| 988 | case FMODE_READ|FMODE_WRITE: |
| 989 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 990 | } |
| 991 | } |
| 992 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 993 | 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] | 994 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 995 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 997 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 998 | } |
| 999 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | 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] | 1001 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1002 | /* |
| 1003 | * Protect the call to nfs4_state_set_mode_locked and |
| 1004 | * serialise the stateid update |
| 1005 | */ |
| 1006 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1007 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1008 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1009 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1010 | } |
| 1011 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1012 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1013 | write_sequnlock(&state->seqlock); |
| 1014 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1015 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1016 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1019 | 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] | 1020 | { |
| 1021 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1022 | struct nfs_delegation *deleg_cur; |
| 1023 | int ret = 0; |
| 1024 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1026 | |
| 1027 | rcu_read_lock(); |
| 1028 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1029 | if (deleg_cur == NULL) |
| 1030 | goto no_delegation; |
| 1031 | |
| 1032 | spin_lock(&deleg_cur->lock); |
| 1033 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1034 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1036 | goto no_delegation_unlock; |
| 1037 | |
| 1038 | if (delegation == NULL) |
| 1039 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1040 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1041 | goto no_delegation_unlock; |
| 1042 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1043 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1044 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1045 | ret = 1; |
| 1046 | no_delegation_unlock: |
| 1047 | spin_unlock(&deleg_cur->lock); |
| 1048 | no_delegation: |
| 1049 | rcu_read_unlock(); |
| 1050 | |
| 1051 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1052 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1053 | ret = 1; |
| 1054 | } |
| 1055 | |
| 1056 | return ret; |
| 1057 | } |
| 1058 | |
| 1059 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1060 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1061 | { |
| 1062 | struct nfs_delegation *delegation; |
| 1063 | |
| 1064 | rcu_read_lock(); |
| 1065 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1066 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1067 | rcu_read_unlock(); |
| 1068 | return; |
| 1069 | } |
| 1070 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1071 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1072 | } |
| 1073 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1074 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1075 | { |
| 1076 | struct nfs4_state *state = opendata->state; |
| 1077 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1078 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1079 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1080 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1081 | nfs4_stateid stateid; |
| 1082 | int ret = -EAGAIN; |
| 1083 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1084 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1086 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1087 | if (can_open_cached(state, fmode, open_mode)) { |
| 1088 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1089 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1090 | goto out_return_state; |
| 1091 | } |
| 1092 | spin_unlock(&state->owner->so_lock); |
| 1093 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1094 | rcu_read_lock(); |
| 1095 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1096 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1097 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1098 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1099 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1100 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1101 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1102 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1103 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1104 | if (ret != 0) |
| 1105 | goto out; |
| 1106 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1107 | |
| 1108 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1109 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1110 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1111 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1112 | out: |
| 1113 | return ERR_PTR(ret); |
| 1114 | out_return_state: |
| 1115 | atomic_inc(&state->count); |
| 1116 | return state; |
| 1117 | } |
| 1118 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1119 | static void |
| 1120 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1121 | { |
| 1122 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1123 | struct nfs_delegation *delegation; |
| 1124 | int delegation_flags = 0; |
| 1125 | |
| 1126 | rcu_read_lock(); |
| 1127 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1128 | if (delegation) |
| 1129 | delegation_flags = delegation->flags; |
| 1130 | rcu_read_unlock(); |
| 1131 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1132 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1133 | "returning a delegation for " |
| 1134 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1135 | clp->cl_hostname); |
| 1136 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1137 | nfs_inode_set_delegation(state->inode, |
| 1138 | data->owner->so_cred, |
| 1139 | &data->o_res); |
| 1140 | else |
| 1141 | nfs_inode_reclaim_delegation(state->inode, |
| 1142 | data->owner->so_cred, |
| 1143 | &data->o_res); |
| 1144 | } |
| 1145 | |
| 1146 | /* |
| 1147 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1148 | * and update the nfs4_state. |
| 1149 | */ |
| 1150 | static struct nfs4_state * |
| 1151 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1152 | { |
| 1153 | struct inode *inode = data->state->inode; |
| 1154 | struct nfs4_state *state = data->state; |
| 1155 | int ret; |
| 1156 | |
| 1157 | if (!data->rpc_done) { |
| 1158 | ret = data->rpc_status; |
| 1159 | goto err; |
| 1160 | } |
| 1161 | |
| 1162 | ret = -ESTALE; |
| 1163 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1164 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1165 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1166 | goto err; |
| 1167 | |
| 1168 | ret = -ENOMEM; |
| 1169 | state = nfs4_get_open_state(inode, data->owner); |
| 1170 | if (state == NULL) |
| 1171 | goto err; |
| 1172 | |
| 1173 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1174 | if (ret) |
| 1175 | goto err; |
| 1176 | |
| 1177 | if (data->o_res.delegation_type != 0) |
| 1178 | nfs4_opendata_check_deleg(data, state); |
| 1179 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1180 | data->o_arg.fmode); |
| 1181 | |
| 1182 | return state; |
| 1183 | err: |
| 1184 | return ERR_PTR(ret); |
| 1185 | |
| 1186 | } |
| 1187 | |
| 1188 | static struct nfs4_state * |
| 1189 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1190 | { |
| 1191 | struct inode *inode; |
| 1192 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1193 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1194 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1195 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1196 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1197 | goto out; |
| 1198 | } |
| 1199 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1200 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1201 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1202 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1203 | 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] | 1204 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1205 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1206 | goto err; |
| 1207 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1208 | state = nfs4_get_open_state(inode, data->owner); |
| 1209 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1210 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1211 | if (data->o_res.delegation_type != 0) |
| 1212 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1213 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1214 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1215 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1216 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1217 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1218 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1219 | err_put_inode: |
| 1220 | iput(inode); |
| 1221 | err: |
| 1222 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1223 | } |
| 1224 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1225 | static struct nfs4_state * |
| 1226 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1227 | { |
| 1228 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1229 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1230 | return _nfs4_opendata_to_nfs4_state(data); |
| 1231 | } |
| 1232 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1233 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1234 | { |
| 1235 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1236 | struct nfs_open_context *ctx; |
| 1237 | |
| 1238 | spin_lock(&state->inode->i_lock); |
| 1239 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1240 | if (ctx->state != state) |
| 1241 | continue; |
| 1242 | get_nfs_open_context(ctx); |
| 1243 | spin_unlock(&state->inode->i_lock); |
| 1244 | return ctx; |
| 1245 | } |
| 1246 | spin_unlock(&state->inode->i_lock); |
| 1247 | return ERR_PTR(-ENOENT); |
| 1248 | } |
| 1249 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1250 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1251 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1252 | { |
| 1253 | struct nfs4_opendata *opendata; |
| 1254 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1255 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
| 1256 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1257 | if (opendata == NULL) |
| 1258 | return ERR_PTR(-ENOMEM); |
| 1259 | opendata->state = state; |
| 1260 | atomic_inc(&state->count); |
| 1261 | return opendata; |
| 1262 | } |
| 1263 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1264 | 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] | 1265 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1266 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1267 | int ret; |
| 1268 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1269 | opendata->o_arg.open_flags = 0; |
| 1270 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1271 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1272 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1273 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1274 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1275 | if (ret != 0) |
| 1276 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1277 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1278 | if (IS_ERR(newstate)) |
| 1279 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1280 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1281 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1286 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1287 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1288 | int ret; |
| 1289 | |
| 1290 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1291 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1292 | smp_rmb(); |
| 1293 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1294 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1295 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1296 | if (ret != 0) |
| 1297 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1298 | if (newstate != state) |
| 1299 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1300 | } |
| 1301 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1302 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1303 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1304 | if (ret != 0) |
| 1305 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1306 | if (newstate != state) |
| 1307 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1308 | } |
| 1309 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1310 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1311 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1312 | if (ret != 0) |
| 1313 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1314 | if (newstate != state) |
| 1315 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1316 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1317 | /* |
| 1318 | * We may have performed cached opens for all three recoveries. |
| 1319 | * Check if we need to update the current stateid. |
| 1320 | */ |
| 1321 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1322 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1323 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1324 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1325 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1326 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1327 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | /* |
| 1332 | * OPEN_RECLAIM: |
| 1333 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1335 | 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] | 1336 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1337 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1338 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1339 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | int status; |
| 1341 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1342 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1343 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1344 | if (IS_ERR(opendata)) |
| 1345 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1346 | rcu_read_lock(); |
| 1347 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1348 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1349 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1350 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1351 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1352 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1353 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | return status; |
| 1355 | } |
| 1356 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1357 | 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] | 1358 | { |
| 1359 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1360 | struct nfs4_exception exception = { }; |
| 1361 | int err; |
| 1362 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1363 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1364 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1365 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1366 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1367 | break; |
| 1368 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | } while (exception.retry); |
| 1370 | return err; |
| 1371 | } |
| 1372 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1373 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1374 | { |
| 1375 | struct nfs_open_context *ctx; |
| 1376 | int ret; |
| 1377 | |
| 1378 | ctx = nfs4_state_find_open_context(state); |
| 1379 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1380 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1381 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1382 | put_nfs_open_context(ctx); |
| 1383 | return ret; |
| 1384 | } |
| 1385 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1386 | static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1388 | switch (err) { |
| 1389 | default: |
| 1390 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1391 | "%d.\n", __func__, err); |
| 1392 | case 0: |
| 1393 | case -ENOENT: |
| 1394 | case -ESTALE: |
| 1395 | break; |
| 1396 | case -NFS4ERR_BADSESSION: |
| 1397 | case -NFS4ERR_BADSLOT: |
| 1398 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1399 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1400 | case -NFS4ERR_DEADSESSION: |
| 1401 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1402 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1403 | return -EAGAIN; |
| 1404 | case -NFS4ERR_STALE_CLIENTID: |
| 1405 | case -NFS4ERR_STALE_STATEID: |
| 1406 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1407 | case -NFS4ERR_EXPIRED: |
| 1408 | /* Don't recall a delegation if it was lost */ |
| 1409 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1410 | return -EAGAIN; |
| 1411 | case -NFS4ERR_DELEG_REVOKED: |
| 1412 | case -NFS4ERR_ADMIN_REVOKED: |
| 1413 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1414 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1415 | nfs_inode_find_state_and_recover(state->inode, |
| 1416 | stateid); |
| 1417 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1418 | return 0; |
| 1419 | case -NFS4ERR_DELAY: |
| 1420 | case -NFS4ERR_GRACE: |
| 1421 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1422 | ssleep(1); |
| 1423 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1424 | case -ENOMEM: |
| 1425 | case -NFS4ERR_DENIED: |
| 1426 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1427 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | return err; |
| 1430 | } |
| 1431 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1432 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1433 | { |
| 1434 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1435 | struct nfs4_opendata *opendata; |
| 1436 | int err; |
| 1437 | |
| 1438 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1439 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1440 | if (IS_ERR(opendata)) |
| 1441 | return PTR_ERR(opendata); |
| 1442 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1443 | err = nfs4_open_recover(opendata, state); |
| 1444 | nfs4_opendata_put(opendata); |
| 1445 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1446 | } |
| 1447 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1448 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1449 | { |
| 1450 | struct nfs4_opendata *data = calldata; |
| 1451 | |
| 1452 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1453 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1454 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1455 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1456 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1457 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1458 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | static void nfs4_open_confirm_release(void *calldata) |
| 1462 | { |
| 1463 | struct nfs4_opendata *data = calldata; |
| 1464 | struct nfs4_state *state = NULL; |
| 1465 | |
| 1466 | /* If this request hasn't been cancelled, do nothing */ |
| 1467 | if (data->cancelled == 0) |
| 1468 | goto out_free; |
| 1469 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1470 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1471 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1472 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1473 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1474 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1475 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1476 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1480 | .rpc_call_done = nfs4_open_confirm_done, |
| 1481 | .rpc_release = nfs4_open_confirm_release, |
| 1482 | }; |
| 1483 | |
| 1484 | /* |
| 1485 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1486 | */ |
| 1487 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1488 | { |
| 1489 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1490 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1491 | struct rpc_message msg = { |
| 1492 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1493 | .rpc_argp = &data->c_arg, |
| 1494 | .rpc_resp = &data->c_res, |
| 1495 | .rpc_cred = data->owner->so_cred, |
| 1496 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1497 | struct rpc_task_setup task_setup_data = { |
| 1498 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1499 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1500 | .callback_ops = &nfs4_open_confirm_ops, |
| 1501 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1502 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1503 | .flags = RPC_TASK_ASYNC, |
| 1504 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | int status; |
| 1506 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1507 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1508 | data->rpc_done = 0; |
| 1509 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1510 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1511 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1512 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1513 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1514 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1515 | if (status != 0) { |
| 1516 | data->cancelled = 1; |
| 1517 | smp_wmb(); |
| 1518 | } else |
| 1519 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1520 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | return status; |
| 1522 | } |
| 1523 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1524 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1526 | struct nfs4_opendata *data = calldata; |
| 1527 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame^] | 1528 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1529 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1530 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1531 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1532 | /* |
| 1533 | * Check if we still need to send an OPEN call, or if we can use |
| 1534 | * a delegation instead. |
| 1535 | */ |
| 1536 | if (data->state != NULL) { |
| 1537 | struct nfs_delegation *delegation; |
| 1538 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1539 | 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] | 1540 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1541 | rcu_read_lock(); |
| 1542 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1543 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1544 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1545 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1546 | rcu_read_unlock(); |
| 1547 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1548 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame^] | 1549 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1550 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1551 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1552 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1553 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1554 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1555 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1556 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1557 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1558 | &data->o_res.seq_res, |
| 1559 | task) != 0) |
| 1560 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame^] | 1561 | |
| 1562 | /* Set the create mode (note dependency on the session type) */ |
| 1563 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1564 | if (data->o_arg.open_flags & O_EXCL) { |
| 1565 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1566 | if (nfs4_has_persistent_session(clp)) |
| 1567 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1568 | else if (clp->cl_mvops->minor_version > 0) |
| 1569 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1570 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1571 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1572 | unlock_no_action: |
| 1573 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1574 | out_no_action: |
| 1575 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1576 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1577 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1578 | } |
| 1579 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1580 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1581 | { |
| 1582 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1584 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1585 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1586 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1587 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1588 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1589 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1590 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1591 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1592 | case S_IFREG: |
| 1593 | break; |
| 1594 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1595 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1598 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1599 | break; |
| 1600 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1601 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1602 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1603 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1604 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1605 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1606 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1607 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1608 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1609 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1610 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1611 | static void nfs4_open_release(void *calldata) |
| 1612 | { |
| 1613 | struct nfs4_opendata *data = calldata; |
| 1614 | struct nfs4_state *state = NULL; |
| 1615 | |
| 1616 | /* If this request hasn't been cancelled, do nothing */ |
| 1617 | if (data->cancelled == 0) |
| 1618 | goto out_free; |
| 1619 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1620 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1621 | goto out_free; |
| 1622 | /* In case we need an open_confirm, no cleanup! */ |
| 1623 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1624 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1625 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1626 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1627 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1628 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1629 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1633 | .rpc_call_prepare = nfs4_open_prepare, |
| 1634 | .rpc_call_done = nfs4_open_done, |
| 1635 | .rpc_release = nfs4_open_release, |
| 1636 | }; |
| 1637 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1638 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1639 | { |
| 1640 | struct inode *dir = data->dir->d_inode; |
| 1641 | struct nfs_server *server = NFS_SERVER(dir); |
| 1642 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1643 | struct nfs_openres *o_res = &data->o_res; |
| 1644 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1645 | struct rpc_message msg = { |
| 1646 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1647 | .rpc_argp = o_arg, |
| 1648 | .rpc_resp = o_res, |
| 1649 | .rpc_cred = data->owner->so_cred, |
| 1650 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1651 | struct rpc_task_setup task_setup_data = { |
| 1652 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1653 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1654 | .callback_ops = &nfs4_open_ops, |
| 1655 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1656 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1657 | .flags = RPC_TASK_ASYNC, |
| 1658 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1659 | int status; |
| 1660 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1661 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1662 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1663 | data->rpc_done = 0; |
| 1664 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1665 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1666 | if (isrecover) |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1667 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1668 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1669 | if (IS_ERR(task)) |
| 1670 | return PTR_ERR(task); |
| 1671 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1672 | if (status != 0) { |
| 1673 | data->cancelled = 1; |
| 1674 | smp_wmb(); |
| 1675 | } else |
| 1676 | status = data->rpc_status; |
| 1677 | rpc_put_task(task); |
| 1678 | |
| 1679 | return status; |
| 1680 | } |
| 1681 | |
| 1682 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1683 | { |
| 1684 | struct inode *dir = data->dir->d_inode; |
| 1685 | struct nfs_openres *o_res = &data->o_res; |
| 1686 | int status; |
| 1687 | |
| 1688 | status = nfs4_run_open_task(data, 1); |
| 1689 | if (status != 0 || !data->rpc_done) |
| 1690 | return status; |
| 1691 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1692 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1693 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1694 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1695 | status = _nfs4_proc_open_confirm(data); |
| 1696 | if (status != 0) |
| 1697 | return status; |
| 1698 | } |
| 1699 | |
| 1700 | return status; |
| 1701 | } |
| 1702 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1703 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1704 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1705 | struct nfs4_state *state, fmode_t fmode, |
| 1706 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1707 | { |
| 1708 | struct nfs_access_entry cache; |
| 1709 | u32 mask; |
| 1710 | |
| 1711 | /* access call failed or for some reason the server doesn't |
| 1712 | * support any access modes -- defer access call until later */ |
| 1713 | if (opendata->o_res.access_supported == 0) |
| 1714 | return 0; |
| 1715 | |
| 1716 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1717 | /* 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] | 1718 | * write mode bits, but POSIX allows the creating process to write. |
| 1719 | * use openflags to check for exec, because fmode won't |
| 1720 | * always have FMODE_EXEC set when file open for exec. */ |
| 1721 | if (openflags & __FMODE_EXEC) { |
| 1722 | /* ONLY check for exec rights */ |
| 1723 | mask = MAY_EXEC; |
| 1724 | } else if (fmode & FMODE_READ) |
| 1725 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1726 | |
| 1727 | cache.cred = cred; |
| 1728 | cache.jiffies = jiffies; |
| 1729 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1730 | nfs_access_add_cache(state->inode, &cache); |
| 1731 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1732 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1733 | return 0; |
| 1734 | |
| 1735 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1736 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1737 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1738 | } |
| 1739 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1740 | /* |
| 1741 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1742 | */ |
| 1743 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1744 | { |
| 1745 | struct inode *dir = data->dir->d_inode; |
| 1746 | struct nfs_server *server = NFS_SERVER(dir); |
| 1747 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1748 | struct nfs_openres *o_res = &data->o_res; |
| 1749 | int status; |
| 1750 | |
| 1751 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1752 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1753 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1754 | if (status != 0) { |
| 1755 | if (status == -NFS4ERR_BADNAME && |
| 1756 | !(o_arg->open_flags & O_CREAT)) |
| 1757 | return -ENOENT; |
| 1758 | return status; |
| 1759 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1760 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1761 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1762 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1763 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1764 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1765 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1766 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1768 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1770 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | } |
| 1772 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1773 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1774 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1777 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1778 | { |
| 1779 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1780 | } |
| 1781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | /* |
| 1783 | * OPEN_EXPIRED: |
| 1784 | * reclaim state on the server after a network partition. |
| 1785 | * Assumes caller holds the appropriate lock |
| 1786 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1787 | 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] | 1788 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1789 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1790 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1792 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1793 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1794 | if (IS_ERR(opendata)) |
| 1795 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1796 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1797 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1798 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1799 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1800 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1803 | 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] | 1804 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1805 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1806 | struct nfs4_exception exception = { }; |
| 1807 | int err; |
| 1808 | |
| 1809 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1810 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1811 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1812 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1813 | switch (err) { |
| 1814 | default: |
| 1815 | goto out; |
| 1816 | case -NFS4ERR_GRACE: |
| 1817 | case -NFS4ERR_DELAY: |
| 1818 | nfs4_handle_exception(server, err, &exception); |
| 1819 | err = 0; |
| 1820 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1821 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1822 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1823 | return err; |
| 1824 | } |
| 1825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1827 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1829 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1831 | ctx = nfs4_state_find_open_context(state); |
| 1832 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1833 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1834 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1835 | put_nfs_open_context(ctx); |
| 1836 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1839 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1840 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1841 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1842 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1843 | nfs4_stateid *stateid = &state->stateid; |
| 1844 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1845 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1846 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1847 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1848 | return; |
| 1849 | |
| 1850 | status = nfs41_test_stateid(server, stateid); |
| 1851 | if (status != NFS_OK) { |
| 1852 | /* Free the stateid unless the server explicitly |
| 1853 | * informs us the stateid is unrecognized. */ |
| 1854 | if (status != -NFS4ERR_BAD_STATEID) |
| 1855 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1856 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1857 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1858 | write_seqlock(&state->seqlock); |
| 1859 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1860 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1861 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | /** |
| 1866 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1867 | * |
| 1868 | * @state: NFSv4 state for an inode |
| 1869 | * |
| 1870 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1871 | * Otherwise a negative NFS4ERR value is returned. |
| 1872 | */ |
| 1873 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1874 | { |
| 1875 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1876 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1877 | int status; |
| 1878 | |
| 1879 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1880 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1881 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1882 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1883 | return -NFS4ERR_BAD_STATEID; |
| 1884 | |
| 1885 | status = nfs41_test_stateid(server, stateid); |
| 1886 | if (status != NFS_OK) { |
| 1887 | /* Free the stateid unless the server explicitly |
| 1888 | * informs us the stateid is unrecognized. */ |
| 1889 | if (status != -NFS4ERR_BAD_STATEID) |
| 1890 | nfs41_free_stateid(server, stateid); |
| 1891 | |
| 1892 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1893 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1894 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1895 | } |
| 1896 | return status; |
| 1897 | } |
| 1898 | |
| 1899 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1900 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1901 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1902 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1903 | nfs41_clear_delegation_stateid(state); |
| 1904 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1905 | if (status != NFS_OK) |
| 1906 | status = nfs4_open_expired(sp, state); |
| 1907 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1908 | } |
| 1909 | #endif |
| 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1912 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1913 | * fields corresponding to attributes that were used to store the verifier. |
| 1914 | * Make sure we clobber those fields in the later setattr call |
| 1915 | */ |
| 1916 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1917 | { |
| 1918 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1919 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1920 | sattr->ia_valid |= ATTR_ATIME; |
| 1921 | |
| 1922 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1923 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1924 | sattr->ia_valid |= ATTR_MTIME; |
| 1925 | } |
| 1926 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1927 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1928 | fmode_t fmode, |
| 1929 | int flags, |
| 1930 | struct nfs4_state **res) |
| 1931 | { |
| 1932 | struct nfs4_state_owner *sp = opendata->owner; |
| 1933 | struct nfs_server *server = sp->so_server; |
| 1934 | struct nfs4_state *state; |
| 1935 | unsigned int seq; |
| 1936 | int ret; |
| 1937 | |
| 1938 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1939 | |
| 1940 | ret = _nfs4_proc_open(opendata); |
| 1941 | if (ret != 0) |
| 1942 | goto out; |
| 1943 | |
| 1944 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1945 | ret = PTR_ERR(state); |
| 1946 | if (IS_ERR(state)) |
| 1947 | goto out; |
| 1948 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1949 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1950 | |
| 1951 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 1952 | if (ret != 0) |
| 1953 | goto out; |
| 1954 | |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1955 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1956 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1957 | *res = state; |
| 1958 | out: |
| 1959 | return ret; |
| 1960 | } |
| 1961 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1962 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1963 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1965 | static int _nfs4_do_open(struct inode *dir, |
| 1966 | struct dentry *dentry, |
| 1967 | fmode_t fmode, |
| 1968 | int flags, |
| 1969 | struct iattr *sattr, |
| 1970 | struct rpc_cred *cred, |
| 1971 | struct nfs4_state **res, |
| 1972 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | { |
| 1974 | struct nfs4_state_owner *sp; |
| 1975 | struct nfs4_state *state = NULL; |
| 1976 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1977 | struct nfs4_opendata *opendata; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1978 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1979 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
| 1981 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1983 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1984 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1986 | goto out_err; |
| 1987 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1988 | status = nfs4_recover_expired_lease(server); |
| 1989 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1990 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1991 | if (dentry->d_inode != NULL) |
| 1992 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1993 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1994 | if (dentry->d_inode) |
| 1995 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1996 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1997 | claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1998 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1999 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2001 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2002 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2003 | if (!opendata->f_attr.mdsthreshold) |
| 2004 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2005 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2006 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2007 | if (dentry->d_inode != NULL) |
| 2008 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2009 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2010 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2011 | if (status != 0) |
| 2012 | goto err_opendata_put; |
| 2013 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame^] | 2014 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2015 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2016 | nfs4_exclusive_attrset(opendata, sattr); |
| 2017 | |
| 2018 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2019 | status = nfs4_do_setattr(state->inode, cred, |
| 2020 | opendata->o_res.f_attr, sattr, |
| 2021 | state); |
| 2022 | if (status == 0) |
| 2023 | nfs_setattr_update_inode(state->inode, sattr); |
| 2024 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2025 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2026 | |
| 2027 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2028 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2029 | else |
| 2030 | kfree(opendata->f_attr.mdsthreshold); |
| 2031 | opendata->f_attr.mdsthreshold = NULL; |
| 2032 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2033 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | *res = state; |
| 2036 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2037 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2038 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2039 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2040 | err_put_state_owner: |
| 2041 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | *res = NULL; |
| 2044 | return status; |
| 2045 | } |
| 2046 | |
| 2047 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2048 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2049 | struct dentry *dentry, |
| 2050 | fmode_t fmode, |
| 2051 | int flags, |
| 2052 | struct iattr *sattr, |
| 2053 | struct rpc_cred *cred, |
| 2054 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2056 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | struct nfs4_exception exception = { }; |
| 2058 | struct nfs4_state *res; |
| 2059 | int status; |
| 2060 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2061 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2063 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2064 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | if (status == 0) |
| 2066 | break; |
| 2067 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2068 | * book-keeping w.r.t. state-changing operations |
| 2069 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2070 | * It is actually a sign of a bug on the client or on the server. |
| 2071 | * |
| 2072 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2073 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | * have unhashed the old state_owner for us, and that we can |
| 2075 | * therefore safely retry using a new one. We should still warn |
| 2076 | * the user though... |
| 2077 | */ |
| 2078 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2079 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2080 | " returned a bad sequence-id error!\n", |
| 2081 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | exception.retry = 1; |
| 2083 | continue; |
| 2084 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2085 | /* |
| 2086 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2087 | * state before it received the OPEN_CONFIRM. |
| 2088 | * Recover by retrying the request as per the discussion |
| 2089 | * on Page 181 of RFC3530. |
| 2090 | */ |
| 2091 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2092 | exception.retry = 1; |
| 2093 | continue; |
| 2094 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2095 | if (status == -EAGAIN) { |
| 2096 | /* We must have found a delegation */ |
| 2097 | exception.retry = 1; |
| 2098 | continue; |
| 2099 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2100 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2101 | continue; |
| 2102 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | status, &exception)); |
| 2104 | } while (exception.retry); |
| 2105 | return res; |
| 2106 | } |
| 2107 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2108 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2109 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2110 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2112 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2114 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | .iap = sattr, |
| 2116 | .server = server, |
| 2117 | .bitmask = server->attr_bitmask, |
| 2118 | }; |
| 2119 | struct nfs_setattrres res = { |
| 2120 | .fattr = fattr, |
| 2121 | .server = server, |
| 2122 | }; |
| 2123 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2125 | .rpc_argp = &arg, |
| 2126 | .rpc_resp = &res, |
| 2127 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2129 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2130 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2132 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2134 | if (state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2135 | struct nfs_lockowner lockowner = { |
| 2136 | .l_owner = current->files, |
| 2137 | .l_pid = current->tgid, |
| 2138 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2139 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2140 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2141 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2142 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2143 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2144 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2145 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2147 | 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] | 2148 | if (status == 0 && state != NULL) |
| 2149 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2150 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2153 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2154 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2155 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2157 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2158 | struct nfs4_exception exception = { |
| 2159 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2160 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2161 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | int err; |
| 2163 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2164 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2165 | switch (err) { |
| 2166 | case -NFS4ERR_OPENMODE: |
| 2167 | if (state && !(state->state & FMODE_WRITE)) { |
| 2168 | err = -EBADF; |
| 2169 | if (sattr->ia_valid & ATTR_OPEN) |
| 2170 | err = -EACCES; |
| 2171 | goto out; |
| 2172 | } |
| 2173 | } |
| 2174 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2176 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | return err; |
| 2178 | } |
| 2179 | |
| 2180 | struct nfs4_closedata { |
| 2181 | struct inode *inode; |
| 2182 | struct nfs4_state *state; |
| 2183 | struct nfs_closeargs arg; |
| 2184 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2185 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2186 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2187 | bool roc; |
| 2188 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | }; |
| 2190 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2191 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2192 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2193 | struct nfs4_closedata *calldata = data; |
| 2194 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2195 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2196 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2197 | if (calldata->roc) |
| 2198 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2199 | nfs4_put_open_state(calldata->state); |
| 2200 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2201 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2202 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2203 | kfree(calldata); |
| 2204 | } |
| 2205 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2206 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2207 | fmode_t fmode) |
| 2208 | { |
| 2209 | spin_lock(&state->owner->so_lock); |
| 2210 | if (!(fmode & FMODE_READ)) |
| 2211 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2212 | if (!(fmode & FMODE_WRITE)) |
| 2213 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2214 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2215 | spin_unlock(&state->owner->so_lock); |
| 2216 | } |
| 2217 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2218 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2220 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2223 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2224 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2225 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2226 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | /* hmm. we are done with the inode, and in the process of freeing |
| 2228 | * the state_owner. we keep this around to process errors |
| 2229 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | switch (task->tk_status) { |
| 2231 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2232 | if (calldata->roc) |
| 2233 | pnfs_roc_set_barrier(state->inode, |
| 2234 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2235 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2236 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2237 | nfs4_close_clear_stateid_flags(state, |
| 2238 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | break; |
| 2240 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2241 | case -NFS4ERR_OLD_STATEID: |
| 2242 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2244 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2245 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2247 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2248 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2250 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2251 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2252 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2255 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2257 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2258 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2259 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2260 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2261 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2262 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2263 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2264 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2265 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2266 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2267 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2268 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2269 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2270 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2271 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2272 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2273 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2274 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2275 | } |
| 2276 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2277 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2278 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2279 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2280 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2281 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2282 | if (!nfs4_valid_open_stateid(state)) |
| 2283 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2284 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2285 | |
| 2286 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2287 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2288 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2289 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2290 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2291 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2292 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2293 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2294 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2295 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2296 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2297 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2298 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2299 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2300 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2301 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2302 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2303 | &calldata->arg.seq_args, |
| 2304 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2305 | task) != 0) |
| 2306 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2307 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2308 | return; |
| 2309 | out_no_action: |
| 2310 | task->tk_action = NULL; |
| 2311 | out_wait: |
| 2312 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2315 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2316 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2317 | .rpc_call_done = nfs4_close_done, |
| 2318 | .rpc_release = nfs4_free_closedata, |
| 2319 | }; |
| 2320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | /* |
| 2322 | * It is possible for data to be read/written from a mem-mapped file |
| 2323 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2324 | * This means that we can't safely call nfsv4 close on a file until |
| 2325 | * the inode is cleared. This in turn means that we are not good |
| 2326 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2327 | * share state even when we are done with one of the three share |
| 2328 | * stateid's in the inode. |
| 2329 | * |
| 2330 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2331 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2332 | 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] | 2333 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2334 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2336 | struct nfs4_state_owner *sp = state->owner; |
| 2337 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2338 | struct rpc_message msg = { |
| 2339 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2340 | .rpc_cred = state->owner->so_cred, |
| 2341 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2342 | struct rpc_task_setup task_setup_data = { |
| 2343 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2344 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2345 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2346 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2347 | .flags = RPC_TASK_ASYNC, |
| 2348 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2349 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2351 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2353 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2354 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2355 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2357 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2358 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2360 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2361 | if (calldata->arg.seqid == NULL) |
| 2362 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2363 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2364 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2365 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2366 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2367 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2368 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2369 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2370 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2371 | msg.rpc_argp = &calldata->arg; |
| 2372 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2373 | task_setup_data.callback_data = calldata; |
| 2374 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2375 | if (IS_ERR(task)) |
| 2376 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2377 | status = 0; |
| 2378 | if (wait) |
| 2379 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2380 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2381 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2382 | out_free_calldata: |
| 2383 | kfree(calldata); |
| 2384 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2385 | nfs4_put_open_state(state); |
| 2386 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2387 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2390 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2391 | 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] | 2392 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | struct nfs4_state *state; |
| 2394 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2395 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2396 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2397 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2398 | if (IS_ERR(state)) |
| 2399 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2400 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2401 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2404 | 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] | 2405 | { |
| 2406 | if (ctx->state == NULL) |
| 2407 | return; |
| 2408 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2409 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2410 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2411 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | |
| 2414 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2415 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2416 | struct nfs4_server_caps_arg args = { |
| 2417 | .fhandle = fhandle, |
| 2418 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | struct nfs4_server_caps_res res = {}; |
| 2420 | struct rpc_message msg = { |
| 2421 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2422 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | .rpc_resp = &res, |
| 2424 | }; |
| 2425 | int status; |
| 2426 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2427 | 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] | 2428 | if (status == 0) { |
| 2429 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2430 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2431 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2432 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2433 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2434 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2436 | server->caps |= NFS_CAP_ACLS; |
| 2437 | if (res.has_links != 0) |
| 2438 | server->caps |= NFS_CAP_HARDLINKS; |
| 2439 | if (res.has_symlinks != 0) |
| 2440 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2441 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2442 | server->caps |= NFS_CAP_FILEID; |
| 2443 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2444 | server->caps |= NFS_CAP_MODE; |
| 2445 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2446 | server->caps |= NFS_CAP_NLINK; |
| 2447 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2448 | server->caps |= NFS_CAP_OWNER; |
| 2449 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2450 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2451 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2452 | server->caps |= NFS_CAP_ATIME; |
| 2453 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2454 | server->caps |= NFS_CAP_CTIME; |
| 2455 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2456 | server->caps |= NFS_CAP_MTIME; |
| 2457 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2458 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2459 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2460 | 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] | 2461 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2462 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | return status; |
| 2466 | } |
| 2467 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2468 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | { |
| 2470 | struct nfs4_exception exception = { }; |
| 2471 | int err; |
| 2472 | do { |
| 2473 | err = nfs4_handle_exception(server, |
| 2474 | _nfs4_server_capabilities(server, fhandle), |
| 2475 | &exception); |
| 2476 | } while (exception.retry); |
| 2477 | return err; |
| 2478 | } |
| 2479 | |
| 2480 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2481 | struct nfs_fsinfo *info) |
| 2482 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | struct nfs4_lookup_root_arg args = { |
| 2484 | .bitmask = nfs4_fattr_bitmap, |
| 2485 | }; |
| 2486 | struct nfs4_lookup_res res = { |
| 2487 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2488 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | .fh = fhandle, |
| 2490 | }; |
| 2491 | struct rpc_message msg = { |
| 2492 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2493 | .rpc_argp = &args, |
| 2494 | .rpc_resp = &res, |
| 2495 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2496 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2497 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2498 | 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] | 2499 | } |
| 2500 | |
| 2501 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2502 | struct nfs_fsinfo *info) |
| 2503 | { |
| 2504 | struct nfs4_exception exception = { }; |
| 2505 | int err; |
| 2506 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2507 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2508 | switch (err) { |
| 2509 | case 0: |
| 2510 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2511 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2512 | default: |
| 2513 | err = nfs4_handle_exception(server, err, &exception); |
| 2514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2516 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | return err; |
| 2518 | } |
| 2519 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2520 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2521 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2522 | { |
| 2523 | struct rpc_auth *auth; |
| 2524 | int ret; |
| 2525 | |
| 2526 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2527 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2528 | ret = -EIO; |
| 2529 | goto out; |
| 2530 | } |
| 2531 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2532 | out: |
| 2533 | return ret; |
| 2534 | } |
| 2535 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2536 | 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] | 2537 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2539 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2540 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2542 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2543 | if (len < 0) |
| 2544 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2545 | |
| 2546 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2547 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2548 | * thus has already been tried. */ |
| 2549 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2550 | continue; |
| 2551 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2552 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2553 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2554 | continue; |
| 2555 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2556 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2557 | /* |
| 2558 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2559 | * to access the mount. It could also mean that we tried to mount |
| 2560 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2561 | * existing mount programs don't handle -EACCES very well so it should |
| 2562 | * be mapped to -EPERM instead. |
| 2563 | */ |
| 2564 | if (status == -EACCES) |
| 2565 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2566 | return status; |
| 2567 | } |
| 2568 | |
| 2569 | /* |
| 2570 | * get the file handle for the "/" directory on the server |
| 2571 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2572 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2573 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2574 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2575 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2576 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2577 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2578 | /* |
| 2579 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2580 | * by nfs4_map_errors() as this function exits. |
| 2581 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2582 | 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] | 2583 | if (status == 0) |
| 2584 | status = nfs4_server_capabilities(server, fhandle); |
| 2585 | if (status == 0) |
| 2586 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2587 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2590 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2591 | struct nfs_fsinfo *info) |
| 2592 | { |
| 2593 | int error; |
| 2594 | struct nfs_fattr *fattr = info->fattr; |
| 2595 | |
| 2596 | error = nfs4_server_capabilities(server, mntfh); |
| 2597 | if (error < 0) { |
| 2598 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2599 | return error; |
| 2600 | } |
| 2601 | |
| 2602 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2603 | if (error < 0) { |
| 2604 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2605 | return error; |
| 2606 | } |
| 2607 | |
| 2608 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2609 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2610 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2611 | |
| 2612 | return error; |
| 2613 | } |
| 2614 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2615 | /* |
| 2616 | * Get locations and (maybe) other attributes of a referral. |
| 2617 | * Note that we'll actually follow the referral later when |
| 2618 | * we detect fsid mismatch in inode revalidation |
| 2619 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2620 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2621 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2622 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2623 | { |
| 2624 | int status = -ENOMEM; |
| 2625 | struct page *page = NULL; |
| 2626 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2627 | |
| 2628 | page = alloc_page(GFP_KERNEL); |
| 2629 | if (page == NULL) |
| 2630 | goto out; |
| 2631 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2632 | if (locations == NULL) |
| 2633 | goto out; |
| 2634 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2635 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2636 | if (status != 0) |
| 2637 | goto out; |
| 2638 | /* Make sure server returned a different fsid for the referral */ |
| 2639 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2640 | dprintk("%s: server did not return a different fsid for" |
| 2641 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2642 | status = -EIO; |
| 2643 | goto out; |
| 2644 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2645 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2646 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2647 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2648 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2649 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2650 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2651 | out: |
| 2652 | if (page) |
| 2653 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2654 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2655 | return status; |
| 2656 | } |
| 2657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2659 | { |
| 2660 | struct nfs4_getattr_arg args = { |
| 2661 | .fh = fhandle, |
| 2662 | .bitmask = server->attr_bitmask, |
| 2663 | }; |
| 2664 | struct nfs4_getattr_res res = { |
| 2665 | .fattr = fattr, |
| 2666 | .server = server, |
| 2667 | }; |
| 2668 | struct rpc_message msg = { |
| 2669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2670 | .rpc_argp = &args, |
| 2671 | .rpc_resp = &res, |
| 2672 | }; |
| 2673 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2674 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2675 | 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] | 2676 | } |
| 2677 | |
| 2678 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2679 | { |
| 2680 | struct nfs4_exception exception = { }; |
| 2681 | int err; |
| 2682 | do { |
| 2683 | err = nfs4_handle_exception(server, |
| 2684 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2685 | &exception); |
| 2686 | } while (exception.retry); |
| 2687 | return err; |
| 2688 | } |
| 2689 | |
| 2690 | /* |
| 2691 | * The file is not closed if it is opened due to the a request to change |
| 2692 | * the size of the file. The open call will not be needed once the |
| 2693 | * VFS layer lookup-intents are implemented. |
| 2694 | * |
| 2695 | * Close is called when the inode is destroyed. |
| 2696 | * If we haven't opened the file for O_WRONLY, we |
| 2697 | * need to in the size_change case to obtain a stateid. |
| 2698 | * |
| 2699 | * Got race? |
| 2700 | * Because OPEN is always done by name in nfsv4, it is |
| 2701 | * possible that we opened a different file by the same |
| 2702 | * name. We can recognize this race condition, but we |
| 2703 | * can't do anything about it besides returning an error. |
| 2704 | * |
| 2705 | * This will be fixed with VFS changes (lookup-intent). |
| 2706 | */ |
| 2707 | static int |
| 2708 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2709 | struct iattr *sattr) |
| 2710 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2711 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2712 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2713 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | int status; |
| 2715 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2716 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2717 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2718 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2719 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2721 | /* Deal with open(O_TRUNC) */ |
| 2722 | if (sattr->ia_valid & ATTR_OPEN) |
| 2723 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2724 | |
| 2725 | /* Optimization: if the end result is no change, don't RPC */ |
| 2726 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2727 | return 0; |
| 2728 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2729 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2730 | if (sattr->ia_valid & ATTR_FILE) { |
| 2731 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2732 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2733 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2734 | if (ctx) { |
| 2735 | cred = ctx->cred; |
| 2736 | state = ctx->state; |
| 2737 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2741 | if (status == 0) |
| 2742 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | return status; |
| 2744 | } |
| 2745 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2746 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2747 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2748 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2749 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2750 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2751 | int status; |
| 2752 | struct nfs4_lookup_arg args = { |
| 2753 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2754 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2755 | .name = name, |
| 2756 | }; |
| 2757 | struct nfs4_lookup_res res = { |
| 2758 | .server = server, |
| 2759 | .fattr = fattr, |
| 2760 | .fh = fhandle, |
| 2761 | }; |
| 2762 | struct rpc_message msg = { |
| 2763 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2764 | .rpc_argp = &args, |
| 2765 | .rpc_resp = &res, |
| 2766 | }; |
| 2767 | |
| 2768 | nfs_fattr_init(fattr); |
| 2769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2771 | 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] | 2772 | dprintk("NFS reply lookup: %d\n", status); |
| 2773 | return status; |
| 2774 | } |
| 2775 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2776 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2777 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2778 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2779 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2780 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2781 | fattr->nlink = 2; |
| 2782 | } |
| 2783 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2784 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2785 | struct qstr *name, struct nfs_fh *fhandle, |
| 2786 | struct nfs_fattr *fattr) |
| 2787 | { |
| 2788 | struct nfs4_exception exception = { }; |
| 2789 | struct rpc_clnt *client = *clnt; |
| 2790 | int err; |
| 2791 | do { |
| 2792 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2793 | switch (err) { |
| 2794 | case -NFS4ERR_BADNAME: |
| 2795 | err = -ENOENT; |
| 2796 | goto out; |
| 2797 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2798 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2799 | goto out; |
| 2800 | case -NFS4ERR_WRONGSEC: |
| 2801 | err = -EPERM; |
| 2802 | if (client != *clnt) |
| 2803 | goto out; |
| 2804 | |
| 2805 | client = nfs4_create_sec_client(client, dir, name); |
| 2806 | if (IS_ERR(client)) |
| 2807 | return PTR_ERR(client); |
| 2808 | |
| 2809 | exception.retry = 1; |
| 2810 | break; |
| 2811 | default: |
| 2812 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2813 | } |
| 2814 | } while (exception.retry); |
| 2815 | |
| 2816 | out: |
| 2817 | if (err == 0) |
| 2818 | *clnt = client; |
| 2819 | else if (client != *clnt) |
| 2820 | rpc_shutdown_client(client); |
| 2821 | |
| 2822 | return err; |
| 2823 | } |
| 2824 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2825 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2826 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2828 | int status; |
| 2829 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2830 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2831 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2832 | if (client != NFS_CLIENT(dir)) { |
| 2833 | rpc_shutdown_client(client); |
| 2834 | nfs_fixup_secinfo_attributes(fattr); |
| 2835 | } |
| 2836 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2839 | struct rpc_clnt * |
| 2840 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2841 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2842 | { |
| 2843 | int status; |
| 2844 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2845 | |
| 2846 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2847 | if (status < 0) { |
| 2848 | rpc_shutdown_client(client); |
| 2849 | return ERR_PTR(status); |
| 2850 | } |
| 2851 | return client; |
| 2852 | } |
| 2853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2855 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2856 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | struct nfs4_accessargs args = { |
| 2858 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2859 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2861 | struct nfs4_accessres res = { |
| 2862 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2863 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | struct rpc_message msg = { |
| 2865 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2866 | .rpc_argp = &args, |
| 2867 | .rpc_resp = &res, |
| 2868 | .rpc_cred = entry->cred, |
| 2869 | }; |
| 2870 | int mode = entry->mask; |
| 2871 | int status; |
| 2872 | |
| 2873 | /* |
| 2874 | * Determine which access bits we want to ask for... |
| 2875 | */ |
| 2876 | if (mode & MAY_READ) |
| 2877 | args.access |= NFS4_ACCESS_READ; |
| 2878 | if (S_ISDIR(inode->i_mode)) { |
| 2879 | if (mode & MAY_WRITE) |
| 2880 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2881 | if (mode & MAY_EXEC) |
| 2882 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2883 | } else { |
| 2884 | if (mode & MAY_WRITE) |
| 2885 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2886 | if (mode & MAY_EXEC) |
| 2887 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2888 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2889 | |
| 2890 | res.fattr = nfs_alloc_fattr(); |
| 2891 | if (res.fattr == NULL) |
| 2892 | return -ENOMEM; |
| 2893 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2894 | 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] | 2895 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2896 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2897 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2899 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | return status; |
| 2901 | } |
| 2902 | |
| 2903 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2904 | { |
| 2905 | struct nfs4_exception exception = { }; |
| 2906 | int err; |
| 2907 | do { |
| 2908 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2909 | _nfs4_proc_access(inode, entry), |
| 2910 | &exception); |
| 2911 | } while (exception.retry); |
| 2912 | return err; |
| 2913 | } |
| 2914 | |
| 2915 | /* |
| 2916 | * TODO: For the time being, we don't try to get any attributes |
| 2917 | * along with any of the zero-copy operations READ, READDIR, |
| 2918 | * READLINK, WRITE. |
| 2919 | * |
| 2920 | * In the case of the first three, we want to put the GETATTR |
| 2921 | * after the read-type operation -- this is because it is hard |
| 2922 | * to predict the length of a GETATTR response in v4, and thus |
| 2923 | * align the READ data correctly. This means that the GETATTR |
| 2924 | * may end up partially falling into the page cache, and we should |
| 2925 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2926 | * To do this efficiently, we need to know the total length |
| 2927 | * of data received, which doesn't seem to be available outside |
| 2928 | * of the RPC layer. |
| 2929 | * |
| 2930 | * In the case of WRITE, we also want to put the GETATTR after |
| 2931 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2932 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | * |
| 2934 | * Both of these changes to the XDR layer would in fact be quite |
| 2935 | * minor, but I decided to leave them for a subsequent patch. |
| 2936 | */ |
| 2937 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2938 | unsigned int pgbase, unsigned int pglen) |
| 2939 | { |
| 2940 | struct nfs4_readlink args = { |
| 2941 | .fh = NFS_FH(inode), |
| 2942 | .pgbase = pgbase, |
| 2943 | .pglen = pglen, |
| 2944 | .pages = &page, |
| 2945 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2946 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | struct rpc_message msg = { |
| 2948 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2949 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2950 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | }; |
| 2952 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2953 | 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] | 2954 | } |
| 2955 | |
| 2956 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2957 | unsigned int pgbase, unsigned int pglen) |
| 2958 | { |
| 2959 | struct nfs4_exception exception = { }; |
| 2960 | int err; |
| 2961 | do { |
| 2962 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2963 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2964 | &exception); |
| 2965 | } while (exception.retry); |
| 2966 | return err; |
| 2967 | } |
| 2968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2970 | * 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] | 2971 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | static int |
| 2973 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2974 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2976 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | int status = 0; |
| 2979 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2980 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2981 | if (IS_ERR(ctx)) |
| 2982 | return PTR_ERR(ctx); |
| 2983 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2984 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2985 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2986 | flags, sattr, ctx->cred, |
| 2987 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2988 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | if (IS_ERR(state)) { |
| 2990 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2991 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2993 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2994 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2995 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2997 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | return status; |
| 2999 | } |
| 3000 | |
| 3001 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3002 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3003 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3004 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3006 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3008 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3009 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3010 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3012 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3013 | .rpc_argp = &args, |
| 3014 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3016 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3017 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3018 | 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] | 3019 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3020 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | return status; |
| 3022 | } |
| 3023 | |
| 3024 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3025 | { |
| 3026 | struct nfs4_exception exception = { }; |
| 3027 | int err; |
| 3028 | do { |
| 3029 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3030 | _nfs4_proc_remove(dir, name), |
| 3031 | &exception); |
| 3032 | } while (exception.retry); |
| 3033 | return err; |
| 3034 | } |
| 3035 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3036 | 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] | 3037 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3038 | struct nfs_server *server = NFS_SERVER(dir); |
| 3039 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3040 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3042 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3044 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3047 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3048 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3049 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3050 | &data->args.seq_args, |
| 3051 | &data->res.seq_res, |
| 3052 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3055 | 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] | 3056 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3057 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3058 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3059 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3060 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3061 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3062 | return 0; |
| 3063 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3064 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3067 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3068 | { |
| 3069 | struct nfs_server *server = NFS_SERVER(dir); |
| 3070 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3071 | struct nfs_renameres *res = msg->rpc_resp; |
| 3072 | |
| 3073 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3074 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3075 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3076 | } |
| 3077 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3078 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3079 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3080 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3081 | &data->args.seq_args, |
| 3082 | &data->res.seq_res, |
| 3083 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3087 | struct inode *new_dir) |
| 3088 | { |
| 3089 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3090 | |
| 3091 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3092 | return 0; |
| 3093 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3094 | return 0; |
| 3095 | |
| 3096 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3097 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3098 | return 1; |
| 3099 | } |
| 3100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3102 | struct inode *new_dir, struct qstr *new_name) |
| 3103 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3104 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3105 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | .old_dir = NFS_FH(old_dir), |
| 3107 | .new_dir = NFS_FH(new_dir), |
| 3108 | .old_name = old_name, |
| 3109 | .new_name = new_name, |
| 3110 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3111 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3112 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3113 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | struct rpc_message msg = { |
| 3115 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3116 | .rpc_argp = &arg, |
| 3117 | .rpc_resp = &res, |
| 3118 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3119 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3121 | 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] | 3122 | if (!status) { |
| 3123 | update_changeattr(old_dir, &res.old_cinfo); |
| 3124 | update_changeattr(new_dir, &res.new_cinfo); |
| 3125 | } |
| 3126 | return status; |
| 3127 | } |
| 3128 | |
| 3129 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3130 | struct inode *new_dir, struct qstr *new_name) |
| 3131 | { |
| 3132 | struct nfs4_exception exception = { }; |
| 3133 | int err; |
| 3134 | do { |
| 3135 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3136 | _nfs4_proc_rename(old_dir, old_name, |
| 3137 | new_dir, new_name), |
| 3138 | &exception); |
| 3139 | } while (exception.retry); |
| 3140 | return err; |
| 3141 | } |
| 3142 | |
| 3143 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3144 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3145 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | struct nfs4_link_arg arg = { |
| 3147 | .fh = NFS_FH(inode), |
| 3148 | .dir_fh = NFS_FH(dir), |
| 3149 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3150 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3152 | struct nfs4_link_res res = { |
| 3153 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3154 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | struct rpc_message msg = { |
| 3156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3157 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3158 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3160 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3162 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3163 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3164 | goto out; |
| 3165 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3166 | 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] | 3167 | if (!status) { |
| 3168 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3169 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3170 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3171 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3172 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | return status; |
| 3174 | } |
| 3175 | |
| 3176 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3177 | { |
| 3178 | struct nfs4_exception exception = { }; |
| 3179 | int err; |
| 3180 | do { |
| 3181 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3182 | _nfs4_proc_link(inode, dir, name), |
| 3183 | &exception); |
| 3184 | } while (exception.retry); |
| 3185 | return err; |
| 3186 | } |
| 3187 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3188 | struct nfs4_createdata { |
| 3189 | struct rpc_message msg; |
| 3190 | struct nfs4_create_arg arg; |
| 3191 | struct nfs4_create_res res; |
| 3192 | struct nfs_fh fh; |
| 3193 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3194 | }; |
| 3195 | |
| 3196 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3197 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3198 | { |
| 3199 | struct nfs4_createdata *data; |
| 3200 | |
| 3201 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3202 | if (data != NULL) { |
| 3203 | struct nfs_server *server = NFS_SERVER(dir); |
| 3204 | |
| 3205 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3206 | data->msg.rpc_argp = &data->arg; |
| 3207 | data->msg.rpc_resp = &data->res; |
| 3208 | data->arg.dir_fh = NFS_FH(dir); |
| 3209 | data->arg.server = server; |
| 3210 | data->arg.name = name; |
| 3211 | data->arg.attrs = sattr; |
| 3212 | data->arg.ftype = ftype; |
| 3213 | data->arg.bitmask = server->attr_bitmask; |
| 3214 | data->res.server = server; |
| 3215 | data->res.fh = &data->fh; |
| 3216 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3217 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3218 | } |
| 3219 | return data; |
| 3220 | } |
| 3221 | |
| 3222 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3223 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3224 | 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] | 3225 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3226 | if (status == 0) { |
| 3227 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3228 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3229 | } |
| 3230 | return status; |
| 3231 | } |
| 3232 | |
| 3233 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3234 | { |
| 3235 | kfree(data); |
| 3236 | } |
| 3237 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3238 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3239 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3241 | struct nfs4_createdata *data; |
| 3242 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3244 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3245 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3246 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3247 | status = -ENOMEM; |
| 3248 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3249 | if (data == NULL) |
| 3250 | goto out; |
| 3251 | |
| 3252 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3253 | data->arg.u.symlink.pages = &page; |
| 3254 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3256 | status = nfs4_do_create(dir, dentry, data); |
| 3257 | |
| 3258 | nfs4_free_createdata(data); |
| 3259 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return status; |
| 3261 | } |
| 3262 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3263 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3264 | struct page *page, unsigned int len, struct iattr *sattr) |
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(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3270 | _nfs4_proc_symlink(dir, dentry, page, |
| 3271 | len, sattr), |
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_mkdir(struct inode *dir, struct dentry *dentry, |
| 3278 | struct iattr *sattr) |
| 3279 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3280 | struct nfs4_createdata *data; |
| 3281 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3283 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3284 | if (data == NULL) |
| 3285 | goto out; |
| 3286 | |
| 3287 | status = nfs4_do_create(dir, dentry, data); |
| 3288 | |
| 3289 | nfs4_free_createdata(data); |
| 3290 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | return status; |
| 3292 | } |
| 3293 | |
| 3294 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3295 | struct iattr *sattr) |
| 3296 | { |
| 3297 | struct nfs4_exception exception = { }; |
| 3298 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3299 | |
| 3300 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | do { |
| 3302 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3303 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3304 | &exception); |
| 3305 | } while (exception.retry); |
| 3306 | return err; |
| 3307 | } |
| 3308 | |
| 3309 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3310 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | { |
| 3312 | struct inode *dir = dentry->d_inode; |
| 3313 | struct nfs4_readdir_arg args = { |
| 3314 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3315 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | .pgbase = 0, |
| 3317 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3318 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3319 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | }; |
| 3321 | struct nfs4_readdir_res res; |
| 3322 | struct rpc_message msg = { |
| 3323 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3324 | .rpc_argp = &args, |
| 3325 | .rpc_resp = &res, |
| 3326 | .rpc_cred = cred, |
| 3327 | }; |
| 3328 | int status; |
| 3329 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3330 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3331 | dentry->d_parent->d_name.name, |
| 3332 | dentry->d_name.name, |
| 3333 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3334 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3336 | 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] | 3337 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3338 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3339 | status += args.pgbase; |
| 3340 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3341 | |
| 3342 | nfs_invalidate_atime(dir); |
| 3343 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3344 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | return status; |
| 3346 | } |
| 3347 | |
| 3348 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3349 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | { |
| 3351 | struct nfs4_exception exception = { }; |
| 3352 | int err; |
| 3353 | do { |
| 3354 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3355 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3356 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | &exception); |
| 3358 | } while (exception.retry); |
| 3359 | return err; |
| 3360 | } |
| 3361 | |
| 3362 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3363 | struct iattr *sattr, dev_t rdev) |
| 3364 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3365 | struct nfs4_createdata *data; |
| 3366 | int mode = sattr->ia_mode; |
| 3367 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3369 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3370 | if (data == NULL) |
| 3371 | goto out; |
| 3372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3374 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3376 | data->arg.ftype = NF4BLK; |
| 3377 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3378 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | } |
| 3380 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3381 | data->arg.ftype = NF4CHR; |
| 3382 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3383 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3384 | } else if (!S_ISSOCK(mode)) { |
| 3385 | status = -EINVAL; |
| 3386 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3389 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3390 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3391 | nfs4_free_createdata(data); |
| 3392 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | return status; |
| 3394 | } |
| 3395 | |
| 3396 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3397 | struct iattr *sattr, dev_t rdev) |
| 3398 | { |
| 3399 | struct nfs4_exception exception = { }; |
| 3400 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3401 | |
| 3402 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | do { |
| 3404 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3405 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3406 | &exception); |
| 3407 | } while (exception.retry); |
| 3408 | return err; |
| 3409 | } |
| 3410 | |
| 3411 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3412 | struct nfs_fsstat *fsstat) |
| 3413 | { |
| 3414 | struct nfs4_statfs_arg args = { |
| 3415 | .fh = fhandle, |
| 3416 | .bitmask = server->attr_bitmask, |
| 3417 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3418 | struct nfs4_statfs_res res = { |
| 3419 | .fsstat = fsstat, |
| 3420 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | struct rpc_message msg = { |
| 3422 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3423 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3424 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | }; |
| 3426 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3427 | nfs_fattr_init(fsstat->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_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3432 | { |
| 3433 | struct nfs4_exception exception = { }; |
| 3434 | int err; |
| 3435 | do { |
| 3436 | err = nfs4_handle_exception(server, |
| 3437 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3438 | &exception); |
| 3439 | } while (exception.retry); |
| 3440 | return err; |
| 3441 | } |
| 3442 | |
| 3443 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3444 | struct nfs_fsinfo *fsinfo) |
| 3445 | { |
| 3446 | struct nfs4_fsinfo_arg args = { |
| 3447 | .fh = fhandle, |
| 3448 | .bitmask = server->attr_bitmask, |
| 3449 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3450 | struct nfs4_fsinfo_res res = { |
| 3451 | .fsinfo = fsinfo, |
| 3452 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | struct rpc_message msg = { |
| 3454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3455 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3456 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | }; |
| 3458 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3459 | 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] | 3460 | } |
| 3461 | |
| 3462 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3463 | { |
| 3464 | struct nfs4_exception exception = { }; |
| 3465 | int err; |
| 3466 | |
| 3467 | do { |
| 3468 | err = nfs4_handle_exception(server, |
| 3469 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3470 | &exception); |
| 3471 | } while (exception.retry); |
| 3472 | return err; |
| 3473 | } |
| 3474 | |
| 3475 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3476 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3477 | int error; |
| 3478 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3479 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3480 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3481 | if (error == 0) { |
| 3482 | /* block layout checks this! */ |
| 3483 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3484 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3485 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3486 | |
| 3487 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3491 | struct nfs_pathconf *pathconf) |
| 3492 | { |
| 3493 | struct nfs4_pathconf_arg args = { |
| 3494 | .fh = fhandle, |
| 3495 | .bitmask = server->attr_bitmask, |
| 3496 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3497 | struct nfs4_pathconf_res res = { |
| 3498 | .pathconf = pathconf, |
| 3499 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | struct rpc_message msg = { |
| 3501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3502 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3503 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | }; |
| 3505 | |
| 3506 | /* None of the pathconf attributes are mandatory to implement */ |
| 3507 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3508 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3509 | return 0; |
| 3510 | } |
| 3511 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3512 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3513 | 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] | 3514 | } |
| 3515 | |
| 3516 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3517 | struct nfs_pathconf *pathconf) |
| 3518 | { |
| 3519 | struct nfs4_exception exception = { }; |
| 3520 | int err; |
| 3521 | |
| 3522 | do { |
| 3523 | err = nfs4_handle_exception(server, |
| 3524 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3525 | &exception); |
| 3526 | } while (exception.retry); |
| 3527 | return err; |
| 3528 | } |
| 3529 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3530 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3531 | const struct nfs_open_context *ctx, |
| 3532 | const struct nfs_lock_context *l_ctx, |
| 3533 | fmode_t fmode) |
| 3534 | { |
| 3535 | const struct nfs_lockowner *lockowner = NULL; |
| 3536 | |
| 3537 | if (l_ctx != NULL) |
| 3538 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3539 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3540 | } |
| 3541 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3542 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3543 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3544 | const struct nfs_open_context *ctx, |
| 3545 | const struct nfs_lock_context *l_ctx, |
| 3546 | fmode_t fmode) |
| 3547 | { |
| 3548 | nfs4_stateid current_stateid; |
| 3549 | |
| 3550 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3551 | return false; |
| 3552 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3553 | } |
| 3554 | |
| 3555 | static bool nfs4_error_stateid_expired(int err) |
| 3556 | { |
| 3557 | switch (err) { |
| 3558 | case -NFS4ERR_DELEG_REVOKED: |
| 3559 | case -NFS4ERR_ADMIN_REVOKED: |
| 3560 | case -NFS4ERR_BAD_STATEID: |
| 3561 | case -NFS4ERR_STALE_STATEID: |
| 3562 | case -NFS4ERR_OLD_STATEID: |
| 3563 | case -NFS4ERR_OPENMODE: |
| 3564 | case -NFS4ERR_EXPIRED: |
| 3565 | return true; |
| 3566 | } |
| 3567 | return false; |
| 3568 | } |
| 3569 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3570 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3571 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3572 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3573 | } |
| 3574 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3575 | 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] | 3576 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3577 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3579 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3580 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3581 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3583 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3584 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3586 | renew_lease(server, data->timestamp); |
| 3587 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | } |
| 3589 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3590 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3591 | struct nfs_readargs *args) |
| 3592 | { |
| 3593 | |
| 3594 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3595 | nfs4_stateid_is_current(&args->stateid, |
| 3596 | args->context, |
| 3597 | args->lock_context, |
| 3598 | FMODE_READ)) |
| 3599 | return false; |
| 3600 | rpc_restart_call_prepare(task); |
| 3601 | return true; |
| 3602 | } |
| 3603 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3604 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3605 | { |
| 3606 | |
| 3607 | dprintk("--> %s\n", __func__); |
| 3608 | |
| 3609 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3610 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3611 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3612 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3613 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3614 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3617 | 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] | 3618 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3620 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3621 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3622 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3625 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3626 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3627 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3628 | &data->args.seq_args, |
| 3629 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3630 | task)) |
| 3631 | return; |
| 3632 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3633 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3636 | 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] | 3637 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3638 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3640 | 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] | 3641 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3642 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3644 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3646 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3647 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3648 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3651 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3652 | struct nfs_writeargs *args) |
| 3653 | { |
| 3654 | |
| 3655 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3656 | nfs4_stateid_is_current(&args->stateid, |
| 3657 | args->context, |
| 3658 | args->lock_context, |
| 3659 | FMODE_WRITE)) |
| 3660 | return false; |
| 3661 | rpc_restart_call_prepare(task); |
| 3662 | return true; |
| 3663 | } |
| 3664 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3665 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3666 | { |
| 3667 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3668 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3669 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3670 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3671 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3672 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3675 | static |
| 3676 | 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] | 3677 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3678 | const struct nfs_pgio_header *hdr = data->header; |
| 3679 | |
| 3680 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3681 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3682 | return false; |
| 3683 | /* Otherwise, request attributes if and only if we don't hold |
| 3684 | * a delegation |
| 3685 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3686 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3687 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3688 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3689 | 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] | 3690 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3691 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3692 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3693 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3694 | data->args.bitmask = NULL; |
| 3695 | data->res.fattr = NULL; |
| 3696 | } else |
| 3697 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3698 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3699 | if (!data->write_done_cb) |
| 3700 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3701 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | data->timestamp = jiffies; |
| 3703 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3704 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3705 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | } |
| 3707 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3708 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3709 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3710 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3711 | &data->args.seq_args, |
| 3712 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3713 | task)) |
| 3714 | return; |
| 3715 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3716 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | } |
| 3718 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3719 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3720 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3721 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3722 | &data->args.seq_args, |
| 3723 | &data->res.seq_res, |
| 3724 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | } |
| 3726 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3727 | 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] | 3728 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3730 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3731 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3732 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3733 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3735 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | } |
| 3737 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3738 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data) |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3739 | { |
| 3740 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3741 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3742 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3745 | 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] | 3746 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3747 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3748 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3749 | if (data->commit_done_cb == NULL) |
| 3750 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3751 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3752 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3753 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3756 | struct nfs4_renewdata { |
| 3757 | struct nfs_client *client; |
| 3758 | unsigned long timestamp; |
| 3759 | }; |
| 3760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | /* |
| 3762 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3763 | * standalone procedure for queueing an asynchronous RENEW. |
| 3764 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3765 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3766 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3767 | struct nfs4_renewdata *data = calldata; |
| 3768 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3769 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3770 | if (atomic_read(&clp->cl_count) > 1) |
| 3771 | nfs4_schedule_state_renewal(clp); |
| 3772 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3773 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3774 | } |
| 3775 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3776 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3778 | struct nfs4_renewdata *data = calldata; |
| 3779 | struct nfs_client *clp = data->client; |
| 3780 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | |
| 3782 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3783 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3784 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3785 | return; |
| 3786 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3787 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3788 | return; |
| 3789 | } |
| 3790 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3792 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | } |
| 3794 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3795 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3796 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3797 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3798 | }; |
| 3799 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3800 | 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] | 3801 | { |
| 3802 | struct rpc_message msg = { |
| 3803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3804 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3805 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3807 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3809 | if (renew_flags == 0) |
| 3810 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3811 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3812 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3813 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3814 | if (data == NULL) |
| 3815 | return -ENOMEM; |
| 3816 | data->client = clp; |
| 3817 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 3818 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3819 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3822 | 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] | 3823 | { |
| 3824 | struct rpc_message msg = { |
| 3825 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3826 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3827 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | }; |
| 3829 | unsigned long now = jiffies; |
| 3830 | int status; |
| 3831 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 3832 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | if (status < 0) |
| 3834 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3835 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | return 0; |
| 3837 | } |
| 3838 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3839 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3840 | { |
| 3841 | return (server->caps & NFS_CAP_ACLS) |
| 3842 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3843 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3844 | } |
| 3845 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3846 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3847 | * 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] | 3848 | * the stack. |
| 3849 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3850 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3851 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3852 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3853 | struct page **pages, unsigned int *pgbase) |
| 3854 | { |
| 3855 | struct page *newpage, **spages; |
| 3856 | int rc = 0; |
| 3857 | size_t len; |
| 3858 | spages = pages; |
| 3859 | |
| 3860 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3861 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3862 | newpage = alloc_page(GFP_KERNEL); |
| 3863 | |
| 3864 | if (newpage == NULL) |
| 3865 | goto unwind; |
| 3866 | memcpy(page_address(newpage), buf, len); |
| 3867 | buf += len; |
| 3868 | buflen -= len; |
| 3869 | *pages++ = newpage; |
| 3870 | rc++; |
| 3871 | } while (buflen != 0); |
| 3872 | |
| 3873 | return rc; |
| 3874 | |
| 3875 | unwind: |
| 3876 | for(; rc > 0; rc--) |
| 3877 | __free_page(spages[rc-1]); |
| 3878 | return -ENOMEM; |
| 3879 | } |
| 3880 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3881 | struct nfs4_cached_acl { |
| 3882 | int cached; |
| 3883 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3884 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3885 | }; |
| 3886 | |
| 3887 | 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] | 3888 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3889 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3890 | |
| 3891 | spin_lock(&inode->i_lock); |
| 3892 | kfree(nfsi->nfs4_acl); |
| 3893 | nfsi->nfs4_acl = acl; |
| 3894 | spin_unlock(&inode->i_lock); |
| 3895 | } |
| 3896 | |
| 3897 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3898 | { |
| 3899 | nfs4_set_cached_acl(inode, NULL); |
| 3900 | } |
| 3901 | |
| 3902 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3903 | { |
| 3904 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3905 | struct nfs4_cached_acl *acl; |
| 3906 | int ret = -ENOENT; |
| 3907 | |
| 3908 | spin_lock(&inode->i_lock); |
| 3909 | acl = nfsi->nfs4_acl; |
| 3910 | if (acl == NULL) |
| 3911 | goto out; |
| 3912 | if (buf == NULL) /* user is just asking for length */ |
| 3913 | goto out_len; |
| 3914 | if (acl->cached == 0) |
| 3915 | goto out; |
| 3916 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3917 | if (acl->len > buflen) |
| 3918 | goto out; |
| 3919 | memcpy(buf, acl->data, acl->len); |
| 3920 | out_len: |
| 3921 | ret = acl->len; |
| 3922 | out: |
| 3923 | spin_unlock(&inode->i_lock); |
| 3924 | return ret; |
| 3925 | } |
| 3926 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3927 | 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] | 3928 | { |
| 3929 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3930 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3931 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3932 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3933 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3934 | if (acl == NULL) |
| 3935 | goto out; |
| 3936 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3937 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3938 | } else { |
| 3939 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3940 | if (acl == NULL) |
| 3941 | goto out; |
| 3942 | acl->cached = 0; |
| 3943 | } |
| 3944 | acl->len = acl_len; |
| 3945 | out: |
| 3946 | nfs4_set_cached_acl(inode, acl); |
| 3947 | } |
| 3948 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3949 | /* |
| 3950 | * The getxattr API returns the required buffer length when called with a |
| 3951 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3952 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3953 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3954 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3955 | * the cache. If not so, we throw away the page, and cache the required |
| 3956 | * length. The next getxattr call will then produce another round trip to |
| 3957 | * the server, this time with the input buf of the required size. |
| 3958 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3959 | 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] | 3960 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3961 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3962 | struct nfs_getaclargs args = { |
| 3963 | .fh = NFS_FH(inode), |
| 3964 | .acl_pages = pages, |
| 3965 | .acl_len = buflen, |
| 3966 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3967 | struct nfs_getaclres res = { |
| 3968 | .acl_len = buflen, |
| 3969 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3970 | struct rpc_message msg = { |
| 3971 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3972 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3973 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3974 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3975 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3976 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3977 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3978 | /* As long as we're doing a round trip to the server anyway, |
| 3979 | * let's be prepared for a page of acl data. */ |
| 3980 | if (npages == 0) |
| 3981 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3982 | if (npages > ARRAY_SIZE(pages)) |
| 3983 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3984 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3985 | for (i = 0; i < npages; i++) { |
| 3986 | pages[i] = alloc_page(GFP_KERNEL); |
| 3987 | if (!pages[i]) |
| 3988 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3989 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3990 | |
| 3991 | /* for decoding across pages */ |
| 3992 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3993 | if (!res.acl_scratch) |
| 3994 | goto out_free; |
| 3995 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3996 | args.acl_len = npages * PAGE_SIZE; |
| 3997 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3998 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3999 | 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] | 4000 | __func__, buf, buflen, npages, args.acl_len); |
| 4001 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4002 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4003 | if (ret) |
| 4004 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4005 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4006 | /* Handle the case where the passed-in buffer is too short */ |
| 4007 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4008 | /* Did the user only issue a request for the acl length? */ |
| 4009 | if (buf == NULL) |
| 4010 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4011 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4012 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4013 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4014 | 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] | 4015 | if (buf) { |
| 4016 | if (res.acl_len > buflen) { |
| 4017 | ret = -ERANGE; |
| 4018 | goto out_free; |
| 4019 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4020 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4021 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4022 | out_ok: |
| 4023 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4024 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4025 | for (i = 0; i < npages; i++) |
| 4026 | if (pages[i]) |
| 4027 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4028 | if (res.acl_scratch) |
| 4029 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4030 | return ret; |
| 4031 | } |
| 4032 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4033 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4034 | { |
| 4035 | struct nfs4_exception exception = { }; |
| 4036 | ssize_t ret; |
| 4037 | do { |
| 4038 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 4039 | if (ret >= 0) |
| 4040 | break; |
| 4041 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4042 | } while (exception.retry); |
| 4043 | return ret; |
| 4044 | } |
| 4045 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4046 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4047 | { |
| 4048 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4049 | int ret; |
| 4050 | |
| 4051 | if (!nfs4_server_supports_acls(server)) |
| 4052 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4053 | ret = nfs_revalidate_inode(server, inode); |
| 4054 | if (ret < 0) |
| 4055 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4056 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4057 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4058 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4059 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4060 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4061 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4062 | return ret; |
| 4063 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4066 | 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] | 4067 | { |
| 4068 | struct nfs_server *server = NFS_SERVER(inode); |
| 4069 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4070 | struct nfs_setaclargs arg = { |
| 4071 | .fh = NFS_FH(inode), |
| 4072 | .acl_pages = pages, |
| 4073 | .acl_len = buflen, |
| 4074 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4075 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4076 | struct rpc_message msg = { |
| 4077 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4078 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4079 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4080 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4081 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4082 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4083 | |
| 4084 | if (!nfs4_server_supports_acls(server)) |
| 4085 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4086 | if (npages > ARRAY_SIZE(pages)) |
| 4087 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4088 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4089 | if (i < 0) |
| 4090 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4091 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4092 | 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] | 4093 | |
| 4094 | /* |
| 4095 | * Free each page after tx, so the only ref left is |
| 4096 | * held by the network stack |
| 4097 | */ |
| 4098 | for (; i > 0; i--) |
| 4099 | put_page(pages[i-1]); |
| 4100 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4101 | /* |
| 4102 | * Acl update can result in inode attribute update. |
| 4103 | * so mark the attribute cache invalid. |
| 4104 | */ |
| 4105 | spin_lock(&inode->i_lock); |
| 4106 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4107 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4108 | nfs_access_zap_cache(inode); |
| 4109 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4110 | return ret; |
| 4111 | } |
| 4112 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4113 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4114 | { |
| 4115 | struct nfs4_exception exception = { }; |
| 4116 | int err; |
| 4117 | do { |
| 4118 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4119 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4120 | &exception); |
| 4121 | } while (exception.retry); |
| 4122 | return err; |
| 4123 | } |
| 4124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4126 | 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] | 4127 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4128 | struct nfs_client *clp = server->nfs_client; |
| 4129 | |
| 4130 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | return 0; |
| 4132 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4133 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4134 | case -NFS4ERR_ADMIN_REVOKED: |
| 4135 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4136 | if (state == NULL) |
| 4137 | break; |
| 4138 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4139 | case -NFS4ERR_OPENMODE: |
| 4140 | if (state == NULL) |
| 4141 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4142 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4143 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4144 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4145 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4146 | if (state != NULL) { |
| 4147 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4148 | goto stateid_invalid; |
| 4149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4151 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4152 | nfs4_schedule_lease_recovery(clp); |
| 4153 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4154 | #if defined(CONFIG_NFS_V4_1) |
| 4155 | case -NFS4ERR_BADSESSION: |
| 4156 | case -NFS4ERR_BADSLOT: |
| 4157 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4158 | case -NFS4ERR_DEADSESSION: |
| 4159 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4160 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4161 | case -NFS4ERR_SEQ_MISORDERED: |
| 4162 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4163 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4164 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4165 | task->tk_status = 0; |
| 4166 | return -EAGAIN; |
| 4167 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4169 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4170 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4172 | task->tk_status = 0; |
| 4173 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4174 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | case -NFS4ERR_OLD_STATEID: |
| 4176 | task->tk_status = 0; |
| 4177 | return -EAGAIN; |
| 4178 | } |
| 4179 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4180 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4181 | stateid_invalid: |
| 4182 | task->tk_status = -EIO; |
| 4183 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4184 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4185 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4186 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4187 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4188 | task->tk_status = 0; |
| 4189 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | } |
| 4191 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4192 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4193 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4194 | { |
| 4195 | __be32 verf[2]; |
| 4196 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4197 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4198 | /* An impossible timestamp guarantees this value |
| 4199 | * will never match a generated boot time. */ |
| 4200 | verf[0] = 0; |
| 4201 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4202 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4203 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4204 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4205 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4206 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4207 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4208 | } |
| 4209 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4210 | static unsigned int |
| 4211 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4212 | char *buf, size_t len) |
| 4213 | { |
| 4214 | unsigned int result; |
| 4215 | |
| 4216 | rcu_read_lock(); |
| 4217 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4218 | clp->cl_ipaddr, |
| 4219 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4220 | RPC_DISPLAY_ADDR), |
| 4221 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4222 | RPC_DISPLAY_PROTO)); |
| 4223 | rcu_read_unlock(); |
| 4224 | return result; |
| 4225 | } |
| 4226 | |
| 4227 | static unsigned int |
| 4228 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4229 | char *buf, size_t len) |
| 4230 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4231 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4232 | |
| 4233 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4234 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4235 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4236 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4237 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4238 | } |
| 4239 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4240 | /** |
| 4241 | * nfs4_proc_setclientid - Negotiate client ID |
| 4242 | * @clp: state data structure |
| 4243 | * @program: RPC program for NFSv4 callback service |
| 4244 | * @port: IP port number for NFS4 callback service |
| 4245 | * @cred: RPC credential to use for this call |
| 4246 | * @res: where to place the result |
| 4247 | * |
| 4248 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4249 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4250 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4251 | unsigned short port, struct rpc_cred *cred, |
| 4252 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | { |
| 4254 | nfs4_verifier sc_verifier; |
| 4255 | struct nfs4_setclientid setclientid = { |
| 4256 | .sc_verifier = &sc_verifier, |
| 4257 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4258 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | }; |
| 4260 | struct rpc_message msg = { |
| 4261 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4262 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4263 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4264 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4266 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4268 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4269 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4270 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4271 | setclientid.sc_name_len = |
| 4272 | nfs4_init_uniform_client_string(clp, |
| 4273 | setclientid.sc_name, |
| 4274 | sizeof(setclientid.sc_name)); |
| 4275 | else |
| 4276 | setclientid.sc_name_len = |
| 4277 | nfs4_init_nonuniform_client_string(clp, |
| 4278 | setclientid.sc_name, |
| 4279 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4280 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4281 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4282 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4283 | sizeof(setclientid.sc_netid), |
| 4284 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4285 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4286 | rcu_read_unlock(); |
| 4287 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4288 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4290 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4291 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4292 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4293 | setclientid.sc_name_len, setclientid.sc_name); |
| 4294 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4295 | dprintk("NFS reply setclientid: %d\n", status); |
| 4296 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4299 | /** |
| 4300 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4301 | * @clp: state data structure |
| 4302 | * @res: result of a previous SETCLIENTID |
| 4303 | * @cred: RPC credential to use for this call |
| 4304 | * |
| 4305 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4306 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4307 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4308 | struct nfs4_setclientid_res *arg, |
| 4309 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | { |
| 4311 | struct nfs_fsinfo fsinfo; |
| 4312 | struct rpc_message msg = { |
| 4313 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4314 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4316 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | }; |
| 4318 | unsigned long now; |
| 4319 | int status; |
| 4320 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4321 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4322 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4323 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4325 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | if (status == 0) { |
| 4327 | spin_lock(&clp->cl_lock); |
| 4328 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4329 | clp->cl_last_renewal = now; |
| 4330 | spin_unlock(&clp->cl_lock); |
| 4331 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4332 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | return status; |
| 4334 | } |
| 4335 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4336 | struct nfs4_delegreturndata { |
| 4337 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4338 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4339 | struct nfs_fh fh; |
| 4340 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4341 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4342 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4343 | int rpc_status; |
| 4344 | }; |
| 4345 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4346 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4347 | { |
| 4348 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4349 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4350 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4351 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4352 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4353 | switch (task->tk_status) { |
| 4354 | case -NFS4ERR_STALE_STATEID: |
| 4355 | case -NFS4ERR_EXPIRED: |
| 4356 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4357 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4358 | break; |
| 4359 | default: |
| 4360 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4361 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4362 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4363 | return; |
| 4364 | } |
| 4365 | } |
| 4366 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | static void nfs4_delegreturn_release(void *calldata) |
| 4370 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4371 | kfree(calldata); |
| 4372 | } |
| 4373 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4374 | #if defined(CONFIG_NFS_V4_1) |
| 4375 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4376 | { |
| 4377 | struct nfs4_delegreturndata *d_data; |
| 4378 | |
| 4379 | d_data = (struct nfs4_delegreturndata *)data; |
| 4380 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4381 | nfs4_setup_sequence(d_data->res.server, |
| 4382 | &d_data->args.seq_args, |
| 4383 | &d_data->res.seq_res, |
| 4384 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4385 | } |
| 4386 | #endif /* CONFIG_NFS_V4_1 */ |
| 4387 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4388 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4389 | #if defined(CONFIG_NFS_V4_1) |
| 4390 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4391 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4392 | .rpc_call_done = nfs4_delegreturn_done, |
| 4393 | .rpc_release = nfs4_delegreturn_release, |
| 4394 | }; |
| 4395 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4396 | 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] | 4397 | { |
| 4398 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4399 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4400 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4401 | struct rpc_message msg = { |
| 4402 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4403 | .rpc_cred = cred, |
| 4404 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4405 | struct rpc_task_setup task_setup_data = { |
| 4406 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4407 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4408 | .callback_ops = &nfs4_delegreturn_ops, |
| 4409 | .flags = RPC_TASK_ASYNC, |
| 4410 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4411 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4412 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4413 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4414 | if (data == NULL) |
| 4415 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4416 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4417 | data->args.fhandle = &data->fh; |
| 4418 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4419 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4420 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4421 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4422 | data->res.fattr = &data->fattr; |
| 4423 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4424 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4425 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4426 | data->rpc_status = 0; |
| 4427 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4428 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4429 | msg.rpc_argp = &data->args; |
| 4430 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4431 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4432 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4433 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4434 | if (!issync) |
| 4435 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4436 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4437 | if (status != 0) |
| 4438 | goto out; |
| 4439 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4440 | if (status == 0) |
| 4441 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4442 | else |
| 4443 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4444 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4445 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4446 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4449 | 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] | 4450 | { |
| 4451 | struct nfs_server *server = NFS_SERVER(inode); |
| 4452 | struct nfs4_exception exception = { }; |
| 4453 | int err; |
| 4454 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4455 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | switch (err) { |
| 4457 | case -NFS4ERR_STALE_STATEID: |
| 4458 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | case 0: |
| 4460 | return 0; |
| 4461 | } |
| 4462 | err = nfs4_handle_exception(server, err, &exception); |
| 4463 | } while (exception.retry); |
| 4464 | return err; |
| 4465 | } |
| 4466 | |
| 4467 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4468 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4469 | |
| 4470 | /* |
| 4471 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4472 | */ |
| 4473 | static unsigned long |
| 4474 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4475 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4476 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | timeout <<= 1; |
| 4478 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4479 | return NFS4_LOCK_MAXTIMEOUT; |
| 4480 | return timeout; |
| 4481 | } |
| 4482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4484 | { |
| 4485 | struct inode *inode = state->inode; |
| 4486 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4487 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4488 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4490 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4492 | struct nfs_lockt_res res = { |
| 4493 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | }; |
| 4495 | struct rpc_message msg = { |
| 4496 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4497 | .rpc_argp = &arg, |
| 4498 | .rpc_resp = &res, |
| 4499 | .rpc_cred = state->owner->so_cred, |
| 4500 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | struct nfs4_lock_state *lsp; |
| 4502 | int status; |
| 4503 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4504 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4505 | status = nfs4_set_lock_state(state, request); |
| 4506 | if (status != 0) |
| 4507 | goto out; |
| 4508 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4509 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4510 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4511 | 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] | 4512 | switch (status) { |
| 4513 | case 0: |
| 4514 | request->fl_type = F_UNLCK; |
| 4515 | break; |
| 4516 | case -NFS4ERR_DENIED: |
| 4517 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4519 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4520 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | return status; |
| 4522 | } |
| 4523 | |
| 4524 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4525 | { |
| 4526 | struct nfs4_exception exception = { }; |
| 4527 | int err; |
| 4528 | |
| 4529 | do { |
| 4530 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4531 | _nfs4_proc_getlk(state, cmd, request), |
| 4532 | &exception); |
| 4533 | } while (exception.retry); |
| 4534 | return err; |
| 4535 | } |
| 4536 | |
| 4537 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4538 | { |
| 4539 | int res = 0; |
| 4540 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4541 | case FL_POSIX: |
| 4542 | res = posix_lock_file_wait(file, fl); |
| 4543 | break; |
| 4544 | case FL_FLOCK: |
| 4545 | res = flock_lock_file_wait(file, fl); |
| 4546 | break; |
| 4547 | default: |
| 4548 | BUG(); |
| 4549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4550 | return res; |
| 4551 | } |
| 4552 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4553 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4554 | struct nfs_locku_args arg; |
| 4555 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4556 | struct nfs4_lock_state *lsp; |
| 4557 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4558 | struct file_lock fl; |
| 4559 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4560 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4561 | }; |
| 4562 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4563 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4564 | struct nfs_open_context *ctx, |
| 4565 | struct nfs4_lock_state *lsp, |
| 4566 | struct nfs_seqid *seqid) |
| 4567 | { |
| 4568 | struct nfs4_unlockdata *p; |
| 4569 | struct inode *inode = lsp->ls_state->inode; |
| 4570 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4571 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4572 | if (p == NULL) |
| 4573 | return NULL; |
| 4574 | p->arg.fh = NFS_FH(inode); |
| 4575 | p->arg.fl = &p->fl; |
| 4576 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4577 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4578 | p->arg.stateid = &lsp->ls_stateid; |
| 4579 | p->lsp = lsp; |
| 4580 | atomic_inc(&lsp->ls_count); |
| 4581 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4582 | p->ctx = get_nfs_open_context(ctx); |
| 4583 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4584 | p->server = NFS_SERVER(inode); |
| 4585 | return p; |
| 4586 | } |
| 4587 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4588 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4589 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4590 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4591 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4592 | nfs4_put_lock_state(calldata->lsp); |
| 4593 | put_nfs_open_context(calldata->ctx); |
| 4594 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4597 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4598 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4599 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4600 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4601 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4602 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4603 | switch (task->tk_status) { |
| 4604 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4605 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4606 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4607 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4608 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4609 | case -NFS4ERR_BAD_STATEID: |
| 4610 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4611 | case -NFS4ERR_STALE_STATEID: |
| 4612 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4613 | break; |
| 4614 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4615 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4616 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4617 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4618 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4619 | } |
| 4620 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4621 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4622 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4623 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4625 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4626 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4627 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4628 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4629 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4630 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4631 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4632 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4633 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4634 | &calldata->res.seq_res, |
| 4635 | task) != 0) |
| 4636 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4637 | return; |
| 4638 | out_no_action: |
| 4639 | task->tk_action = NULL; |
| 4640 | out_wait: |
| 4641 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4644 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4645 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4646 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4647 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4648 | }; |
| 4649 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4650 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4651 | struct nfs_open_context *ctx, |
| 4652 | struct nfs4_lock_state *lsp, |
| 4653 | struct nfs_seqid *seqid) |
| 4654 | { |
| 4655 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4656 | struct rpc_message msg = { |
| 4657 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4658 | .rpc_cred = ctx->cred, |
| 4659 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4660 | struct rpc_task_setup task_setup_data = { |
| 4661 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4662 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4663 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4664 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4665 | .flags = RPC_TASK_ASYNC, |
| 4666 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4667 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4668 | /* Ensure this is an unlock - when canceling a lock, the |
| 4669 | * canceled lock is passed in, and it won't be an unlock. |
| 4670 | */ |
| 4671 | fl->fl_type = F_UNLCK; |
| 4672 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4673 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4674 | if (data == NULL) { |
| 4675 | nfs_free_seqid(seqid); |
| 4676 | return ERR_PTR(-ENOMEM); |
| 4677 | } |
| 4678 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4679 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4680 | msg.rpc_argp = &data->arg; |
| 4681 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4682 | task_setup_data.callback_data = data; |
| 4683 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4684 | } |
| 4685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4686 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4687 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4688 | struct inode *inode = state->inode; |
| 4689 | struct nfs4_state_owner *sp = state->owner; |
| 4690 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4691 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4692 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4693 | struct rpc_task *task; |
| 4694 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4695 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4697 | status = nfs4_set_lock_state(state, request); |
| 4698 | /* Unlock _before_ we do the RPC call */ |
| 4699 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4700 | /* Exclude nfs_delegation_claim_locks() */ |
| 4701 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4702 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4703 | down_read(&nfsi->rwsem); |
| 4704 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4705 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4706 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4707 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4708 | } |
| 4709 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4710 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4711 | if (status != 0) |
| 4712 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4713 | /* Is this a delegated lock? */ |
| 4714 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4715 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4716 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4717 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4718 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4719 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4720 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4721 | 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] | 4722 | status = PTR_ERR(task); |
| 4723 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4724 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4725 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4726 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4727 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4728 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4729 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | } |
| 4731 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4732 | struct nfs4_lockdata { |
| 4733 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4734 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4735 | struct nfs4_lock_state *lsp; |
| 4736 | struct nfs_open_context *ctx; |
| 4737 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4738 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4739 | int rpc_status; |
| 4740 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4741 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4742 | }; |
| 4743 | |
| 4744 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4745 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4746 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4747 | { |
| 4748 | struct nfs4_lockdata *p; |
| 4749 | struct inode *inode = lsp->ls_state->inode; |
| 4750 | struct nfs_server *server = NFS_SERVER(inode); |
| 4751 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4752 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4753 | if (p == NULL) |
| 4754 | return NULL; |
| 4755 | |
| 4756 | p->arg.fh = NFS_FH(inode); |
| 4757 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4758 | 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] | 4759 | if (p->arg.open_seqid == NULL) |
| 4760 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4761 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4762 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4763 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4764 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4765 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4766 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4767 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4768 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4769 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4770 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4771 | atomic_inc(&lsp->ls_count); |
| 4772 | p->ctx = get_nfs_open_context(ctx); |
| 4773 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4774 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4775 | out_free_seqid: |
| 4776 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4777 | out_free: |
| 4778 | kfree(p); |
| 4779 | return NULL; |
| 4780 | } |
| 4781 | |
| 4782 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4783 | { |
| 4784 | struct nfs4_lockdata *data = calldata; |
| 4785 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4787 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4788 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4789 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4790 | /* Do we need to do an open_to_lock_owner? */ |
| 4791 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4792 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4793 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4794 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4795 | data->arg.open_stateid = &state->stateid; |
| 4796 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4797 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4798 | } else |
| 4799 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4800 | if (!nfs4_valid_open_stateid(state)) { |
| 4801 | data->rpc_status = -EBADF; |
| 4802 | task->tk_action = NULL; |
| 4803 | goto out_release_open_seqid; |
| 4804 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4805 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4806 | if (nfs4_setup_sequence(data->server, |
| 4807 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4808 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4809 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4810 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4811 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4812 | nfs_release_seqid(data->arg.open_seqid); |
| 4813 | out_release_lock_seqid: |
| 4814 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4815 | out_wait: |
| 4816 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4817 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4818 | } |
| 4819 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4820 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4821 | { |
| 4822 | struct nfs4_lockdata *data = calldata; |
| 4823 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4824 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4825 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4826 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4827 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4828 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4829 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4830 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4831 | if (data->rpc_status == 0) |
| 4832 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4833 | else |
| 4834 | goto out; |
| 4835 | } |
| 4836 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4837 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4838 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4839 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4840 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4841 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4842 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | static void nfs4_lock_release(void *calldata) |
| 4846 | { |
| 4847 | struct nfs4_lockdata *data = calldata; |
| 4848 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4849 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4850 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4851 | if (data->cancelled != 0) { |
| 4852 | struct rpc_task *task; |
| 4853 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4854 | data->arg.lock_seqid); |
| 4855 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4856 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4857 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4858 | } else |
| 4859 | nfs_free_seqid(data->arg.lock_seqid); |
| 4860 | nfs4_put_lock_state(data->lsp); |
| 4861 | put_nfs_open_context(data->ctx); |
| 4862 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4863 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4867 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4868 | .rpc_call_done = nfs4_lock_done, |
| 4869 | .rpc_release = nfs4_lock_release, |
| 4870 | }; |
| 4871 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4872 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4873 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4874 | switch (error) { |
| 4875 | case -NFS4ERR_ADMIN_REVOKED: |
| 4876 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4877 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4878 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4879 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4880 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4881 | break; |
| 4882 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4883 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4884 | case -NFS4ERR_EXPIRED: |
| 4885 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4886 | }; |
| 4887 | } |
| 4888 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4889 | 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] | 4890 | { |
| 4891 | struct nfs4_lockdata *data; |
| 4892 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4893 | struct rpc_message msg = { |
| 4894 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4895 | .rpc_cred = state->owner->so_cred, |
| 4896 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4897 | struct rpc_task_setup task_setup_data = { |
| 4898 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4899 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4900 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4901 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4902 | .flags = RPC_TASK_ASYNC, |
| 4903 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4904 | int ret; |
| 4905 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4906 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4907 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4908 | fl->fl_u.nfs4_fl.owner, |
| 4909 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4910 | if (data == NULL) |
| 4911 | return -ENOMEM; |
| 4912 | if (IS_SETLKW(cmd)) |
| 4913 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4914 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4915 | msg.rpc_argp = &data->arg; |
| 4916 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4917 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4918 | if (recovery_type > NFS_LOCK_NEW) { |
| 4919 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4920 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 4921 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 4922 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4923 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4924 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4925 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4926 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4927 | if (ret == 0) { |
| 4928 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4929 | if (ret) |
| 4930 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4931 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4932 | } else |
| 4933 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4934 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4935 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4936 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4940 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4941 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4942 | struct nfs4_exception exception = { |
| 4943 | .inode = state->inode, |
| 4944 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4945 | int err; |
| 4946 | |
| 4947 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4948 | /* Cache the lock if possible... */ |
| 4949 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4950 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4951 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4952 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4953 | break; |
| 4954 | nfs4_handle_exception(server, err, &exception); |
| 4955 | } while (exception.retry); |
| 4956 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4960 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4961 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4962 | struct nfs4_exception exception = { |
| 4963 | .inode = state->inode, |
| 4964 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4965 | int err; |
| 4966 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4967 | err = nfs4_set_lock_state(state, request); |
| 4968 | if (err != 0) |
| 4969 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4970 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4971 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4972 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4973 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4974 | switch (err) { |
| 4975 | default: |
| 4976 | goto out; |
| 4977 | case -NFS4ERR_GRACE: |
| 4978 | case -NFS4ERR_DELAY: |
| 4979 | nfs4_handle_exception(server, err, &exception); |
| 4980 | err = 0; |
| 4981 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4982 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4983 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4984 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | } |
| 4986 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4987 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4988 | /** |
| 4989 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4990 | * |
| 4991 | * @state: NFSv4 state for an inode |
| 4992 | * |
| 4993 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4994 | * Otherwise a negative NFS4ERR value is returned. |
| 4995 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4996 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4997 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4998 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4999 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5000 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5001 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5002 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5003 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5004 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 5005 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5006 | /* Free the stateid unless the server |
| 5007 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5008 | if (status != -NFS4ERR_BAD_STATEID) |
| 5009 | nfs41_free_stateid(server, |
| 5010 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5011 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5012 | ret = status; |
| 5013 | } |
| 5014 | } |
| 5015 | }; |
| 5016 | |
| 5017 | return ret; |
| 5018 | } |
| 5019 | |
| 5020 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5021 | { |
| 5022 | int status = NFS_OK; |
| 5023 | |
| 5024 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5025 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5026 | if (status != NFS_OK) |
| 5027 | status = nfs4_lock_expired(state, request); |
| 5028 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5029 | } |
| 5030 | #endif |
| 5031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5033 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5034 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5035 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5036 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5037 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5038 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5040 | if ((fl_flags & FL_POSIX) && |
| 5041 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5042 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5043 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5044 | status = nfs4_set_lock_state(state, request); |
| 5045 | if (status != 0) |
| 5046 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5047 | request->fl_flags |= FL_ACCESS; |
| 5048 | status = do_vfs_lock(request->fl_file, request); |
| 5049 | if (status < 0) |
| 5050 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5051 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5052 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5053 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5054 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5055 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5056 | status = do_vfs_lock(request->fl_file, request); |
| 5057 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5058 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5059 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5060 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5061 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5062 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5063 | goto out; |
| 5064 | down_read(&nfsi->rwsem); |
| 5065 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5066 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5067 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5068 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5069 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5070 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5071 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5072 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5073 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5074 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5075 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5076 | out: |
| 5077 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5078 | return status; |
| 5079 | } |
| 5080 | |
| 5081 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5082 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5083 | struct nfs4_exception exception = { |
| 5084 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5085 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5086 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | int err; |
| 5088 | |
| 5089 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5090 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5091 | if (err == -NFS4ERR_DENIED) |
| 5092 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5094 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | } while (exception.retry); |
| 5096 | return err; |
| 5097 | } |
| 5098 | |
| 5099 | static int |
| 5100 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5101 | { |
| 5102 | struct nfs_open_context *ctx; |
| 5103 | struct nfs4_state *state; |
| 5104 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5105 | int status; |
| 5106 | |
| 5107 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5108 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5109 | state = ctx->state; |
| 5110 | |
| 5111 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5112 | return -EINVAL; |
| 5113 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5114 | if (IS_GETLK(cmd)) { |
| 5115 | if (state != NULL) |
| 5116 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5117 | return 0; |
| 5118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | |
| 5120 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5121 | return -EINVAL; |
| 5122 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5123 | if (request->fl_type == F_UNLCK) { |
| 5124 | if (state != NULL) |
| 5125 | return nfs4_proc_unlck(state, cmd, request); |
| 5126 | return 0; |
| 5127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5129 | if (state == NULL) |
| 5130 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5131 | /* |
| 5132 | * Don't rely on the VFS having checked the file open mode, |
| 5133 | * since it won't do this for flock() locks. |
| 5134 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5135 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5136 | case F_RDLCK: |
| 5137 | if (!(filp->f_mode & FMODE_READ)) |
| 5138 | return -EBADF; |
| 5139 | break; |
| 5140 | case F_WRLCK: |
| 5141 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5142 | return -EBADF; |
| 5143 | } |
| 5144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | do { |
| 5146 | status = nfs4_proc_setlk(state, cmd, request); |
| 5147 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5148 | break; |
| 5149 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5150 | status = -ERESTARTSYS; |
| 5151 | if (signalled()) |
| 5152 | break; |
| 5153 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | return status; |
| 5155 | } |
| 5156 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5157 | int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5158 | { |
| 5159 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5160 | int err; |
| 5161 | |
| 5162 | err = nfs4_set_lock_state(state, fl); |
| 5163 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5164 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5165 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5166 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5167 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5168 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5169 | struct nfs_release_lockowner_data { |
| 5170 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5171 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5172 | struct nfs_release_lockowner_args args; |
| 5173 | }; |
| 5174 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5175 | static void nfs4_release_lockowner_release(void *calldata) |
| 5176 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5177 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5178 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5179 | kfree(calldata); |
| 5180 | } |
| 5181 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5182 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5183 | .rpc_release = nfs4_release_lockowner_release, |
| 5184 | }; |
| 5185 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5186 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5187 | { |
| 5188 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5189 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5190 | struct rpc_message msg = { |
| 5191 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5192 | }; |
| 5193 | |
| 5194 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5195 | return -EINVAL; |
| 5196 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5197 | if (!data) |
| 5198 | return -ENOMEM; |
| 5199 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5200 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5201 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5202 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5203 | data->args.lock_owner.s_dev = server->s_dev; |
| 5204 | msg.rpc_argp = &data->args; |
| 5205 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5206 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5207 | } |
| 5208 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5209 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5210 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5211 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5212 | const void *buf, size_t buflen, |
| 5213 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5214 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5215 | if (strcmp(key, "") != 0) |
| 5216 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5217 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5218 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5219 | } |
| 5220 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5221 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5222 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5223 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5224 | if (strcmp(key, "") != 0) |
| 5225 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5226 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5227 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5230 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5231 | size_t list_len, const char *name, |
| 5232 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5233 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5234 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5235 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5236 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5237 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5238 | |
| 5239 | if (list && len <= list_len) |
| 5240 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5241 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5244 | /* |
| 5245 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5246 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5247 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5248 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5249 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5250 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5251 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5252 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5253 | return; |
| 5254 | |
| 5255 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5256 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5257 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5258 | fattr->nlink = 2; |
| 5259 | } |
| 5260 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5261 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5262 | const struct qstr *name, |
| 5263 | struct nfs4_fs_locations *fs_locations, |
| 5264 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5265 | { |
| 5266 | struct nfs_server *server = NFS_SERVER(dir); |
| 5267 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5268 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5269 | }; |
| 5270 | struct nfs4_fs_locations_arg args = { |
| 5271 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5272 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5273 | .page = page, |
| 5274 | .bitmask = bitmask, |
| 5275 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5276 | struct nfs4_fs_locations_res res = { |
| 5277 | .fs_locations = fs_locations, |
| 5278 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5279 | struct rpc_message msg = { |
| 5280 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5281 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5282 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5283 | }; |
| 5284 | int status; |
| 5285 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5286 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5287 | |
| 5288 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5289 | * is not supported */ |
| 5290 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5291 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5292 | else |
| 5293 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5294 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5295 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5296 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5297 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5298 | 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] | 5299 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5300 | return status; |
| 5301 | } |
| 5302 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5303 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5304 | const struct qstr *name, |
| 5305 | struct nfs4_fs_locations *fs_locations, |
| 5306 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5307 | { |
| 5308 | struct nfs4_exception exception = { }; |
| 5309 | int err; |
| 5310 | do { |
| 5311 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5312 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5313 | &exception); |
| 5314 | } while (exception.retry); |
| 5315 | return err; |
| 5316 | } |
| 5317 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5318 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5319 | { |
| 5320 | int status; |
| 5321 | struct nfs4_secinfo_arg args = { |
| 5322 | .dir_fh = NFS_FH(dir), |
| 5323 | .name = name, |
| 5324 | }; |
| 5325 | struct nfs4_secinfo_res res = { |
| 5326 | .flavors = flavors, |
| 5327 | }; |
| 5328 | struct rpc_message msg = { |
| 5329 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5330 | .rpc_argp = &args, |
| 5331 | .rpc_resp = &res, |
| 5332 | }; |
| 5333 | |
| 5334 | dprintk("NFS call secinfo %s\n", name->name); |
| 5335 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5336 | dprintk("NFS reply secinfo: %d\n", status); |
| 5337 | return status; |
| 5338 | } |
| 5339 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5340 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5341 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5342 | { |
| 5343 | struct nfs4_exception exception = { }; |
| 5344 | int err; |
| 5345 | do { |
| 5346 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5347 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5348 | &exception); |
| 5349 | } while (exception.retry); |
| 5350 | return err; |
| 5351 | } |
| 5352 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5353 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5354 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5355 | * Check the exchange flags returned by the server for invalid flags, having |
| 5356 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5357 | * DS flags set. |
| 5358 | */ |
| 5359 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5360 | { |
| 5361 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5362 | goto out_inval; |
| 5363 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5364 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5365 | goto out_inval; |
| 5366 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5367 | goto out_inval; |
| 5368 | return NFS_OK; |
| 5369 | out_inval: |
| 5370 | return -NFS4ERR_INVAL; |
| 5371 | } |
| 5372 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5373 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5374 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5375 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5376 | { |
| 5377 | if (a->server_scope_sz == b->server_scope_sz && |
| 5378 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5379 | return true; |
| 5380 | |
| 5381 | return false; |
| 5382 | } |
| 5383 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5384 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5385 | * nfs4_proc_bind_conn_to_session() |
| 5386 | * |
| 5387 | * The 4.1 client currently uses the same TCP connection for the |
| 5388 | * fore and backchannel. |
| 5389 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5390 | 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] | 5391 | { |
| 5392 | int status; |
| 5393 | struct nfs41_bind_conn_to_session_res res; |
| 5394 | struct rpc_message msg = { |
| 5395 | .rpc_proc = |
| 5396 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5397 | .rpc_argp = clp, |
| 5398 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5399 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5400 | }; |
| 5401 | |
| 5402 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5403 | |
| 5404 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5405 | if (unlikely(res.session == NULL)) { |
| 5406 | status = -ENOMEM; |
| 5407 | goto out; |
| 5408 | } |
| 5409 | |
| 5410 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5411 | if (status == 0) { |
| 5412 | if (memcmp(res.session->sess_id.data, |
| 5413 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5414 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5415 | status = -EIO; |
| 5416 | goto out_session; |
| 5417 | } |
| 5418 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5419 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5420 | __func__); |
| 5421 | status = -EIO; |
| 5422 | goto out_session; |
| 5423 | } |
| 5424 | if (res.use_conn_in_rdma_mode) { |
| 5425 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5426 | __func__); |
| 5427 | status = -EIO; |
| 5428 | goto out_session; |
| 5429 | } |
| 5430 | } |
| 5431 | out_session: |
| 5432 | kfree(res.session); |
| 5433 | out: |
| 5434 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5435 | return status; |
| 5436 | } |
| 5437 | |
| 5438 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5439 | * nfs4_proc_exchange_id() |
| 5440 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5441 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5442 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5443 | * Since the clientid has expired, all compounds using sessions |
| 5444 | * associated with the stale clientid will be returning |
| 5445 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5446 | * be in some phase of session reset. |
| 5447 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5448 | 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] | 5449 | { |
| 5450 | nfs4_verifier verifier; |
| 5451 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5452 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5453 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5454 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5455 | }; |
| 5456 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5457 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5458 | }; |
| 5459 | int status; |
| 5460 | struct rpc_message msg = { |
| 5461 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5462 | .rpc_argp = &args, |
| 5463 | .rpc_resp = &res, |
| 5464 | .rpc_cred = cred, |
| 5465 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5466 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5467 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5468 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5469 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5470 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5471 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5472 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5473 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5474 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5475 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5476 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5477 | status = -ENOMEM; |
| 5478 | goto out; |
| 5479 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5480 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5481 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5482 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5483 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5484 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5485 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5486 | } |
| 5487 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5488 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5489 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5490 | status = -ENOMEM; |
| 5491 | goto out_server_scope; |
| 5492 | } |
| 5493 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5494 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5495 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5496 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5497 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5498 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5499 | clp->cl_clientid = res.clientid; |
| 5500 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5501 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5502 | clp->cl_seqid = res.seqid; |
| 5503 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5504 | kfree(clp->cl_serverowner); |
| 5505 | clp->cl_serverowner = res.server_owner; |
| 5506 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5507 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5508 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5509 | kfree(clp->cl_implid); |
| 5510 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5511 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5512 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5513 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5514 | res.server_scope)) { |
| 5515 | dprintk("%s: server_scope mismatch detected\n", |
| 5516 | __func__); |
| 5517 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5518 | kfree(clp->cl_serverscope); |
| 5519 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5520 | } |
| 5521 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5522 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5523 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5524 | goto out; |
| 5525 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5526 | } else |
| 5527 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5528 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5529 | out_server_owner: |
| 5530 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5531 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5532 | kfree(res.server_scope); |
| 5533 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5534 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5535 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5536 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5537 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5538 | clp->cl_implid->date.seconds, |
| 5539 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5540 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5541 | return status; |
| 5542 | } |
| 5543 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5544 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5545 | struct rpc_cred *cred) |
| 5546 | { |
| 5547 | struct rpc_message msg = { |
| 5548 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5549 | .rpc_argp = clp, |
| 5550 | .rpc_cred = cred, |
| 5551 | }; |
| 5552 | int status; |
| 5553 | |
| 5554 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5555 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5556 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5557 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5558 | return status; |
| 5559 | } |
| 5560 | |
| 5561 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5562 | struct rpc_cred *cred) |
| 5563 | { |
| 5564 | unsigned int loop; |
| 5565 | int ret; |
| 5566 | |
| 5567 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5568 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5569 | switch (ret) { |
| 5570 | case -NFS4ERR_DELAY: |
| 5571 | case -NFS4ERR_CLIENTID_BUSY: |
| 5572 | ssleep(1); |
| 5573 | break; |
| 5574 | default: |
| 5575 | return ret; |
| 5576 | } |
| 5577 | } |
| 5578 | return 0; |
| 5579 | } |
| 5580 | |
| 5581 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5582 | { |
| 5583 | struct rpc_cred *cred; |
| 5584 | int ret = 0; |
| 5585 | |
| 5586 | if (clp->cl_mvops->minor_version < 1) |
| 5587 | goto out; |
| 5588 | if (clp->cl_exchange_flags == 0) |
| 5589 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5590 | if (clp->cl_preserve_clid) |
| 5591 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5592 | cred = nfs4_get_exchange_id_cred(clp); |
| 5593 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5594 | if (cred) |
| 5595 | put_rpccred(cred); |
| 5596 | switch (ret) { |
| 5597 | case 0: |
| 5598 | case -NFS4ERR_STALE_CLIENTID: |
| 5599 | clp->cl_exchange_flags = 0; |
| 5600 | } |
| 5601 | out: |
| 5602 | return ret; |
| 5603 | } |
| 5604 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5605 | struct nfs4_get_lease_time_data { |
| 5606 | struct nfs4_get_lease_time_args *args; |
| 5607 | struct nfs4_get_lease_time_res *res; |
| 5608 | struct nfs_client *clp; |
| 5609 | }; |
| 5610 | |
| 5611 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5612 | void *calldata) |
| 5613 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5614 | struct nfs4_get_lease_time_data *data = |
| 5615 | (struct nfs4_get_lease_time_data *)calldata; |
| 5616 | |
| 5617 | dprintk("--> %s\n", __func__); |
| 5618 | /* just setup sequence, do not trigger session recovery |
| 5619 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5620 | nfs41_setup_sequence(data->clp->cl_session, |
| 5621 | &data->args->la_seq_args, |
| 5622 | &data->res->lr_seq_res, |
| 5623 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5624 | dprintk("<-- %s\n", __func__); |
| 5625 | } |
| 5626 | |
| 5627 | /* |
| 5628 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5629 | * from sequence operation or clientid errors. |
| 5630 | */ |
| 5631 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5632 | { |
| 5633 | struct nfs4_get_lease_time_data *data = |
| 5634 | (struct nfs4_get_lease_time_data *)calldata; |
| 5635 | |
| 5636 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5637 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5638 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5639 | switch (task->tk_status) { |
| 5640 | case -NFS4ERR_DELAY: |
| 5641 | case -NFS4ERR_GRACE: |
| 5642 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5643 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5644 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5645 | /* fall through */ |
| 5646 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5647 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5648 | return; |
| 5649 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5650 | dprintk("<-- %s\n", __func__); |
| 5651 | } |
| 5652 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5653 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5654 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5655 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5656 | }; |
| 5657 | |
| 5658 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5659 | { |
| 5660 | struct rpc_task *task; |
| 5661 | struct nfs4_get_lease_time_args args; |
| 5662 | struct nfs4_get_lease_time_res res = { |
| 5663 | .lr_fsinfo = fsinfo, |
| 5664 | }; |
| 5665 | struct nfs4_get_lease_time_data data = { |
| 5666 | .args = &args, |
| 5667 | .res = &res, |
| 5668 | .clp = clp, |
| 5669 | }; |
| 5670 | struct rpc_message msg = { |
| 5671 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5672 | .rpc_argp = &args, |
| 5673 | .rpc_resp = &res, |
| 5674 | }; |
| 5675 | struct rpc_task_setup task_setup = { |
| 5676 | .rpc_client = clp->cl_rpcclient, |
| 5677 | .rpc_message = &msg, |
| 5678 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5679 | .callback_data = &data, |
| 5680 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5681 | }; |
| 5682 | int status; |
| 5683 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5684 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5685 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5686 | dprintk("--> %s\n", __func__); |
| 5687 | task = rpc_run_task(&task_setup); |
| 5688 | |
| 5689 | if (IS_ERR(task)) |
| 5690 | status = PTR_ERR(task); |
| 5691 | else { |
| 5692 | status = task->tk_status; |
| 5693 | rpc_put_task(task); |
| 5694 | } |
| 5695 | dprintk("<-- %s return %d\n", __func__, status); |
| 5696 | |
| 5697 | return status; |
| 5698 | } |
| 5699 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5700 | /* |
| 5701 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5702 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5703 | * use them. |
| 5704 | * |
| 5705 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5706 | * always set csa_cachethis to FALSE because the current implementation |
| 5707 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5708 | */ |
| 5709 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5710 | { |
| 5711 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5712 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5713 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5714 | |
| 5715 | if (mxrqst_sz == 0) |
| 5716 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5717 | if (mxresp_sz == 0) |
| 5718 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5719 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5720 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5721 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5722 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5723 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5724 | |
| 5725 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5726 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5727 | __func__, |
| 5728 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5729 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5730 | |
| 5731 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5732 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5733 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5734 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5735 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5736 | args->bc_attrs.max_reqs = 1; |
| 5737 | |
| 5738 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5739 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5740 | __func__, |
| 5741 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5742 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5743 | args->bc_attrs.max_reqs); |
| 5744 | } |
| 5745 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5746 | 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] | 5747 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5748 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5749 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5750 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5751 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5752 | return -EINVAL; |
| 5753 | /* |
| 5754 | * Our requested max_ops is the minimum we need; we're not |
| 5755 | * prepared to break up compounds into smaller pieces than that. |
| 5756 | * So, no point even trying to continue if the server won't |
| 5757 | * cooperate: |
| 5758 | */ |
| 5759 | if (rcvd->max_ops < sent->max_ops) |
| 5760 | return -EINVAL; |
| 5761 | if (rcvd->max_reqs == 0) |
| 5762 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5763 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5764 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5765 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5766 | } |
| 5767 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5768 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5769 | { |
| 5770 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5771 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5772 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5773 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5774 | return -EINVAL; |
| 5775 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5776 | return -EINVAL; |
| 5777 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5778 | return -EINVAL; |
| 5779 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5780 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5781 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5782 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5783 | return -EINVAL; |
| 5784 | return 0; |
| 5785 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5786 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5787 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5788 | struct nfs4_session *session) |
| 5789 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5790 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5791 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5792 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5793 | if (ret) |
| 5794 | return ret; |
| 5795 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5796 | } |
| 5797 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5798 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5799 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5800 | { |
| 5801 | struct nfs4_session *session = clp->cl_session; |
| 5802 | struct nfs41_create_session_args args = { |
| 5803 | .client = clp, |
| 5804 | .cb_program = NFS4_CALLBACK, |
| 5805 | }; |
| 5806 | struct nfs41_create_session_res res = { |
| 5807 | .client = clp, |
| 5808 | }; |
| 5809 | struct rpc_message msg = { |
| 5810 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5811 | .rpc_argp = &args, |
| 5812 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5813 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5814 | }; |
| 5815 | int status; |
| 5816 | |
| 5817 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5818 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5819 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5820 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5821 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5822 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5823 | /* Verify the session's negotiated channel_attrs values */ |
| 5824 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5825 | /* Increment the clientid slot sequence id */ |
| 5826 | clp->cl_seqid++; |
| 5827 | } |
| 5828 | |
| 5829 | return status; |
| 5830 | } |
| 5831 | |
| 5832 | /* |
| 5833 | * Issues a CREATE_SESSION operation to the server. |
| 5834 | * It is the responsibility of the caller to verify the session is |
| 5835 | * expired before calling this routine. |
| 5836 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5837 | 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] | 5838 | { |
| 5839 | int status; |
| 5840 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5841 | struct nfs4_session *session = clp->cl_session; |
| 5842 | |
| 5843 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5844 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5845 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5846 | if (status) |
| 5847 | goto out; |
| 5848 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5849 | /* Init or reset the session slot tables */ |
| 5850 | status = nfs4_setup_session_slot_tables(session); |
| 5851 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5852 | if (status) |
| 5853 | goto out; |
| 5854 | |
| 5855 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5856 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5857 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5858 | out: |
| 5859 | dprintk("<-- %s\n", __func__); |
| 5860 | return status; |
| 5861 | } |
| 5862 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5863 | /* |
| 5864 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5865 | * The caller must serialize access to this routine. |
| 5866 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5867 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5868 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5869 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5870 | struct rpc_message msg = { |
| 5871 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5872 | .rpc_argp = session, |
| 5873 | .rpc_cred = cred, |
| 5874 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5875 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5876 | |
| 5877 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5878 | |
| 5879 | /* session is still being setup */ |
| 5880 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5881 | return status; |
| 5882 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5883 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5884 | |
| 5885 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5886 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5887 | "Session has been destroyed regardless...\n", status); |
| 5888 | |
| 5889 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5890 | return status; |
| 5891 | } |
| 5892 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5893 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5894 | * Renew the cl_session lease. |
| 5895 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5896 | struct nfs4_sequence_data { |
| 5897 | struct nfs_client *clp; |
| 5898 | struct nfs4_sequence_args args; |
| 5899 | struct nfs4_sequence_res res; |
| 5900 | }; |
| 5901 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5902 | static void nfs41_sequence_release(void *data) |
| 5903 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5904 | struct nfs4_sequence_data *calldata = data; |
| 5905 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5906 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5907 | if (atomic_read(&clp->cl_count) > 1) |
| 5908 | nfs4_schedule_state_renewal(clp); |
| 5909 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5910 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5911 | } |
| 5912 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5913 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5914 | { |
| 5915 | switch(task->tk_status) { |
| 5916 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5917 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5918 | return -EAGAIN; |
| 5919 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5920 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5921 | } |
| 5922 | return 0; |
| 5923 | } |
| 5924 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5925 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5926 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5927 | struct nfs4_sequence_data *calldata = data; |
| 5928 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5929 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5930 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5931 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5932 | |
| 5933 | if (task->tk_status < 0) { |
| 5934 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5935 | if (atomic_read(&clp->cl_count) == 1) |
| 5936 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5937 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5938 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5939 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5940 | return; |
| 5941 | } |
| 5942 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5943 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5944 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5945 | dprintk("<-- %s\n", __func__); |
| 5946 | } |
| 5947 | |
| 5948 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5949 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5950 | struct nfs4_sequence_data *calldata = data; |
| 5951 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5952 | struct nfs4_sequence_args *args; |
| 5953 | struct nfs4_sequence_res *res; |
| 5954 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5955 | args = task->tk_msg.rpc_argp; |
| 5956 | res = task->tk_msg.rpc_resp; |
| 5957 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5958 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5962 | .rpc_call_done = nfs41_sequence_call_done, |
| 5963 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5964 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5965 | }; |
| 5966 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5967 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 5968 | struct rpc_cred *cred, |
| 5969 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5970 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5971 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5972 | struct rpc_message msg = { |
| 5973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5974 | .rpc_cred = cred, |
| 5975 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5976 | struct rpc_task_setup task_setup_data = { |
| 5977 | .rpc_client = clp->cl_rpcclient, |
| 5978 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5979 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5980 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5981 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5982 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5983 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5984 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5985 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5986 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5987 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5988 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5989 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5990 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5991 | if (is_privileged) |
| 5992 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5993 | msg.rpc_argp = &calldata->args; |
| 5994 | msg.rpc_resp = &calldata->res; |
| 5995 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5996 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5997 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5998 | return rpc_run_task(&task_setup_data); |
| 5999 | } |
| 6000 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6001 | 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] | 6002 | { |
| 6003 | struct rpc_task *task; |
| 6004 | int ret = 0; |
| 6005 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6006 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6007 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6008 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6009 | if (IS_ERR(task)) |
| 6010 | ret = PTR_ERR(task); |
| 6011 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6012 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6013 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6014 | return ret; |
| 6015 | } |
| 6016 | |
| 6017 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6018 | { |
| 6019 | struct rpc_task *task; |
| 6020 | int ret; |
| 6021 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6022 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6023 | if (IS_ERR(task)) { |
| 6024 | ret = PTR_ERR(task); |
| 6025 | goto out; |
| 6026 | } |
| 6027 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6028 | if (!ret) { |
| 6029 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6030 | |
| 6031 | if (task->tk_status == 0) |
| 6032 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6033 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6034 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6035 | rpc_put_task(task); |
| 6036 | out: |
| 6037 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6038 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6039 | } |
| 6040 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6041 | struct nfs4_reclaim_complete_data { |
| 6042 | struct nfs_client *clp; |
| 6043 | struct nfs41_reclaim_complete_args arg; |
| 6044 | struct nfs41_reclaim_complete_res res; |
| 6045 | }; |
| 6046 | |
| 6047 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6048 | { |
| 6049 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6050 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6051 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6052 | &calldata->arg.seq_args, |
| 6053 | &calldata->res.seq_res, |
| 6054 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6055 | } |
| 6056 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6057 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6058 | { |
| 6059 | switch(task->tk_status) { |
| 6060 | case 0: |
| 6061 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6062 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6063 | break; |
| 6064 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6065 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6066 | /* fall through */ |
| 6067 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6068 | return -EAGAIN; |
| 6069 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6070 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6071 | } |
| 6072 | return 0; |
| 6073 | } |
| 6074 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6075 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6076 | { |
| 6077 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6078 | struct nfs_client *clp = calldata->clp; |
| 6079 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6080 | |
| 6081 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6082 | if (!nfs41_sequence_done(task, res)) |
| 6083 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6084 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6085 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6086 | rpc_restart_call_prepare(task); |
| 6087 | return; |
| 6088 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6089 | dprintk("<-- %s\n", __func__); |
| 6090 | } |
| 6091 | |
| 6092 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6093 | { |
| 6094 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6095 | |
| 6096 | kfree(calldata); |
| 6097 | } |
| 6098 | |
| 6099 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6100 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6101 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6102 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6103 | }; |
| 6104 | |
| 6105 | /* |
| 6106 | * Issue a global reclaim complete. |
| 6107 | */ |
| 6108 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6109 | { |
| 6110 | struct nfs4_reclaim_complete_data *calldata; |
| 6111 | struct rpc_task *task; |
| 6112 | struct rpc_message msg = { |
| 6113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6114 | }; |
| 6115 | struct rpc_task_setup task_setup_data = { |
| 6116 | .rpc_client = clp->cl_rpcclient, |
| 6117 | .rpc_message = &msg, |
| 6118 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6119 | .flags = RPC_TASK_ASYNC, |
| 6120 | }; |
| 6121 | int status = -ENOMEM; |
| 6122 | |
| 6123 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6124 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6125 | if (calldata == NULL) |
| 6126 | goto out; |
| 6127 | calldata->clp = clp; |
| 6128 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6129 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6130 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6131 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6132 | msg.rpc_argp = &calldata->arg; |
| 6133 | msg.rpc_resp = &calldata->res; |
| 6134 | task_setup_data.callback_data = calldata; |
| 6135 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6136 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6137 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6138 | goto out; |
| 6139 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6140 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6141 | if (status == 0) |
| 6142 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6143 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6144 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6145 | out: |
| 6146 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6147 | return status; |
| 6148 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6149 | |
| 6150 | static void |
| 6151 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6152 | { |
| 6153 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6154 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6155 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6156 | |
| 6157 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6158 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6159 | * right now covering the LAYOUTGET we are about to send. |
| 6160 | * However, that is not so catastrophic, and there seems |
| 6161 | * to be no way to prevent it completely. |
| 6162 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6163 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6164 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6165 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6166 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6167 | NFS_I(lgp->args.inode)->layout, |
| 6168 | lgp->args.ctx->state)) { |
| 6169 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6170 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6174 | { |
| 6175 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6176 | struct inode *inode = lgp->args.inode; |
| 6177 | struct nfs_server *server = NFS_SERVER(inode); |
| 6178 | struct pnfs_layout_hdr *lo; |
| 6179 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6180 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6181 | |
| 6182 | dprintk("--> %s\n", __func__); |
| 6183 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6184 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6185 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6186 | |
| 6187 | switch (task->tk_status) { |
| 6188 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6189 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6190 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6191 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6192 | timeo = rpc_get_timeout(task->tk_client); |
| 6193 | giveup = lgp->args.timestamp + timeo; |
| 6194 | if (time_after(giveup, jiffies)) |
| 6195 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6196 | break; |
| 6197 | case -NFS4ERR_EXPIRED: |
| 6198 | case -NFS4ERR_BAD_STATEID: |
| 6199 | spin_lock(&inode->i_lock); |
| 6200 | lo = NFS_I(inode)->layout; |
| 6201 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6202 | spin_unlock(&inode->i_lock); |
| 6203 | /* If the open stateid was bad, then recover it. */ |
| 6204 | state = lgp->args.ctx->state; |
| 6205 | } else { |
| 6206 | LIST_HEAD(head); |
| 6207 | |
| 6208 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6209 | spin_unlock(&inode->i_lock); |
| 6210 | /* Mark the bad layout state as invalid, then |
| 6211 | * retry using the open stateid. */ |
| 6212 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6213 | } |
| 6214 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6215 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6216 | rpc_restart_call_prepare(task); |
| 6217 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6218 | dprintk("<-- %s\n", __func__); |
| 6219 | } |
| 6220 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6221 | static size_t max_response_pages(struct nfs_server *server) |
| 6222 | { |
| 6223 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6224 | return nfs_page_array_len(0, max_resp_sz); |
| 6225 | } |
| 6226 | |
| 6227 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6228 | { |
| 6229 | int i; |
| 6230 | |
| 6231 | if (!pages) |
| 6232 | return; |
| 6233 | |
| 6234 | for (i = 0; i < size; i++) { |
| 6235 | if (!pages[i]) |
| 6236 | break; |
| 6237 | __free_page(pages[i]); |
| 6238 | } |
| 6239 | kfree(pages); |
| 6240 | } |
| 6241 | |
| 6242 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6243 | { |
| 6244 | struct page **pages; |
| 6245 | int i; |
| 6246 | |
| 6247 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6248 | if (!pages) { |
| 6249 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6250 | return NULL; |
| 6251 | } |
| 6252 | |
| 6253 | for (i = 0; i < size; i++) { |
| 6254 | pages[i] = alloc_page(gfp_flags); |
| 6255 | if (!pages[i]) { |
| 6256 | dprintk("%s: failed to allocate page\n", __func__); |
| 6257 | nfs4_free_pages(pages, size); |
| 6258 | return NULL; |
| 6259 | } |
| 6260 | } |
| 6261 | |
| 6262 | return pages; |
| 6263 | } |
| 6264 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6265 | static void nfs4_layoutget_release(void *calldata) |
| 6266 | { |
| 6267 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6268 | struct inode *inode = lgp->args.inode; |
| 6269 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6270 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6271 | |
| 6272 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6273 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6274 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6275 | put_nfs_open_context(lgp->args.ctx); |
| 6276 | kfree(calldata); |
| 6277 | dprintk("<-- %s\n", __func__); |
| 6278 | } |
| 6279 | |
| 6280 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6281 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6282 | .rpc_call_done = nfs4_layoutget_done, |
| 6283 | .rpc_release = nfs4_layoutget_release, |
| 6284 | }; |
| 6285 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6286 | struct pnfs_layout_segment * |
| 6287 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6288 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6289 | struct inode *inode = lgp->args.inode; |
| 6290 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6291 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6292 | struct rpc_task *task; |
| 6293 | struct rpc_message msg = { |
| 6294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6295 | .rpc_argp = &lgp->args, |
| 6296 | .rpc_resp = &lgp->res, |
| 6297 | }; |
| 6298 | struct rpc_task_setup task_setup_data = { |
| 6299 | .rpc_client = server->client, |
| 6300 | .rpc_message = &msg, |
| 6301 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6302 | .callback_data = lgp, |
| 6303 | .flags = RPC_TASK_ASYNC, |
| 6304 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6305 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6306 | int status = 0; |
| 6307 | |
| 6308 | dprintk("--> %s\n", __func__); |
| 6309 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6310 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6311 | if (!lgp->args.layout.pages) { |
| 6312 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6313 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6314 | } |
| 6315 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6316 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6317 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6318 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6319 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6320 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6321 | |
| 6322 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6323 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6324 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6325 | task = rpc_run_task(&task_setup_data); |
| 6326 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6327 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6328 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6329 | if (status == 0) |
| 6330 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6331 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6332 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6333 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6334 | rpc_put_task(task); |
| 6335 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6336 | if (status) |
| 6337 | return ERR_PTR(status); |
| 6338 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6339 | } |
| 6340 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6341 | static void |
| 6342 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6343 | { |
| 6344 | struct nfs4_layoutreturn *lrp = calldata; |
| 6345 | |
| 6346 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6347 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6348 | &lrp->args.seq_args, |
| 6349 | &lrp->res.seq_res, |
| 6350 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6354 | { |
| 6355 | struct nfs4_layoutreturn *lrp = calldata; |
| 6356 | struct nfs_server *server; |
| 6357 | |
| 6358 | dprintk("--> %s\n", __func__); |
| 6359 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6360 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6361 | return; |
| 6362 | |
| 6363 | server = NFS_SERVER(lrp->args.inode); |
| 6364 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6365 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6366 | return; |
| 6367 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6368 | dprintk("<-- %s\n", __func__); |
| 6369 | } |
| 6370 | |
| 6371 | static void nfs4_layoutreturn_release(void *calldata) |
| 6372 | { |
| 6373 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6374 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6375 | |
| 6376 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6377 | spin_lock(&lo->plh_inode->i_lock); |
| 6378 | if (lrp->res.lrs_present) |
| 6379 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6380 | lo->plh_block_lgets--; |
| 6381 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6382 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6383 | kfree(calldata); |
| 6384 | dprintk("<-- %s\n", __func__); |
| 6385 | } |
| 6386 | |
| 6387 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6388 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6389 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6390 | .rpc_release = nfs4_layoutreturn_release, |
| 6391 | }; |
| 6392 | |
| 6393 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6394 | { |
| 6395 | struct rpc_task *task; |
| 6396 | struct rpc_message msg = { |
| 6397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6398 | .rpc_argp = &lrp->args, |
| 6399 | .rpc_resp = &lrp->res, |
| 6400 | }; |
| 6401 | struct rpc_task_setup task_setup_data = { |
| 6402 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6403 | .rpc_message = &msg, |
| 6404 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6405 | .callback_data = lrp, |
| 6406 | }; |
| 6407 | int status; |
| 6408 | |
| 6409 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6410 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6411 | task = rpc_run_task(&task_setup_data); |
| 6412 | if (IS_ERR(task)) |
| 6413 | return PTR_ERR(task); |
| 6414 | status = task->tk_status; |
| 6415 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6416 | rpc_put_task(task); |
| 6417 | return status; |
| 6418 | } |
| 6419 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6420 | /* |
| 6421 | * Retrieve the list of Data Server devices from the MDS. |
| 6422 | */ |
| 6423 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6424 | const struct nfs_fh *fh, |
| 6425 | struct pnfs_devicelist *devlist) |
| 6426 | { |
| 6427 | struct nfs4_getdevicelist_args args = { |
| 6428 | .fh = fh, |
| 6429 | .layoutclass = server->pnfs_curr_ld->id, |
| 6430 | }; |
| 6431 | struct nfs4_getdevicelist_res res = { |
| 6432 | .devlist = devlist, |
| 6433 | }; |
| 6434 | struct rpc_message msg = { |
| 6435 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6436 | .rpc_argp = &args, |
| 6437 | .rpc_resp = &res, |
| 6438 | }; |
| 6439 | int status; |
| 6440 | |
| 6441 | dprintk("--> %s\n", __func__); |
| 6442 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6443 | &res.seq_res, 0); |
| 6444 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6445 | return status; |
| 6446 | } |
| 6447 | |
| 6448 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6449 | const struct nfs_fh *fh, |
| 6450 | struct pnfs_devicelist *devlist) |
| 6451 | { |
| 6452 | struct nfs4_exception exception = { }; |
| 6453 | int err; |
| 6454 | |
| 6455 | do { |
| 6456 | err = nfs4_handle_exception(server, |
| 6457 | _nfs4_getdevicelist(server, fh, devlist), |
| 6458 | &exception); |
| 6459 | } while (exception.retry); |
| 6460 | |
| 6461 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6462 | err, devlist->num_devs); |
| 6463 | |
| 6464 | return err; |
| 6465 | } |
| 6466 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6467 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6468 | static int |
| 6469 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6470 | { |
| 6471 | struct nfs4_getdeviceinfo_args args = { |
| 6472 | .pdev = pdev, |
| 6473 | }; |
| 6474 | struct nfs4_getdeviceinfo_res res = { |
| 6475 | .pdev = pdev, |
| 6476 | }; |
| 6477 | struct rpc_message msg = { |
| 6478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6479 | .rpc_argp = &args, |
| 6480 | .rpc_resp = &res, |
| 6481 | }; |
| 6482 | int status; |
| 6483 | |
| 6484 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6485 | 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] | 6486 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6487 | |
| 6488 | return status; |
| 6489 | } |
| 6490 | |
| 6491 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6492 | { |
| 6493 | struct nfs4_exception exception = { }; |
| 6494 | int err; |
| 6495 | |
| 6496 | do { |
| 6497 | err = nfs4_handle_exception(server, |
| 6498 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6499 | &exception); |
| 6500 | } while (exception.retry); |
| 6501 | return err; |
| 6502 | } |
| 6503 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6504 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6505 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6506 | { |
| 6507 | struct nfs4_layoutcommit_data *data = calldata; |
| 6508 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6509 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6510 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6511 | nfs41_setup_sequence(session, |
| 6512 | &data->args.seq_args, |
| 6513 | &data->res.seq_res, |
| 6514 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6515 | } |
| 6516 | |
| 6517 | static void |
| 6518 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6519 | { |
| 6520 | struct nfs4_layoutcommit_data *data = calldata; |
| 6521 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6522 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6523 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6524 | return; |
| 6525 | |
| 6526 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6527 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6528 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6529 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6530 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6531 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6532 | break; |
| 6533 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6534 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6535 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6536 | break; |
| 6537 | default: |
| 6538 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6539 | rpc_restart_call_prepare(task); |
| 6540 | return; |
| 6541 | } |
| 6542 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6543 | } |
| 6544 | |
| 6545 | static void nfs4_layoutcommit_release(void *calldata) |
| 6546 | { |
| 6547 | struct nfs4_layoutcommit_data *data = calldata; |
| 6548 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6549 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6550 | put_rpccred(data->cred); |
| 6551 | kfree(data); |
| 6552 | } |
| 6553 | |
| 6554 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6555 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6556 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6557 | .rpc_release = nfs4_layoutcommit_release, |
| 6558 | }; |
| 6559 | |
| 6560 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6561 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6562 | { |
| 6563 | struct rpc_message msg = { |
| 6564 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6565 | .rpc_argp = &data->args, |
| 6566 | .rpc_resp = &data->res, |
| 6567 | .rpc_cred = data->cred, |
| 6568 | }; |
| 6569 | struct rpc_task_setup task_setup_data = { |
| 6570 | .task = &data->task, |
| 6571 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6572 | .rpc_message = &msg, |
| 6573 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6574 | .callback_data = data, |
| 6575 | .flags = RPC_TASK_ASYNC, |
| 6576 | }; |
| 6577 | struct rpc_task *task; |
| 6578 | int status = 0; |
| 6579 | |
| 6580 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6581 | "lbw: %llu inode %lu\n", |
| 6582 | data->task.tk_pid, sync, |
| 6583 | data->args.lastbytewritten, |
| 6584 | data->args.inode->i_ino); |
| 6585 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6586 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6587 | task = rpc_run_task(&task_setup_data); |
| 6588 | if (IS_ERR(task)) |
| 6589 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6590 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6591 | goto out; |
| 6592 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6593 | if (status != 0) |
| 6594 | goto out; |
| 6595 | status = task->tk_status; |
| 6596 | out: |
| 6597 | dprintk("%s: status %d\n", __func__, status); |
| 6598 | rpc_put_task(task); |
| 6599 | return status; |
| 6600 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6601 | |
| 6602 | static int |
| 6603 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6604 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6605 | { |
| 6606 | struct nfs41_secinfo_no_name_args args = { |
| 6607 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6608 | }; |
| 6609 | struct nfs4_secinfo_res res = { |
| 6610 | .flavors = flavors, |
| 6611 | }; |
| 6612 | struct rpc_message msg = { |
| 6613 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6614 | .rpc_argp = &args, |
| 6615 | .rpc_resp = &res, |
| 6616 | }; |
| 6617 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6618 | } |
| 6619 | |
| 6620 | static int |
| 6621 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6622 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6623 | { |
| 6624 | struct nfs4_exception exception = { }; |
| 6625 | int err; |
| 6626 | do { |
| 6627 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6628 | switch (err) { |
| 6629 | case 0: |
| 6630 | case -NFS4ERR_WRONGSEC: |
| 6631 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6632 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6633 | default: |
| 6634 | err = nfs4_handle_exception(server, err, &exception); |
| 6635 | } |
| 6636 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6637 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6638 | return err; |
| 6639 | } |
| 6640 | |
| 6641 | static int |
| 6642 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6643 | struct nfs_fsinfo *info) |
| 6644 | { |
| 6645 | int err; |
| 6646 | struct page *page; |
| 6647 | rpc_authflavor_t flavor; |
| 6648 | struct nfs4_secinfo_flavors *flavors; |
| 6649 | |
| 6650 | page = alloc_page(GFP_KERNEL); |
| 6651 | if (!page) { |
| 6652 | err = -ENOMEM; |
| 6653 | goto out; |
| 6654 | } |
| 6655 | |
| 6656 | flavors = page_address(page); |
| 6657 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6658 | |
| 6659 | /* |
| 6660 | * Fall back on "guess and check" method if |
| 6661 | * the server doesn't support SECINFO_NO_NAME |
| 6662 | */ |
| 6663 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6664 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6665 | goto out_freepage; |
| 6666 | } |
| 6667 | if (err) |
| 6668 | goto out_freepage; |
| 6669 | |
| 6670 | flavor = nfs_find_best_sec(flavors); |
| 6671 | if (err == 0) |
| 6672 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6673 | |
| 6674 | out_freepage: |
| 6675 | put_page(page); |
| 6676 | if (err == -EACCES) |
| 6677 | return -EPERM; |
| 6678 | out: |
| 6679 | return err; |
| 6680 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6681 | |
| 6682 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6683 | { |
| 6684 | int status; |
| 6685 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6686 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6687 | }; |
| 6688 | struct nfs41_test_stateid_res res; |
| 6689 | struct rpc_message msg = { |
| 6690 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6691 | .rpc_argp = &args, |
| 6692 | .rpc_resp = &res, |
| 6693 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6694 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6695 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6696 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6697 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6698 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6699 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6700 | if (status != NFS_OK) { |
| 6701 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6702 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6703 | } |
| 6704 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6705 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6706 | } |
| 6707 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6708 | /** |
| 6709 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6710 | * |
| 6711 | * @server: server / transport on which to perform the operation |
| 6712 | * @stateid: state ID to test |
| 6713 | * |
| 6714 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6715 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6716 | * failed or the state ID is not currently valid. |
| 6717 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6718 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6719 | { |
| 6720 | struct nfs4_exception exception = { }; |
| 6721 | int err; |
| 6722 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6723 | err = _nfs41_test_stateid(server, stateid); |
| 6724 | if (err != -NFS4ERR_DELAY) |
| 6725 | break; |
| 6726 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6727 | } while (exception.retry); |
| 6728 | return err; |
| 6729 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6730 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6731 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6732 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6733 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6734 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6735 | }; |
| 6736 | struct nfs41_free_stateid_res res; |
| 6737 | struct rpc_message msg = { |
| 6738 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6739 | .rpc_argp = &args, |
| 6740 | .rpc_resp = &res, |
| 6741 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6742 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6743 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6744 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6745 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6746 | nfs4_set_sequence_privileged(&args.seq_args); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6747 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6748 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6749 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6750 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6751 | } |
| 6752 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6753 | /** |
| 6754 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6755 | * |
| 6756 | * @server: server / transport on which to perform the operation |
| 6757 | * @stateid: state ID to release |
| 6758 | * |
| 6759 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6760 | * negative NFS4ERR value is returned. |
| 6761 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6762 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6763 | { |
| 6764 | struct nfs4_exception exception = { }; |
| 6765 | int err; |
| 6766 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6767 | err = _nfs4_free_stateid(server, stateid); |
| 6768 | if (err != -NFS4ERR_DELAY) |
| 6769 | break; |
| 6770 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6771 | } while (exception.retry); |
| 6772 | return err; |
| 6773 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6774 | |
| 6775 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6776 | const nfs4_stateid *s2) |
| 6777 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6778 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6779 | return false; |
| 6780 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6781 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6782 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6783 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6784 | return true; |
| 6785 | |
| 6786 | return false; |
| 6787 | } |
| 6788 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6789 | #endif /* CONFIG_NFS_V4_1 */ |
| 6790 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6791 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6792 | const nfs4_stateid *s2) |
| 6793 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6794 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6795 | } |
| 6796 | |
| 6797 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6798 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6799 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6800 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6801 | .recover_open = nfs4_open_reclaim, |
| 6802 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6803 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6804 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6805 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6806 | }; |
| 6807 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6808 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6809 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6810 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6811 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6812 | .recover_open = nfs4_open_reclaim, |
| 6813 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6814 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6815 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6816 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6817 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6818 | }; |
| 6819 | #endif /* CONFIG_NFS_V4_1 */ |
| 6820 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6821 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6822 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6823 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6824 | .recover_open = nfs4_open_expired, |
| 6825 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6826 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6827 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6828 | }; |
| 6829 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6830 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6831 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6832 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6833 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6834 | .recover_open = nfs41_open_expired, |
| 6835 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6836 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6837 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6838 | }; |
| 6839 | #endif /* CONFIG_NFS_V4_1 */ |
| 6840 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6841 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6842 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6843 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6844 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6845 | }; |
| 6846 | |
| 6847 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6848 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6849 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6850 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6851 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6852 | }; |
| 6853 | #endif |
| 6854 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6855 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6856 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6857 | .init_caps = NFS_CAP_READDIRPLUS |
| 6858 | | NFS_CAP_ATOMIC_OPEN |
| 6859 | | NFS_CAP_CHANGE_ATTR |
| 6860 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6861 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6862 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6863 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6864 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6865 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6866 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6867 | }; |
| 6868 | |
| 6869 | #if defined(CONFIG_NFS_V4_1) |
| 6870 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6871 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 6872 | .init_caps = NFS_CAP_READDIRPLUS |
| 6873 | | NFS_CAP_ATOMIC_OPEN |
| 6874 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 6875 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 6876 | | NFS_CAP_STATEID_NFSV41 |
| 6877 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 6878 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6879 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6880 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6881 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6882 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6883 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6884 | }; |
| 6885 | #endif |
| 6886 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6887 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6888 | [0] = &nfs_v4_0_minor_ops, |
| 6889 | #if defined(CONFIG_NFS_V4_1) |
| 6890 | [1] = &nfs_v4_1_minor_ops, |
| 6891 | #endif |
| 6892 | }; |
| 6893 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6894 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6895 | .create = nfs_create, |
| 6896 | .lookup = nfs_lookup, |
| 6897 | .atomic_open = nfs_atomic_open, |
| 6898 | .link = nfs_link, |
| 6899 | .unlink = nfs_unlink, |
| 6900 | .symlink = nfs_symlink, |
| 6901 | .mkdir = nfs_mkdir, |
| 6902 | .rmdir = nfs_rmdir, |
| 6903 | .mknod = nfs_mknod, |
| 6904 | .rename = nfs_rename, |
| 6905 | .permission = nfs_permission, |
| 6906 | .getattr = nfs_getattr, |
| 6907 | .setattr = nfs_setattr, |
| 6908 | .getxattr = generic_getxattr, |
| 6909 | .setxattr = generic_setxattr, |
| 6910 | .listxattr = generic_listxattr, |
| 6911 | .removexattr = generic_removexattr, |
| 6912 | }; |
| 6913 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6914 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6915 | .permission = nfs_permission, |
| 6916 | .getattr = nfs_getattr, |
| 6917 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6918 | .getxattr = generic_getxattr, |
| 6919 | .setxattr = generic_setxattr, |
| 6920 | .listxattr = generic_listxattr, |
| 6921 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6922 | }; |
| 6923 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6924 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6925 | .version = 4, /* protocol version */ |
| 6926 | .dentry_ops = &nfs4_dentry_operations, |
| 6927 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6928 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6929 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6930 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6931 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6932 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6933 | .getattr = nfs4_proc_getattr, |
| 6934 | .setattr = nfs4_proc_setattr, |
| 6935 | .lookup = nfs4_proc_lookup, |
| 6936 | .access = nfs4_proc_access, |
| 6937 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6938 | .create = nfs4_proc_create, |
| 6939 | .remove = nfs4_proc_remove, |
| 6940 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6941 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6942 | .unlink_done = nfs4_proc_unlink_done, |
| 6943 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6944 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6945 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6946 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6947 | .link = nfs4_proc_link, |
| 6948 | .symlink = nfs4_proc_symlink, |
| 6949 | .mkdir = nfs4_proc_mkdir, |
| 6950 | .rmdir = nfs4_proc_remove, |
| 6951 | .readdir = nfs4_proc_readdir, |
| 6952 | .mknod = nfs4_proc_mknod, |
| 6953 | .statfs = nfs4_proc_statfs, |
| 6954 | .fsinfo = nfs4_proc_fsinfo, |
| 6955 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6956 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6957 | .decode_dirent = nfs4_decode_dirent, |
| 6958 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6959 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6960 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6961 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6962 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6963 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6964 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6965 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6966 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6967 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6968 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6969 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6970 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6971 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6972 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6973 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6974 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6975 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6976 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6977 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6978 | .create_server = nfs4_create_server, |
| 6979 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6980 | }; |
| 6981 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6982 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6983 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6984 | .list = nfs4_xattr_list_nfs4_acl, |
| 6985 | .get = nfs4_xattr_get_nfs4_acl, |
| 6986 | .set = nfs4_xattr_set_nfs4_acl, |
| 6987 | }; |
| 6988 | |
| 6989 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6990 | &nfs4_xattr_nfs4_acl_handler, |
| 6991 | NULL |
| 6992 | }; |
| 6993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6994 | /* |
| 6995 | * Local variables: |
| 6996 | * c-basic-offset: 8 |
| 6997 | * End: |
| 6998 | */ |