Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 76 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 77 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 78 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 80 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *, long *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 81 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 82 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 83 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 86 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 87 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 89 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 90 | struct rpc_cred *); |
| 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 92 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 93 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 96 | static inline struct nfs4_label * |
| 97 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 98 | struct iattr *sattr, struct nfs4_label *label) |
| 99 | { |
| 100 | int err; |
| 101 | |
| 102 | if (label == NULL) |
| 103 | return NULL; |
| 104 | |
| 105 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 106 | return NULL; |
| 107 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 108 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 109 | &dentry->d_name, (void **)&label->label, &label->len); |
| 110 | if (err == 0) |
| 111 | return label; |
| 112 | |
| 113 | return NULL; |
| 114 | } |
| 115 | static inline void |
| 116 | nfs4_label_release_security(struct nfs4_label *label) |
| 117 | { |
| 118 | if (label) |
| 119 | security_release_secctx(label->label, label->len); |
| 120 | } |
| 121 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 122 | { |
| 123 | if (label) |
| 124 | return server->attr_bitmask; |
| 125 | |
| 126 | return server->attr_bitmask_nl; |
| 127 | } |
| 128 | #else |
| 129 | static inline struct nfs4_label * |
| 130 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 131 | struct iattr *sattr, struct nfs4_label *l) |
| 132 | { return NULL; } |
| 133 | static inline void |
| 134 | nfs4_label_release_security(struct nfs4_label *label) |
| 135 | { return; } |
| 136 | static inline u32 * |
| 137 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 138 | { return server->attr_bitmask; } |
| 139 | #endif |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 142 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 144 | if (err >= -1000) |
| 145 | return err; |
| 146 | switch (err) { |
| 147 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 148 | case -NFS4ERR_LAYOUTTRYLATER: |
| 149 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 150 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 151 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 152 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 153 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 154 | case -NFS4ERR_BADOWNER: |
| 155 | case -NFS4ERR_BADNAME: |
| 156 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 157 | case -NFS4ERR_SHARE_DENIED: |
| 158 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 159 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 160 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 161 | case -NFS4ERR_FILE_OPEN: |
| 162 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 163 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 165 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 166 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 168 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* |
| 172 | * This is our standard bitmap for GETATTR requests. |
| 173 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 174 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | FATTR4_WORD0_TYPE |
| 176 | | FATTR4_WORD0_CHANGE |
| 177 | | FATTR4_WORD0_SIZE |
| 178 | | FATTR4_WORD0_FSID |
| 179 | | FATTR4_WORD0_FILEID, |
| 180 | FATTR4_WORD1_MODE |
| 181 | | FATTR4_WORD1_NUMLINKS |
| 182 | | FATTR4_WORD1_OWNER |
| 183 | | FATTR4_WORD1_OWNER_GROUP |
| 184 | | FATTR4_WORD1_RAWDEV |
| 185 | | FATTR4_WORD1_SPACE_USED |
| 186 | | FATTR4_WORD1_TIME_ACCESS |
| 187 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 188 | | FATTR4_WORD1_TIME_MODIFY, |
| 189 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 190 | FATTR4_WORD2_SECURITY_LABEL |
| 191 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 194 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 195 | FATTR4_WORD0_TYPE |
| 196 | | FATTR4_WORD0_CHANGE |
| 197 | | FATTR4_WORD0_SIZE |
| 198 | | FATTR4_WORD0_FSID |
| 199 | | FATTR4_WORD0_FILEID, |
| 200 | FATTR4_WORD1_MODE |
| 201 | | FATTR4_WORD1_NUMLINKS |
| 202 | | FATTR4_WORD1_OWNER |
| 203 | | FATTR4_WORD1_OWNER_GROUP |
| 204 | | FATTR4_WORD1_RAWDEV |
| 205 | | FATTR4_WORD1_SPACE_USED |
| 206 | | FATTR4_WORD1_TIME_ACCESS |
| 207 | | FATTR4_WORD1_TIME_METADATA |
| 208 | | FATTR4_WORD1_TIME_MODIFY, |
| 209 | FATTR4_WORD2_MDSTHRESHOLD |
| 210 | }; |
| 211 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 212 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 213 | FATTR4_WORD0_TYPE |
| 214 | | FATTR4_WORD0_CHANGE |
| 215 | | FATTR4_WORD0_FILEID, |
| 216 | }; |
| 217 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 218 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | FATTR4_WORD0_FILES_AVAIL |
| 220 | | FATTR4_WORD0_FILES_FREE |
| 221 | | FATTR4_WORD0_FILES_TOTAL, |
| 222 | FATTR4_WORD1_SPACE_AVAIL |
| 223 | | FATTR4_WORD1_SPACE_FREE |
| 224 | | FATTR4_WORD1_SPACE_TOTAL |
| 225 | }; |
| 226 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 227 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | FATTR4_WORD0_MAXLINK |
| 229 | | FATTR4_WORD0_MAXNAME, |
| 230 | 0 |
| 231 | }; |
| 232 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 233 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | | FATTR4_WORD0_MAXREAD |
| 235 | | FATTR4_WORD0_MAXWRITE |
| 236 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 237 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 238 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 239 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 242 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 243 | FATTR4_WORD0_TYPE |
| 244 | | FATTR4_WORD0_CHANGE |
| 245 | | FATTR4_WORD0_SIZE |
| 246 | | FATTR4_WORD0_FSID |
| 247 | | FATTR4_WORD0_FILEID |
| 248 | | FATTR4_WORD0_FS_LOCATIONS, |
| 249 | FATTR4_WORD1_MODE |
| 250 | | FATTR4_WORD1_NUMLINKS |
| 251 | | FATTR4_WORD1_OWNER |
| 252 | | FATTR4_WORD1_OWNER_GROUP |
| 253 | | FATTR4_WORD1_RAWDEV |
| 254 | | FATTR4_WORD1_SPACE_USED |
| 255 | | FATTR4_WORD1_TIME_ACCESS |
| 256 | | FATTR4_WORD1_TIME_METADATA |
| 257 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 258 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 259 | }; |
| 260 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 261 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | struct nfs4_readdir_arg *readdir) |
| 263 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 264 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 267 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | readdir->cookie = 0; |
| 273 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 274 | if (cookie == 2) |
| 275 | return; |
| 276 | |
| 277 | /* |
| 278 | * NFSv4 servers do not return entries for '.' and '..' |
| 279 | * Therefore, we fake these entries here. We let '.' |
| 280 | * have cookie 0 and '..' have cookie 1. Note that |
| 281 | * when talking to the server, we always send cookie 0 |
| 282 | * instead of 1 or 2. |
| 283 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 284 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | if (cookie == 0) { |
| 287 | *p++ = xdr_one; /* next */ |
| 288 | *p++ = xdr_zero; /* cookie, first word */ |
| 289 | *p++ = xdr_one; /* cookie, second word */ |
| 290 | *p++ = xdr_one; /* entry len */ |
| 291 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 292 | p++; |
| 293 | *p++ = xdr_one; /* bitmap length */ |
| 294 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 295 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 296 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | *p++ = xdr_one; /* next */ |
| 300 | *p++ = xdr_zero; /* cookie, first word */ |
| 301 | *p++ = xdr_two; /* cookie, second word */ |
| 302 | *p++ = xdr_two; /* entry len */ |
| 303 | memcpy(p, "..\0\0", 4); /* entry */ |
| 304 | p++; |
| 305 | *p++ = xdr_one; /* bitmap length */ |
| 306 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 307 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 308 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | readdir->pgbase = (char *)p - (char *)start; |
| 311 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 312 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 315 | static long nfs4_update_delay(long *timeout) |
| 316 | { |
| 317 | long ret; |
| 318 | if (!timeout) |
| 319 | return NFS4_POLL_RETRY_MAX; |
| 320 | if (*timeout <= 0) |
| 321 | *timeout = NFS4_POLL_RETRY_MIN; |
| 322 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 323 | *timeout = NFS4_POLL_RETRY_MAX; |
| 324 | ret = *timeout; |
| 325 | *timeout <<= 1; |
| 326 | return ret; |
| 327 | } |
| 328 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 329 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 330 | { |
| 331 | int res = 0; |
| 332 | |
| 333 | might_sleep(); |
| 334 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 335 | freezable_schedule_timeout_killable_unsafe( |
| 336 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 337 | if (fatal_signal_pending(current)) |
| 338 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 339 | return res; |
| 340 | } |
| 341 | |
| 342 | /* This is the error handling routine for processes that are allowed |
| 343 | * to sleep. |
| 344 | */ |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 345 | 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] | 346 | { |
| 347 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 348 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 349 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 350 | int ret = errorcode; |
| 351 | |
| 352 | exception->retry = 0; |
| 353 | switch(errorcode) { |
| 354 | case 0: |
| 355 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 356 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 357 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 358 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 359 | exception->retry = 1; |
| 360 | return 0; |
| 361 | } |
| 362 | if (state == NULL) |
| 363 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 364 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 365 | if (ret < 0) |
| 366 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 367 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 368 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 369 | case -NFS4ERR_ADMIN_REVOKED: |
| 370 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 371 | if (state == NULL) |
| 372 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 373 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 374 | if (ret < 0) |
| 375 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 376 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 377 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 378 | if (state != NULL) { |
| 379 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 380 | if (ret < 0) |
| 381 | break; |
| 382 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 383 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 384 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 385 | nfs4_schedule_lease_recovery(clp); |
| 386 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 387 | case -NFS4ERR_MOVED: |
| 388 | ret = nfs4_schedule_migration_recovery(server); |
| 389 | if (ret < 0) |
| 390 | break; |
| 391 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 392 | case -NFS4ERR_LEASE_MOVED: |
| 393 | nfs4_schedule_lease_moved_recovery(clp); |
| 394 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 395 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 396 | case -NFS4ERR_BADSESSION: |
| 397 | case -NFS4ERR_BADSLOT: |
| 398 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 399 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 400 | case -NFS4ERR_DEADSESSION: |
| 401 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 402 | case -NFS4ERR_SEQ_MISORDERED: |
| 403 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 404 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 405 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 406 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 407 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 408 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 409 | if (exception->timeout > HZ) { |
| 410 | /* We have retried a decent amount, time to |
| 411 | * fail |
| 412 | */ |
| 413 | ret = -EBUSY; |
| 414 | break; |
| 415 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 416 | case -NFS4ERR_GRACE: |
| 417 | case -NFS4ERR_DELAY: |
| 418 | ret = nfs4_delay(server->client, &exception->timeout); |
| 419 | if (ret != 0) |
| 420 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 421 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 422 | case -NFS4ERR_OLD_STATEID: |
| 423 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 424 | break; |
| 425 | case -NFS4ERR_BADOWNER: |
| 426 | /* The following works around a Linux server bug! */ |
| 427 | case -NFS4ERR_BADNAME: |
| 428 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 429 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 430 | exception->retry = 1; |
| 431 | printk(KERN_WARNING "NFS: v4 server %s " |
| 432 | "does not accept raw " |
| 433 | "uid/gids. " |
| 434 | "Reenabling the idmapper.\n", |
| 435 | server->nfs_client->cl_hostname); |
| 436 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | } |
| 438 | /* We failed to handle the error */ |
| 439 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 440 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 441 | ret = nfs4_wait_clnt_recover(clp); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 442 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 443 | return -EIO; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 444 | if (ret == 0) |
| 445 | exception->retry = 1; |
| 446 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 447 | } |
| 448 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 449 | /* |
| 450 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 451 | * or 'false' otherwise. |
| 452 | */ |
| 453 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 454 | { |
| 455 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 456 | |
| 457 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 458 | flavor == RPC_AUTH_GSS_KRB5P) |
| 459 | return true; |
| 460 | |
| 461 | return false; |
| 462 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 463 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 464 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | spin_lock(&clp->cl_lock); |
| 467 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 468 | clp->cl_last_renewal = timestamp; |
| 469 | spin_unlock(&clp->cl_lock); |
| 470 | } |
| 471 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 472 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 473 | { |
| 474 | do_renew_lease(server->nfs_client, timestamp); |
| 475 | } |
| 476 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 477 | struct nfs4_call_sync_data { |
| 478 | const struct nfs_server *seq_server; |
| 479 | struct nfs4_sequence_args *seq_args; |
| 480 | struct nfs4_sequence_res *seq_res; |
| 481 | }; |
| 482 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 483 | static void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 484 | struct nfs4_sequence_res *res, int cache_reply) |
| 485 | { |
| 486 | args->sa_slot = NULL; |
| 487 | args->sa_cache_this = cache_reply; |
| 488 | args->sa_privileged = 0; |
| 489 | |
| 490 | res->sr_slot = NULL; |
| 491 | } |
| 492 | |
| 493 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 494 | { |
| 495 | args->sa_privileged = 1; |
| 496 | } |
| 497 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 498 | static int nfs40_setup_sequence(const struct nfs_server *server, |
| 499 | struct nfs4_sequence_args *args, |
| 500 | struct nfs4_sequence_res *res, |
| 501 | struct rpc_task *task) |
| 502 | { |
| 503 | struct nfs4_slot_table *tbl = server->nfs_client->cl_slot_tbl; |
| 504 | struct nfs4_slot *slot; |
| 505 | |
| 506 | /* slot already allocated? */ |
| 507 | if (res->sr_slot != NULL) |
| 508 | goto out_start; |
| 509 | |
| 510 | spin_lock(&tbl->slot_tbl_lock); |
| 511 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 512 | goto out_sleep; |
| 513 | |
| 514 | slot = nfs4_alloc_slot(tbl); |
| 515 | if (IS_ERR(slot)) { |
| 516 | if (slot == ERR_PTR(-ENOMEM)) |
| 517 | task->tk_timeout = HZ >> 2; |
| 518 | goto out_sleep; |
| 519 | } |
| 520 | spin_unlock(&tbl->slot_tbl_lock); |
| 521 | |
| 522 | args->sa_slot = slot; |
| 523 | res->sr_slot = slot; |
| 524 | |
| 525 | out_start: |
| 526 | rpc_call_start(task); |
| 527 | return 0; |
| 528 | |
| 529 | out_sleep: |
| 530 | if (args->sa_privileged) |
| 531 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 532 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 533 | else |
| 534 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 535 | spin_unlock(&tbl->slot_tbl_lock); |
| 536 | return -EAGAIN; |
| 537 | } |
| 538 | |
| 539 | static int nfs40_sequence_done(struct rpc_task *task, |
| 540 | struct nfs4_sequence_res *res) |
| 541 | { |
| 542 | struct nfs4_slot *slot = res->sr_slot; |
| 543 | struct nfs4_slot_table *tbl; |
| 544 | |
Trond Myklebust | cab92c1 | 2014-01-29 12:12:15 -0500 | [diff] [blame] | 545 | if (slot == NULL) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 546 | goto out; |
| 547 | |
| 548 | tbl = slot->table; |
| 549 | spin_lock(&tbl->slot_tbl_lock); |
| 550 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 551 | nfs4_free_slot(tbl, slot); |
| 552 | spin_unlock(&tbl->slot_tbl_lock); |
| 553 | |
| 554 | res->sr_slot = NULL; |
| 555 | out: |
| 556 | return 1; |
| 557 | } |
| 558 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 559 | #if defined(CONFIG_NFS_V4_1) |
| 560 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 561 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 562 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 563 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 564 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 565 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 566 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 567 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 568 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 569 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 570 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 571 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 572 | /* Be nice to the server: try to ensure that the last transmitted |
| 573 | * value for highest_user_slotid <= target_highest_slotid |
| 574 | */ |
| 575 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 576 | send_new_highest_used_slotid = true; |
| 577 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 578 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 579 | send_new_highest_used_slotid = false; |
| 580 | goto out_unlock; |
| 581 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 582 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 583 | |
| 584 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 585 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 586 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 587 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 588 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 589 | if (send_new_highest_used_slotid) |
| 590 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 591 | } |
| 592 | |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 593 | 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] | 594 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 595 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 596 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 597 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 598 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 599 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 600 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 601 | if (slot == NULL) |
| 602 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 603 | /* don't increment the sequence number if the task wasn't sent */ |
| 604 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 605 | goto out; |
| 606 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 607 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 608 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 609 | if (slot->interrupted) { |
| 610 | slot->interrupted = 0; |
| 611 | interrupted = true; |
| 612 | } |
| 613 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 614 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 615 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 616 | switch (res->sr_status) { |
| 617 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 618 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 619 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 620 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 621 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 622 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 623 | if (res->sr_status_flags != 0) |
| 624 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 625 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 626 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 627 | case 1: |
| 628 | /* |
| 629 | * sr_status remains 1 if an RPC level error occurred. |
| 630 | * The server may or may not have processed the sequence |
| 631 | * operation.. |
| 632 | * Mark the slot as having hosted an interrupted RPC call. |
| 633 | */ |
| 634 | slot->interrupted = 1; |
| 635 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 636 | case -NFS4ERR_DELAY: |
| 637 | /* The server detected a resend of the RPC call and |
| 638 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 639 | * of RFC5661. |
| 640 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 641 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 642 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 643 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 644 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 645 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 646 | case -NFS4ERR_BADSLOT: |
| 647 | /* |
| 648 | * The slot id we used was probably retired. Try again |
| 649 | * using a different slot id. |
| 650 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 651 | goto retry_nowait; |
| 652 | case -NFS4ERR_SEQ_MISORDERED: |
| 653 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 654 | * Was the last operation on this sequence interrupted? |
| 655 | * If so, retry after bumping the sequence number. |
| 656 | */ |
| 657 | if (interrupted) { |
| 658 | ++slot->seq_nr; |
| 659 | goto retry_nowait; |
| 660 | } |
| 661 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 662 | * Could this slot have been previously retired? |
| 663 | * If so, then the server may be expecting seq_nr = 1! |
| 664 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 665 | if (slot->seq_nr != 1) { |
| 666 | slot->seq_nr = 1; |
| 667 | goto retry_nowait; |
| 668 | } |
| 669 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 670 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 671 | ++slot->seq_nr; |
| 672 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 673 | default: |
| 674 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 675 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 676 | } |
| 677 | out: |
| 678 | /* The session may be reset by one of the error handlers. */ |
| 679 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 680 | nfs41_sequence_free_slot(res); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 681 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 682 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 683 | retry_nowait: |
| 684 | if (rpc_restart_call_prepare(task)) { |
| 685 | task->tk_status = 0; |
| 686 | ret = 0; |
| 687 | } |
| 688 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 689 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 690 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 691 | goto out; |
| 692 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 693 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 694 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 695 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 696 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 697 | static int nfs4_sequence_done(struct rpc_task *task, |
| 698 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 699 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 700 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 701 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 702 | if (!res->sr_slot->table->session) |
| 703 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 704 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 705 | } |
| 706 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 707 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 708 | struct nfs4_sequence_args *args, |
| 709 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 710 | struct rpc_task *task) |
| 711 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 712 | struct nfs4_slot *slot; |
| 713 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 714 | |
| 715 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 716 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 717 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 718 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 719 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 720 | tbl = &session->fc_slot_table; |
| 721 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 722 | task->tk_timeout = 0; |
| 723 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 724 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 725 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 726 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 727 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 728 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 729 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 732 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 733 | if (IS_ERR(slot)) { |
| 734 | /* If out of memory, try again in 1/4 second */ |
| 735 | if (slot == ERR_PTR(-ENOMEM)) |
| 736 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 737 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 738 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 739 | } |
| 740 | spin_unlock(&tbl->slot_tbl_lock); |
| 741 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 742 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 743 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 744 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 745 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 746 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 747 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 748 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 749 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 750 | /* |
| 751 | * sr_status is only set in decode_sequence, and so will remain |
| 752 | * set to 1 if an rpc level failure occurs. |
| 753 | */ |
| 754 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 755 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 756 | out_success: |
| 757 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 758 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 759 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 760 | /* Privileged tasks are queued with top priority */ |
| 761 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 762 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 763 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 764 | else |
| 765 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 766 | spin_unlock(&tbl->slot_tbl_lock); |
| 767 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 768 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 769 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 770 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 771 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 772 | struct nfs4_sequence_args *args, |
| 773 | struct nfs4_sequence_res *res, |
| 774 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 775 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 776 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 777 | int ret = 0; |
| 778 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 779 | if (!session) |
| 780 | return nfs40_setup_sequence(server, args, res, task); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 781 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 782 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 783 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 784 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 785 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 786 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 787 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 788 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 789 | return ret; |
| 790 | } |
| 791 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 792 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 793 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 794 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 795 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 796 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 797 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 798 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 799 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 800 | } |
| 801 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 802 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 803 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 804 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 805 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 806 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 807 | } |
| 808 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 809 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 810 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 811 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 812 | }; |
| 813 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 814 | #else /* !CONFIG_NFS_V4_1 */ |
| 815 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 816 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 817 | struct nfs4_sequence_args *args, |
| 818 | struct nfs4_sequence_res *res, |
| 819 | struct rpc_task *task) |
| 820 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 821 | return nfs40_setup_sequence(server, args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 822 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 823 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 824 | static int nfs4_sequence_done(struct rpc_task *task, |
| 825 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 826 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 827 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 828 | } |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 829 | |
| 830 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 831 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 832 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 833 | { |
| 834 | struct nfs4_call_sync_data *data = calldata; |
| 835 | nfs4_setup_sequence(data->seq_server, |
| 836 | data->seq_args, data->seq_res, task); |
| 837 | } |
| 838 | |
| 839 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 840 | { |
| 841 | struct nfs4_call_sync_data *data = calldata; |
| 842 | nfs4_sequence_done(task, data->seq_res); |
| 843 | } |
| 844 | |
| 845 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 846 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 847 | .rpc_call_done = nfs40_call_sync_done, |
| 848 | }; |
| 849 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 850 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 851 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 852 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 853 | struct nfs4_sequence_args *args, |
| 854 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 855 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 856 | int ret; |
| 857 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 858 | struct nfs_client *clp = server->nfs_client; |
| 859 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 860 | .seq_server = server, |
| 861 | .seq_args = args, |
| 862 | .seq_res = res, |
| 863 | }; |
| 864 | struct rpc_task_setup task_setup = { |
| 865 | .rpc_client = clnt, |
| 866 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 867 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 868 | .callback_data = &data |
| 869 | }; |
| 870 | |
| 871 | task = rpc_run_task(&task_setup); |
| 872 | if (IS_ERR(task)) |
| 873 | ret = PTR_ERR(task); |
| 874 | else { |
| 875 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 876 | rpc_put_task(task); |
| 877 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 878 | return ret; |
| 879 | } |
| 880 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 881 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 882 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 883 | struct rpc_message *msg, |
| 884 | struct nfs4_sequence_args *args, |
| 885 | struct nfs4_sequence_res *res, |
| 886 | int cache_reply) |
| 887 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 888 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 889 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
| 892 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 893 | { |
| 894 | struct nfs_inode *nfsi = NFS_I(dir); |
| 895 | |
| 896 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 897 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 898 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 900 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 901 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | spin_unlock(&dir->i_lock); |
| 903 | } |
| 904 | |
| 905 | struct nfs4_opendata { |
| 906 | struct kref kref; |
| 907 | struct nfs_openargs o_arg; |
| 908 | struct nfs_openres o_res; |
| 909 | struct nfs_open_confirmargs c_arg; |
| 910 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 911 | struct nfs4_string owner_name; |
| 912 | struct nfs4_string group_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 914 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 916 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | struct nfs4_state_owner *owner; |
| 918 | struct nfs4_state *state; |
| 919 | struct iattr attrs; |
| 920 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 921 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 922 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 923 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 924 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | int cancelled; |
| 926 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 927 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 928 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 929 | int err, struct nfs4_exception *exception) |
| 930 | { |
| 931 | if (err != -EINVAL) |
| 932 | return false; |
| 933 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 934 | return false; |
| 935 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 936 | exception->retry = 1; |
| 937 | return true; |
| 938 | } |
| 939 | |
| 940 | static enum open_claim_type4 |
| 941 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 942 | enum open_claim_type4 claim) |
| 943 | { |
| 944 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 945 | return claim; |
| 946 | switch (claim) { |
| 947 | default: |
| 948 | return claim; |
| 949 | case NFS4_OPEN_CLAIM_FH: |
| 950 | return NFS4_OPEN_CLAIM_NULL; |
| 951 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 952 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 953 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 954 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 955 | } |
| 956 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
| 958 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 959 | { |
| 960 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 961 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 962 | p->o_res.seqid = p->o_arg.seqid; |
| 963 | p->c_res.seqid = p->c_arg.seqid; |
| 964 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 965 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 966 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 967 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 970 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 971 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 972 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 973 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 974 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 975 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 976 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 977 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 978 | struct inode *dir = parent->d_inode; |
| 979 | struct nfs_server *server = NFS_SERVER(dir); |
| 980 | struct nfs4_opendata *p; |
| 981 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 982 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 983 | if (p == NULL) |
| 984 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 985 | |
| 986 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 987 | if (IS_ERR(p->f_label)) |
| 988 | goto err_free_p; |
| 989 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 990 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 991 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 992 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 993 | nfs_sb_active(dentry->d_sb); |
| 994 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 995 | p->dir = parent; |
| 996 | p->owner = sp; |
| 997 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | p->o_arg.open_flags = flags; |
| 999 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1000 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1001 | * will return permission denied for all bits until close */ |
| 1002 | if (!(flags & O_EXCL)) { |
| 1003 | /* ask server to check for all possible rights as results |
| 1004 | * are cached */ |
| 1005 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1006 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1007 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1008 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1009 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1010 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1011 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1012 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1013 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1014 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1015 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1016 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1017 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1018 | case NFS4_OPEN_CLAIM_NULL: |
| 1019 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1020 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1021 | p->o_arg.fh = NFS_FH(dir); |
| 1022 | break; |
| 1023 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1024 | case NFS4_OPEN_CLAIM_FH: |
| 1025 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1026 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1027 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 1028 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1029 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1030 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1031 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1032 | p->o_arg.u.attrs = &p->attrs; |
| 1033 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1034 | |
| 1035 | verf[0] = jiffies; |
| 1036 | verf[1] = current->pid; |
| 1037 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1038 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1039 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1040 | p->c_arg.fh = &p->o_res.fh; |
| 1041 | p->c_arg.stateid = &p->o_res.stateid; |
| 1042 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1043 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1044 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1045 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1046 | |
| 1047 | err_free_label: |
| 1048 | nfs4_label_free(p->f_label); |
| 1049 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1050 | kfree(p); |
| 1051 | err: |
| 1052 | dput(parent); |
| 1053 | return NULL; |
| 1054 | } |
| 1055 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1056 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1057 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1058 | struct nfs4_opendata *p = container_of(kref, |
| 1059 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1060 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1061 | |
| 1062 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1063 | if (p->state != NULL) |
| 1064 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1065 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1066 | |
| 1067 | nfs4_label_free(p->f_label); |
| 1068 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1069 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1070 | dput(p->dentry); |
| 1071 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1072 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1073 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1074 | kfree(p); |
| 1075 | } |
| 1076 | |
| 1077 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1078 | { |
| 1079 | if (p != NULL) |
| 1080 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1083 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1084 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1085 | int ret; |
| 1086 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1087 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1088 | return ret; |
| 1089 | } |
| 1090 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1091 | 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] | 1092 | { |
| 1093 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1094 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1095 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1096 | goto out; |
| 1097 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1098 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1099 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1100 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1101 | break; |
| 1102 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1103 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1104 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1105 | break; |
| 1106 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1107 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1108 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1109 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1110 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1111 | return ret; |
| 1112 | } |
| 1113 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1114 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1115 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1116 | if (delegation == NULL) |
| 1117 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1118 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1119 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1120 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1121 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1122 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1123 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1124 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1125 | return 1; |
| 1126 | } |
| 1127 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1128 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1129 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1130 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1131 | case FMODE_WRITE: |
| 1132 | state->n_wronly++; |
| 1133 | break; |
| 1134 | case FMODE_READ: |
| 1135 | state->n_rdonly++; |
| 1136 | break; |
| 1137 | case FMODE_READ|FMODE_WRITE: |
| 1138 | state->n_rdwr++; |
| 1139 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1140 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1141 | } |
| 1142 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1143 | static void nfs_test_and_clear_all_open_stateid(struct nfs4_state *state) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1144 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1145 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1146 | bool need_recover = false; |
| 1147 | |
| 1148 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1149 | need_recover = true; |
| 1150 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1151 | need_recover = true; |
| 1152 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1153 | need_recover = true; |
| 1154 | if (need_recover) |
| 1155 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1156 | } |
| 1157 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1158 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1159 | nfs4_stateid *stateid) |
| 1160 | { |
| 1161 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1162 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1163 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1164 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1165 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1166 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1167 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1168 | return true; |
| 1169 | return false; |
| 1170 | } |
| 1171 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1172 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1173 | nfs4_stateid *stateid, fmode_t fmode) |
| 1174 | { |
| 1175 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1176 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1177 | case FMODE_WRITE: |
| 1178 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1179 | break; |
| 1180 | case FMODE_READ: |
| 1181 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1182 | break; |
| 1183 | case 0: |
| 1184 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1185 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1186 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1187 | } |
| 1188 | if (stateid == NULL) |
| 1189 | return; |
| 1190 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1191 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1192 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1193 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1194 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | static void nfs_clear_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1198 | { |
| 1199 | write_seqlock(&state->seqlock); |
| 1200 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
| 1201 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1202 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1203 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1204 | } |
| 1205 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1206 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1207 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1208 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1209 | case FMODE_READ: |
| 1210 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1211 | break; |
| 1212 | case FMODE_WRITE: |
| 1213 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1214 | break; |
| 1215 | case FMODE_READ|FMODE_WRITE: |
| 1216 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1217 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1218 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1219 | return; |
| 1220 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1221 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1222 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1223 | } |
| 1224 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1225 | 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] | 1226 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1227 | /* |
| 1228 | * Protect the call to nfs4_state_set_mode_locked and |
| 1229 | * serialise the stateid update |
| 1230 | */ |
| 1231 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1232 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1233 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1234 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1235 | } |
| 1236 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1237 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1238 | write_sequnlock(&state->seqlock); |
| 1239 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1240 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1241 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1244 | 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] | 1245 | { |
| 1246 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1247 | struct nfs_delegation *deleg_cur; |
| 1248 | int ret = 0; |
| 1249 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1250 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1251 | |
| 1252 | rcu_read_lock(); |
| 1253 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1254 | if (deleg_cur == NULL) |
| 1255 | goto no_delegation; |
| 1256 | |
| 1257 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1258 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1259 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1260 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1261 | goto no_delegation_unlock; |
| 1262 | |
| 1263 | if (delegation == NULL) |
| 1264 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1265 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1266 | goto no_delegation_unlock; |
| 1267 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1268 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1269 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1270 | ret = 1; |
| 1271 | no_delegation_unlock: |
| 1272 | spin_unlock(&deleg_cur->lock); |
| 1273 | no_delegation: |
| 1274 | rcu_read_unlock(); |
| 1275 | |
| 1276 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1277 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1278 | ret = 1; |
| 1279 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1280 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1281 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1282 | |
| 1283 | return ret; |
| 1284 | } |
| 1285 | |
| 1286 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1287 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1288 | { |
| 1289 | struct nfs_delegation *delegation; |
| 1290 | |
| 1291 | rcu_read_lock(); |
| 1292 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1293 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1294 | rcu_read_unlock(); |
| 1295 | return; |
| 1296 | } |
| 1297 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1298 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1301 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1302 | { |
| 1303 | struct nfs4_state *state = opendata->state; |
| 1304 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1305 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1306 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1307 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1308 | nfs4_stateid stateid; |
| 1309 | int ret = -EAGAIN; |
| 1310 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1311 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1312 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1313 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1314 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1315 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1316 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1317 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1318 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1319 | rcu_read_lock(); |
| 1320 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1321 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1322 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1323 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1324 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1325 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1326 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1327 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1328 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1329 | if (!opendata->is_recover) { |
| 1330 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1331 | if (ret != 0) |
| 1332 | goto out; |
| 1333 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1334 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1335 | |
| 1336 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1337 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1338 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1339 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1340 | out: |
| 1341 | return ERR_PTR(ret); |
| 1342 | out_return_state: |
| 1343 | atomic_inc(&state->count); |
| 1344 | return state; |
| 1345 | } |
| 1346 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1347 | static void |
| 1348 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1349 | { |
| 1350 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1351 | struct nfs_delegation *delegation; |
| 1352 | int delegation_flags = 0; |
| 1353 | |
| 1354 | rcu_read_lock(); |
| 1355 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1356 | if (delegation) |
| 1357 | delegation_flags = delegation->flags; |
| 1358 | rcu_read_unlock(); |
| 1359 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1360 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1361 | "returning a delegation for " |
| 1362 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1363 | clp->cl_hostname); |
| 1364 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1365 | nfs_inode_set_delegation(state->inode, |
| 1366 | data->owner->so_cred, |
| 1367 | &data->o_res); |
| 1368 | else |
| 1369 | nfs_inode_reclaim_delegation(state->inode, |
| 1370 | data->owner->so_cred, |
| 1371 | &data->o_res); |
| 1372 | } |
| 1373 | |
| 1374 | /* |
| 1375 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1376 | * and update the nfs4_state. |
| 1377 | */ |
| 1378 | static struct nfs4_state * |
| 1379 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1380 | { |
| 1381 | struct inode *inode = data->state->inode; |
| 1382 | struct nfs4_state *state = data->state; |
| 1383 | int ret; |
| 1384 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1385 | if (!data->rpc_done) { |
| 1386 | if (data->rpc_status) { |
| 1387 | ret = data->rpc_status; |
| 1388 | goto err; |
| 1389 | } |
| 1390 | /* cached opens have already been processed */ |
| 1391 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1394 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1395 | if (ret) |
| 1396 | goto err; |
| 1397 | |
| 1398 | if (data->o_res.delegation_type != 0) |
| 1399 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1400 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1401 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1402 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1403 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1404 | |
| 1405 | return state; |
| 1406 | err: |
| 1407 | return ERR_PTR(ret); |
| 1408 | |
| 1409 | } |
| 1410 | |
| 1411 | static struct nfs4_state * |
| 1412 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1413 | { |
| 1414 | struct inode *inode; |
| 1415 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1416 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1417 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1418 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1419 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1420 | goto out; |
| 1421 | } |
| 1422 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1423 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1424 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1425 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1426 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr, data->f_label); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1427 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1428 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1429 | goto err; |
| 1430 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1431 | state = nfs4_get_open_state(inode, data->owner); |
| 1432 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1433 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1434 | if (data->o_res.delegation_type != 0) |
| 1435 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1436 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1437 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1438 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1439 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1440 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1441 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1442 | err_put_inode: |
| 1443 | iput(inode); |
| 1444 | err: |
| 1445 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1448 | static struct nfs4_state * |
| 1449 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1450 | { |
| 1451 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1452 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1453 | return _nfs4_opendata_to_nfs4_state(data); |
| 1454 | } |
| 1455 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1456 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1457 | { |
| 1458 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1459 | struct nfs_open_context *ctx; |
| 1460 | |
| 1461 | spin_lock(&state->inode->i_lock); |
| 1462 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1463 | if (ctx->state != state) |
| 1464 | continue; |
| 1465 | get_nfs_open_context(ctx); |
| 1466 | spin_unlock(&state->inode->i_lock); |
| 1467 | return ctx; |
| 1468 | } |
| 1469 | spin_unlock(&state->inode->i_lock); |
| 1470 | return ERR_PTR(-ENOENT); |
| 1471 | } |
| 1472 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1473 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1474 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1475 | { |
| 1476 | struct nfs4_opendata *opendata; |
| 1477 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1478 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1479 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1480 | if (opendata == NULL) |
| 1481 | return ERR_PTR(-ENOMEM); |
| 1482 | opendata->state = state; |
| 1483 | atomic_inc(&state->count); |
| 1484 | return opendata; |
| 1485 | } |
| 1486 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1487 | 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] | 1488 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1489 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1490 | int ret; |
| 1491 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1492 | opendata->o_arg.open_flags = 0; |
| 1493 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1494 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1495 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1496 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1497 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1498 | if (ret != 0) |
| 1499 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1500 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1501 | if (IS_ERR(newstate)) |
| 1502 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1503 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1504 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1505 | return 0; |
| 1506 | } |
| 1507 | |
| 1508 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1509 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1510 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1511 | int ret; |
| 1512 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1513 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1514 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1515 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1516 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1517 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1518 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1519 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1520 | smp_rmb(); |
| 1521 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1522 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1523 | if (ret != 0) |
| 1524 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1525 | if (newstate != state) |
| 1526 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1527 | } |
| 1528 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1529 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1530 | if (ret != 0) |
| 1531 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1532 | if (newstate != state) |
| 1533 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1534 | } |
| 1535 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1536 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1537 | if (ret != 0) |
| 1538 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1539 | if (newstate != state) |
| 1540 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1541 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1542 | /* |
| 1543 | * We may have performed cached opens for all three recoveries. |
| 1544 | * Check if we need to update the current stateid. |
| 1545 | */ |
| 1546 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1547 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1548 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1549 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1550 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1551 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1552 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1553 | return 0; |
| 1554 | } |
| 1555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | /* |
| 1557 | * OPEN_RECLAIM: |
| 1558 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1560 | 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] | 1561 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1562 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1563 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1564 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | int status; |
| 1566 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1567 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1568 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1569 | if (IS_ERR(opendata)) |
| 1570 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1571 | rcu_read_lock(); |
| 1572 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1573 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1574 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1575 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1576 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1577 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1578 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | return status; |
| 1580 | } |
| 1581 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1582 | 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] | 1583 | { |
| 1584 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1585 | struct nfs4_exception exception = { }; |
| 1586 | int err; |
| 1587 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1588 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1589 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1590 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1591 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1592 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1593 | break; |
| 1594 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | } while (exception.retry); |
| 1596 | return err; |
| 1597 | } |
| 1598 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1599 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1600 | { |
| 1601 | struct nfs_open_context *ctx; |
| 1602 | int ret; |
| 1603 | |
| 1604 | ctx = nfs4_state_find_open_context(state); |
| 1605 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1606 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1607 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1608 | put_nfs_open_context(ctx); |
| 1609 | return ret; |
| 1610 | } |
| 1611 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1612 | 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] | 1613 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1614 | switch (err) { |
| 1615 | default: |
| 1616 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1617 | "%d.\n", __func__, err); |
| 1618 | case 0: |
| 1619 | case -ENOENT: |
| 1620 | case -ESTALE: |
| 1621 | break; |
| 1622 | case -NFS4ERR_BADSESSION: |
| 1623 | case -NFS4ERR_BADSLOT: |
| 1624 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1625 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1626 | case -NFS4ERR_DEADSESSION: |
| 1627 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1628 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1629 | return -EAGAIN; |
| 1630 | case -NFS4ERR_STALE_CLIENTID: |
| 1631 | case -NFS4ERR_STALE_STATEID: |
| 1632 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1633 | case -NFS4ERR_EXPIRED: |
| 1634 | /* Don't recall a delegation if it was lost */ |
| 1635 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1636 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1637 | case -NFS4ERR_MOVED: |
| 1638 | nfs4_schedule_migration_recovery(server); |
| 1639 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1640 | case -NFS4ERR_LEASE_MOVED: |
| 1641 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1642 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1643 | case -NFS4ERR_DELEG_REVOKED: |
| 1644 | case -NFS4ERR_ADMIN_REVOKED: |
| 1645 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1646 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1647 | nfs_inode_find_state_and_recover(state->inode, |
| 1648 | stateid); |
| 1649 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1650 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1651 | case -NFS4ERR_DELAY: |
| 1652 | case -NFS4ERR_GRACE: |
| 1653 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1654 | ssleep(1); |
| 1655 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1656 | case -ENOMEM: |
| 1657 | case -NFS4ERR_DENIED: |
| 1658 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1659 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | return err; |
| 1662 | } |
| 1663 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1664 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1665 | { |
| 1666 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1667 | struct nfs4_opendata *opendata; |
| 1668 | int err; |
| 1669 | |
| 1670 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1671 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1672 | if (IS_ERR(opendata)) |
| 1673 | return PTR_ERR(opendata); |
| 1674 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1675 | err = nfs4_open_recover(opendata, state); |
| 1676 | nfs4_opendata_put(opendata); |
| 1677 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1678 | } |
| 1679 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1680 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1681 | { |
| 1682 | struct nfs4_opendata *data = calldata; |
| 1683 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1684 | nfs40_setup_sequence(data->o_arg.server, &data->c_arg.seq_args, |
| 1685 | &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1686 | } |
| 1687 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1688 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1689 | { |
| 1690 | struct nfs4_opendata *data = calldata; |
| 1691 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1692 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1693 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1694 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1695 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1696 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1697 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1698 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1699 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1700 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | static void nfs4_open_confirm_release(void *calldata) |
| 1704 | { |
| 1705 | struct nfs4_opendata *data = calldata; |
| 1706 | struct nfs4_state *state = NULL; |
| 1707 | |
| 1708 | /* If this request hasn't been cancelled, do nothing */ |
| 1709 | if (data->cancelled == 0) |
| 1710 | goto out_free; |
| 1711 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1712 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1713 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1714 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1715 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1716 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1717 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1718 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1722 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1723 | .rpc_call_done = nfs4_open_confirm_done, |
| 1724 | .rpc_release = nfs4_open_confirm_release, |
| 1725 | }; |
| 1726 | |
| 1727 | /* |
| 1728 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1729 | */ |
| 1730 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1731 | { |
| 1732 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1733 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1734 | struct rpc_message msg = { |
| 1735 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1736 | .rpc_argp = &data->c_arg, |
| 1737 | .rpc_resp = &data->c_res, |
| 1738 | .rpc_cred = data->owner->so_cred, |
| 1739 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1740 | struct rpc_task_setup task_setup_data = { |
| 1741 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1742 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1743 | .callback_ops = &nfs4_open_confirm_ops, |
| 1744 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1745 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1746 | .flags = RPC_TASK_ASYNC, |
| 1747 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | int status; |
| 1749 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1750 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1751 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1752 | data->rpc_done = 0; |
| 1753 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1754 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1755 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1756 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1757 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1758 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1759 | if (status != 0) { |
| 1760 | data->cancelled = 1; |
| 1761 | smp_wmb(); |
| 1762 | } else |
| 1763 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1764 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | return status; |
| 1766 | } |
| 1767 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1768 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1770 | struct nfs4_opendata *data = calldata; |
| 1771 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1772 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1773 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1774 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1775 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1776 | /* |
| 1777 | * Check if we still need to send an OPEN call, or if we can use |
| 1778 | * a delegation instead. |
| 1779 | */ |
| 1780 | if (data->state != NULL) { |
| 1781 | struct nfs_delegation *delegation; |
| 1782 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1783 | 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] | 1784 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1785 | rcu_read_lock(); |
| 1786 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1787 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1788 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1789 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1790 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1791 | rcu_read_unlock(); |
| 1792 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1793 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1794 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1795 | switch (data->o_arg.claim) { |
| 1796 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1797 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1798 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1799 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1800 | case NFS4_OPEN_CLAIM_FH: |
| 1801 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1802 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1803 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1804 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1805 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1806 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1807 | &data->o_res.seq_res, |
| 1808 | task) != 0) |
| 1809 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1810 | |
| 1811 | /* Set the create mode (note dependency on the session type) */ |
| 1812 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1813 | if (data->o_arg.open_flags & O_EXCL) { |
| 1814 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1815 | if (nfs4_has_persistent_session(clp)) |
| 1816 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1817 | else if (clp->cl_mvops->minor_version > 0) |
| 1818 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1819 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1820 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1821 | unlock_no_action: |
| 1822 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1823 | out_no_action: |
| 1824 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1825 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1826 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1829 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1830 | { |
| 1831 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1833 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1834 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1835 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1836 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1837 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1838 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1839 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1840 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1841 | case S_IFREG: |
| 1842 | break; |
| 1843 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1844 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1845 | break; |
| 1846 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1847 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1848 | break; |
| 1849 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1850 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1851 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1852 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1853 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1854 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1855 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1856 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1857 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1858 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1859 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1860 | static void nfs4_open_release(void *calldata) |
| 1861 | { |
| 1862 | struct nfs4_opendata *data = calldata; |
| 1863 | struct nfs4_state *state = NULL; |
| 1864 | |
| 1865 | /* If this request hasn't been cancelled, do nothing */ |
| 1866 | if (data->cancelled == 0) |
| 1867 | goto out_free; |
| 1868 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1869 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1870 | goto out_free; |
| 1871 | /* In case we need an open_confirm, no cleanup! */ |
| 1872 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1873 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1874 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1875 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1876 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1877 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1878 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1882 | .rpc_call_prepare = nfs4_open_prepare, |
| 1883 | .rpc_call_done = nfs4_open_done, |
| 1884 | .rpc_release = nfs4_open_release, |
| 1885 | }; |
| 1886 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1887 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1888 | { |
| 1889 | struct inode *dir = data->dir->d_inode; |
| 1890 | struct nfs_server *server = NFS_SERVER(dir); |
| 1891 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1892 | struct nfs_openres *o_res = &data->o_res; |
| 1893 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1894 | struct rpc_message msg = { |
| 1895 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1896 | .rpc_argp = o_arg, |
| 1897 | .rpc_resp = o_res, |
| 1898 | .rpc_cred = data->owner->so_cred, |
| 1899 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1900 | struct rpc_task_setup task_setup_data = { |
| 1901 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1902 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1903 | .callback_ops = &nfs4_open_ops, |
| 1904 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1905 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1906 | .flags = RPC_TASK_ASYNC, |
| 1907 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1908 | int status; |
| 1909 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1910 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1911 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1912 | data->rpc_done = 0; |
| 1913 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1914 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1915 | data->is_recover = 0; |
| 1916 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1917 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1918 | data->is_recover = 1; |
| 1919 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1920 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1921 | if (IS_ERR(task)) |
| 1922 | return PTR_ERR(task); |
| 1923 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1924 | if (status != 0) { |
| 1925 | data->cancelled = 1; |
| 1926 | smp_wmb(); |
| 1927 | } else |
| 1928 | status = data->rpc_status; |
| 1929 | rpc_put_task(task); |
| 1930 | |
| 1931 | return status; |
| 1932 | } |
| 1933 | |
| 1934 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1935 | { |
| 1936 | struct inode *dir = data->dir->d_inode; |
| 1937 | struct nfs_openres *o_res = &data->o_res; |
| 1938 | int status; |
| 1939 | |
| 1940 | status = nfs4_run_open_task(data, 1); |
| 1941 | if (status != 0 || !data->rpc_done) |
| 1942 | return status; |
| 1943 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1944 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1945 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1946 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1947 | status = _nfs4_proc_open_confirm(data); |
| 1948 | if (status != 0) |
| 1949 | return status; |
| 1950 | } |
| 1951 | |
| 1952 | return status; |
| 1953 | } |
| 1954 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1955 | /* |
| 1956 | * Additional permission checks in order to distinguish between an |
| 1957 | * open for read, and an open for execute. This works around the |
| 1958 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 1959 | * the same. |
| 1960 | * Note that in the non-execute case, we want to turn off permission |
| 1961 | * checking if we just created a new file (POSIX open() semantics). |
| 1962 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1963 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1964 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1965 | struct nfs4_state *state, fmode_t fmode, |
| 1966 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1967 | { |
| 1968 | struct nfs_access_entry cache; |
| 1969 | u32 mask; |
| 1970 | |
| 1971 | /* access call failed or for some reason the server doesn't |
| 1972 | * support any access modes -- defer access call until later */ |
| 1973 | if (opendata->o_res.access_supported == 0) |
| 1974 | return 0; |
| 1975 | |
| 1976 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1977 | /* |
| 1978 | * Use openflags to check for exec, because fmode won't |
| 1979 | * always have FMODE_EXEC set when file open for exec. |
| 1980 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1981 | if (openflags & __FMODE_EXEC) { |
| 1982 | /* ONLY check for exec rights */ |
| 1983 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1984 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1985 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1986 | |
| 1987 | cache.cred = cred; |
| 1988 | cache.jiffies = jiffies; |
| 1989 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1990 | nfs_access_add_cache(state->inode, &cache); |
| 1991 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1992 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1993 | return 0; |
| 1994 | |
| 1995 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1996 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1997 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1998 | } |
| 1999 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2000 | /* |
| 2001 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2002 | */ |
| 2003 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2004 | { |
| 2005 | struct inode *dir = data->dir->d_inode; |
| 2006 | struct nfs_server *server = NFS_SERVER(dir); |
| 2007 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2008 | struct nfs_openres *o_res = &data->o_res; |
| 2009 | int status; |
| 2010 | |
| 2011 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2012 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2013 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2014 | if (status != 0) { |
| 2015 | if (status == -NFS4ERR_BADNAME && |
| 2016 | !(o_arg->open_flags & O_CREAT)) |
| 2017 | return -ENOENT; |
| 2018 | return status; |
| 2019 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2020 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2021 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2022 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2023 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2024 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2025 | if (o_arg->open_flags & O_EXCL) |
| 2026 | data->file_created = 1; |
| 2027 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2028 | data->file_created = 1; |
| 2029 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2030 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2031 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2033 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2035 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2038 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2039 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2042 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2043 | { |
| 2044 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2045 | } |
| 2046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | /* |
| 2048 | * OPEN_EXPIRED: |
| 2049 | * reclaim state on the server after a network partition. |
| 2050 | * Assumes caller holds the appropriate lock |
| 2051 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2052 | 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] | 2053 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2054 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2055 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2057 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2058 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2059 | if (IS_ERR(opendata)) |
| 2060 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2061 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2062 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2063 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2064 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2065 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2068 | 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] | 2069 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2070 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2071 | struct nfs4_exception exception = { }; |
| 2072 | int err; |
| 2073 | |
| 2074 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2075 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2076 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2077 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2078 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2079 | switch (err) { |
| 2080 | default: |
| 2081 | goto out; |
| 2082 | case -NFS4ERR_GRACE: |
| 2083 | case -NFS4ERR_DELAY: |
| 2084 | nfs4_handle_exception(server, err, &exception); |
| 2085 | err = 0; |
| 2086 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2087 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2088 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2089 | return err; |
| 2090 | } |
| 2091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2093 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2095 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2097 | ctx = nfs4_state_find_open_context(state); |
| 2098 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2099 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2100 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2101 | put_nfs_open_context(ctx); |
| 2102 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2105 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2106 | { |
| 2107 | nfs_remove_bad_delegation(state->inode); |
| 2108 | write_seqlock(&state->seqlock); |
| 2109 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2110 | write_sequnlock(&state->seqlock); |
| 2111 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2112 | } |
| 2113 | |
| 2114 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2115 | { |
| 2116 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2117 | nfs_finish_clear_delegation_stateid(state); |
| 2118 | } |
| 2119 | |
| 2120 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2121 | { |
| 2122 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2123 | nfs40_clear_delegation_stateid(state); |
| 2124 | return nfs4_open_expired(sp, state); |
| 2125 | } |
| 2126 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2127 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2128 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2129 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2130 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2131 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2132 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2133 | struct rpc_cred *cred; |
| 2134 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2135 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2136 | /* Get the delegation credential for use by test/free_stateid */ |
| 2137 | rcu_read_lock(); |
| 2138 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2139 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2140 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2141 | return; |
| 2142 | } |
| 2143 | |
| 2144 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2145 | cred = get_rpccred(delegation->cred); |
| 2146 | rcu_read_unlock(); |
| 2147 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2148 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2149 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2150 | if (status != NFS_OK) { |
| 2151 | /* Free the stateid unless the server explicitly |
| 2152 | * informs us the stateid is unrecognized. */ |
| 2153 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2154 | nfs41_free_stateid(server, &stateid, cred); |
| 2155 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2156 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2157 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2158 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | /** |
| 2162 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2163 | * |
| 2164 | * @state: NFSv4 state for an inode |
| 2165 | * |
| 2166 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2167 | * Otherwise a negative NFS4ERR value is returned. |
| 2168 | */ |
| 2169 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2170 | { |
| 2171 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2172 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2173 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2174 | int status; |
| 2175 | |
| 2176 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2177 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2178 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2179 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2180 | return -NFS4ERR_BAD_STATEID; |
| 2181 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2182 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2183 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2184 | if (status != NFS_OK) { |
| 2185 | /* Free the stateid unless the server explicitly |
| 2186 | * informs us the stateid is unrecognized. */ |
| 2187 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2188 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2189 | |
| 2190 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2191 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2192 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2193 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2194 | } |
| 2195 | return status; |
| 2196 | } |
| 2197 | |
| 2198 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2199 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2200 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2201 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2202 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2203 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2204 | if (status != NFS_OK) |
| 2205 | status = nfs4_open_expired(sp, state); |
| 2206 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2207 | } |
| 2208 | #endif |
| 2209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2211 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2212 | * fields corresponding to attributes that were used to store the verifier. |
| 2213 | * Make sure we clobber those fields in the later setattr call |
| 2214 | */ |
| 2215 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2216 | { |
| 2217 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2218 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2219 | sattr->ia_valid |= ATTR_ATIME; |
| 2220 | |
| 2221 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2222 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2223 | sattr->ia_valid |= ATTR_MTIME; |
| 2224 | } |
| 2225 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2226 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2227 | fmode_t fmode, |
| 2228 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2229 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2230 | { |
| 2231 | struct nfs4_state_owner *sp = opendata->owner; |
| 2232 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2233 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2234 | struct nfs4_state *state; |
| 2235 | unsigned int seq; |
| 2236 | int ret; |
| 2237 | |
| 2238 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2239 | |
| 2240 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2241 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2242 | goto out; |
| 2243 | |
| 2244 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2245 | ret = PTR_ERR(state); |
| 2246 | if (IS_ERR(state)) |
| 2247 | goto out; |
| 2248 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2249 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2250 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2251 | dentry = opendata->dentry; |
| 2252 | if (dentry->d_inode == NULL) { |
| 2253 | /* FIXME: Is this d_drop() ever needed? */ |
| 2254 | d_drop(dentry); |
| 2255 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2256 | if (dentry == NULL) { |
| 2257 | dentry = opendata->dentry; |
| 2258 | } else if (dentry != ctx->dentry) { |
| 2259 | dput(ctx->dentry); |
| 2260 | ctx->dentry = dget(dentry); |
| 2261 | } |
| 2262 | nfs_set_verifier(dentry, |
| 2263 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2264 | } |
| 2265 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2266 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2267 | if (ret != 0) |
| 2268 | goto out; |
| 2269 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2270 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2271 | if (dentry->d_inode == state->inode) { |
| 2272 | nfs_inode_attach_open_context(ctx); |
| 2273 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2274 | nfs4_schedule_stateid_recovery(server, state); |
| 2275 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2276 | out: |
| 2277 | return ret; |
| 2278 | } |
| 2279 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2280 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2281 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2283 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2284 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2285 | int flags, |
| 2286 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2287 | struct nfs4_label *label, |
| 2288 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | { |
| 2290 | struct nfs4_state_owner *sp; |
| 2291 | struct nfs4_state *state = NULL; |
| 2292 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2293 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2294 | struct dentry *dentry = ctx->dentry; |
| 2295 | struct rpc_cred *cred = ctx->cred; |
| 2296 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2297 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2298 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2299 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2300 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | |
| 2302 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2304 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2305 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2307 | goto out_err; |
| 2308 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2309 | status = nfs4_recover_expired_lease(server); |
| 2310 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2311 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2312 | if (dentry->d_inode != NULL) |
| 2313 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2314 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2315 | if (dentry->d_inode) |
| 2316 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2317 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2318 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2319 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2320 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2322 | if (label) { |
| 2323 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2324 | if (IS_ERR(olabel)) { |
| 2325 | status = PTR_ERR(olabel); |
| 2326 | goto err_opendata_put; |
| 2327 | } |
| 2328 | } |
| 2329 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2330 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2331 | if (!opendata->f_attr.mdsthreshold) { |
| 2332 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2333 | if (!opendata->f_attr.mdsthreshold) |
| 2334 | goto err_free_label; |
| 2335 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2336 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2337 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2338 | if (dentry->d_inode != NULL) |
| 2339 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2340 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2341 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2342 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2343 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2344 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2345 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2346 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2347 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2348 | nfs4_exclusive_attrset(opendata, sattr); |
| 2349 | |
| 2350 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2351 | status = nfs4_do_setattr(state->inode, cred, |
| 2352 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2353 | state, label, olabel); |
| 2354 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2355 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2356 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2357 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2358 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2359 | } |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2360 | if (opendata->file_created) |
| 2361 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2362 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2363 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2364 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2365 | opendata->f_attr.mdsthreshold = NULL; |
| 2366 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2367 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2368 | nfs4_label_free(olabel); |
| 2369 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2370 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2373 | err_free_label: |
| 2374 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2375 | err_opendata_put: |
| 2376 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2377 | err_put_state_owner: |
| 2378 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | return status; |
| 2381 | } |
| 2382 | |
| 2383 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2384 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2385 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2386 | int flags, |
| 2387 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2388 | struct nfs4_label *label, |
| 2389 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2391 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | struct nfs4_exception exception = { }; |
| 2393 | struct nfs4_state *res; |
| 2394 | int status; |
| 2395 | |
| 2396 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2397 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2398 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2399 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | if (status == 0) |
| 2401 | break; |
| 2402 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2403 | * book-keeping w.r.t. state-changing operations |
| 2404 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2405 | * It is actually a sign of a bug on the client or on the server. |
| 2406 | * |
| 2407 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2408 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | * have unhashed the old state_owner for us, and that we can |
| 2410 | * therefore safely retry using a new one. We should still warn |
| 2411 | * the user though... |
| 2412 | */ |
| 2413 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2414 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2415 | " returned a bad sequence-id error!\n", |
| 2416 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | exception.retry = 1; |
| 2418 | continue; |
| 2419 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2420 | /* |
| 2421 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2422 | * state before it received the OPEN_CONFIRM. |
| 2423 | * Recover by retrying the request as per the discussion |
| 2424 | * on Page 181 of RFC3530. |
| 2425 | */ |
| 2426 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2427 | exception.retry = 1; |
| 2428 | continue; |
| 2429 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2430 | if (status == -EAGAIN) { |
| 2431 | /* We must have found a delegation */ |
| 2432 | exception.retry = 1; |
| 2433 | continue; |
| 2434 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2435 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2436 | continue; |
| 2437 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | status, &exception)); |
| 2439 | } while (exception.retry); |
| 2440 | return res; |
| 2441 | } |
| 2442 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2443 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2444 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2445 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2446 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2448 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2450 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | .iap = sattr, |
| 2452 | .server = server, |
| 2453 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2454 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | }; |
| 2456 | struct nfs_setattrres res = { |
| 2457 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2458 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | .server = server, |
| 2460 | }; |
| 2461 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2462 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2463 | .rpc_argp = &arg, |
| 2464 | .rpc_resp = &res, |
| 2465 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2467 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2468 | fmode_t fmode; |
| 2469 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2470 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2472 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2473 | if (ilabel) |
| 2474 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2475 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2476 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2478 | /* Servers should only apply open mode checks for file size changes */ |
| 2479 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2480 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2481 | |
| 2482 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2483 | /* Use that stateid */ |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2484 | } else if (truncate && state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2485 | struct nfs_lockowner lockowner = { |
| 2486 | .l_owner = current->files, |
| 2487 | .l_pid = current->tgid, |
| 2488 | }; |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2489 | if (!nfs4_valid_open_stateid(state)) |
| 2490 | return -EBADF; |
| 2491 | if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2492 | &lockowner) == -EIO) |
| 2493 | return -EBADF; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2494 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2495 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2497 | 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] | 2498 | if (status == 0 && state != NULL) |
| 2499 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2500 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2503 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2504 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2505 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2506 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2508 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2509 | struct nfs4_exception exception = { |
| 2510 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2511 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2512 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | int err; |
| 2514 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2515 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2516 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2517 | switch (err) { |
| 2518 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2519 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2520 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2521 | "applying open mode checks to " |
| 2522 | "a SETATTR that is not " |
| 2523 | "changing file size.\n", |
| 2524 | server->nfs_client->cl_hostname); |
| 2525 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2526 | if (state && !(state->state & FMODE_WRITE)) { |
| 2527 | err = -EBADF; |
| 2528 | if (sattr->ia_valid & ATTR_OPEN) |
| 2529 | err = -EACCES; |
| 2530 | goto out; |
| 2531 | } |
| 2532 | } |
| 2533 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2535 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | return err; |
| 2537 | } |
| 2538 | |
| 2539 | struct nfs4_closedata { |
| 2540 | struct inode *inode; |
| 2541 | struct nfs4_state *state; |
| 2542 | struct nfs_closeargs arg; |
| 2543 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2544 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2545 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2546 | bool roc; |
| 2547 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | }; |
| 2549 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2550 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2551 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2552 | struct nfs4_closedata *calldata = data; |
| 2553 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2554 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2555 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2556 | if (calldata->roc) |
| 2557 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2558 | nfs4_put_open_state(calldata->state); |
| 2559 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2560 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2561 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2562 | kfree(calldata); |
| 2563 | } |
| 2564 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2565 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2567 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2570 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2572 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2573 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2574 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2575 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | /* hmm. we are done with the inode, and in the process of freeing |
| 2577 | * the state_owner. we keep this around to process errors |
| 2578 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | switch (task->tk_status) { |
| 2580 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2581 | res_stateid = &calldata->res.stateid; |
| 2582 | if (calldata->arg.fmode == 0 && calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2583 | pnfs_roc_set_barrier(state->inode, |
| 2584 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2585 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2586 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2587 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2589 | case -NFS4ERR_OLD_STATEID: |
| 2590 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2592 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2593 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2595 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2596 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2597 | goto out_release; |
| 2598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | } |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2600 | nfs_clear_open_stateid(state, res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2601 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2602 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2603 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2604 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2607 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2609 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2610 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2611 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2612 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2613 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2614 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2615 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2616 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2617 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2618 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2619 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2620 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2621 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2622 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2623 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2624 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2625 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2626 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2627 | if (state->n_rdonly == 0) |
| 2628 | call_close |= is_rdonly; |
| 2629 | else if (is_rdonly) |
| 2630 | calldata->arg.fmode |= FMODE_READ; |
| 2631 | if (state->n_wronly == 0) |
| 2632 | call_close |= is_wronly; |
| 2633 | else if (is_wronly) |
| 2634 | calldata->arg.fmode |= FMODE_WRITE; |
| 2635 | } else if (is_rdwr) |
| 2636 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2637 | |
| 2638 | if (calldata->arg.fmode == 0) |
| 2639 | call_close |= is_rdwr; |
| 2640 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2641 | if (!nfs4_valid_open_stateid(state)) |
| 2642 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2643 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2644 | |
| 2645 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2646 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2647 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2648 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2649 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2650 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2651 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2652 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2653 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2654 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2655 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2656 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2657 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2658 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2659 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2660 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2661 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2662 | &calldata->arg.seq_args, |
| 2663 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2664 | task) != 0) |
| 2665 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2666 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2667 | return; |
| 2668 | out_no_action: |
| 2669 | task->tk_action = NULL; |
| 2670 | out_wait: |
| 2671 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2674 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2675 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2676 | .rpc_call_done = nfs4_close_done, |
| 2677 | .rpc_release = nfs4_free_closedata, |
| 2678 | }; |
| 2679 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2680 | static bool nfs4_state_has_opener(struct nfs4_state *state) |
| 2681 | { |
| 2682 | /* first check existing openers */ |
| 2683 | if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 && |
| 2684 | state->n_rdonly != 0) |
| 2685 | return true; |
| 2686 | |
| 2687 | if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 && |
| 2688 | state->n_wronly != 0) |
| 2689 | return true; |
| 2690 | |
| 2691 | if (test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 && |
| 2692 | state->n_rdwr != 0) |
| 2693 | return true; |
| 2694 | |
| 2695 | return false; |
| 2696 | } |
| 2697 | |
| 2698 | static bool nfs4_roc(struct inode *inode) |
| 2699 | { |
| 2700 | struct nfs_inode *nfsi = NFS_I(inode); |
| 2701 | struct nfs_open_context *ctx; |
| 2702 | struct nfs4_state *state; |
| 2703 | |
| 2704 | spin_lock(&inode->i_lock); |
| 2705 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 2706 | state = ctx->state; |
| 2707 | if (state == NULL) |
| 2708 | continue; |
| 2709 | if (nfs4_state_has_opener(state)) { |
| 2710 | spin_unlock(&inode->i_lock); |
| 2711 | return false; |
| 2712 | } |
| 2713 | } |
| 2714 | spin_unlock(&inode->i_lock); |
| 2715 | |
| 2716 | if (nfs4_check_delegation(inode, FMODE_READ)) |
| 2717 | return false; |
| 2718 | |
| 2719 | return pnfs_roc(inode); |
| 2720 | } |
| 2721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | /* |
| 2723 | * It is possible for data to be read/written from a mem-mapped file |
| 2724 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2725 | * This means that we can't safely call nfsv4 close on a file until |
| 2726 | * the inode is cleared. This in turn means that we are not good |
| 2727 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2728 | * share state even when we are done with one of the three share |
| 2729 | * stateid's in the inode. |
| 2730 | * |
| 2731 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2732 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2733 | 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] | 2734 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2735 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2737 | struct nfs4_state_owner *sp = state->owner; |
| 2738 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2739 | struct rpc_message msg = { |
| 2740 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2741 | .rpc_cred = state->owner->so_cred, |
| 2742 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2743 | struct rpc_task_setup task_setup_data = { |
| 2744 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2745 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2746 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2747 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2748 | .flags = RPC_TASK_ASYNC, |
| 2749 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2750 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2752 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2753 | &task_setup_data.rpc_client, &msg); |
| 2754 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2755 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2757 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2758 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2759 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2761 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2762 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2764 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2765 | if (calldata->arg.seqid == NULL) |
| 2766 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2767 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2768 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2769 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2770 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2771 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2772 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2773 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2774 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2775 | msg.rpc_argp = &calldata->arg; |
| 2776 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2777 | task_setup_data.callback_data = calldata; |
| 2778 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2779 | if (IS_ERR(task)) |
| 2780 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2781 | status = 0; |
| 2782 | if (wait) |
| 2783 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2784 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2785 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2786 | out_free_calldata: |
| 2787 | kfree(calldata); |
| 2788 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2789 | nfs4_put_open_state(state); |
| 2790 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2791 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2794 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2795 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 2796 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2799 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2800 | |
| 2801 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2803 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2804 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2805 | |
| 2806 | nfs4_label_release_security(label); |
| 2807 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2808 | if (IS_ERR(state)) |
| 2809 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2810 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2813 | 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] | 2814 | { |
| 2815 | if (ctx->state == NULL) |
| 2816 | return; |
| 2817 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2818 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2819 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2820 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2823 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 2824 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 2825 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2828 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2829 | struct nfs4_server_caps_arg args = { |
| 2830 | .fhandle = fhandle, |
| 2831 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | struct nfs4_server_caps_res res = {}; |
| 2833 | struct rpc_message msg = { |
| 2834 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2835 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | .rpc_resp = &res, |
| 2837 | }; |
| 2838 | int status; |
| 2839 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2840 | 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] | 2841 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2842 | /* Sanity check the server answers */ |
| 2843 | switch (server->nfs_client->cl_minorversion) { |
| 2844 | case 0: |
| 2845 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 2846 | res.attr_bitmask[2] = 0; |
| 2847 | break; |
| 2848 | case 1: |
| 2849 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 2850 | break; |
| 2851 | case 2: |
| 2852 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 2853 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2855 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2856 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2857 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2858 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2859 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 2860 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 2861 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 2862 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | server->caps |= NFS_CAP_ACLS; |
| 2864 | if (res.has_links != 0) |
| 2865 | server->caps |= NFS_CAP_HARDLINKS; |
| 2866 | if (res.has_symlinks != 0) |
| 2867 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2868 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2869 | server->caps |= NFS_CAP_FILEID; |
| 2870 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2871 | server->caps |= NFS_CAP_MODE; |
| 2872 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2873 | server->caps |= NFS_CAP_NLINK; |
| 2874 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2875 | server->caps |= NFS_CAP_OWNER; |
| 2876 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2877 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2878 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2879 | server->caps |= NFS_CAP_ATIME; |
| 2880 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2881 | server->caps |= NFS_CAP_CTIME; |
| 2882 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2883 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2884 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2885 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2886 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2887 | #endif |
| 2888 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2889 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2890 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2891 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2892 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2893 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2894 | server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2895 | server->cache_consistency_bitmask[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2897 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | return status; |
| 2901 | } |
| 2902 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2903 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | { |
| 2905 | struct nfs4_exception exception = { }; |
| 2906 | int err; |
| 2907 | do { |
| 2908 | err = nfs4_handle_exception(server, |
| 2909 | _nfs4_server_capabilities(server, fhandle), |
| 2910 | &exception); |
| 2911 | } while (exception.retry); |
| 2912 | return err; |
| 2913 | } |
| 2914 | |
| 2915 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2916 | struct nfs_fsinfo *info) |
| 2917 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2918 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2920 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | }; |
| 2922 | struct nfs4_lookup_res res = { |
| 2923 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2924 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | .fh = fhandle, |
| 2926 | }; |
| 2927 | struct rpc_message msg = { |
| 2928 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2929 | .rpc_argp = &args, |
| 2930 | .rpc_resp = &res, |
| 2931 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2932 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2933 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2934 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2935 | /* |
| 2936 | * Process the label in the upcoming getfattr |
| 2937 | */ |
| 2938 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2939 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2940 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2941 | 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] | 2942 | } |
| 2943 | |
| 2944 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2945 | struct nfs_fsinfo *info) |
| 2946 | { |
| 2947 | struct nfs4_exception exception = { }; |
| 2948 | int err; |
| 2949 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2950 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2951 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2952 | switch (err) { |
| 2953 | case 0: |
| 2954 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2955 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2956 | default: |
| 2957 | err = nfs4_handle_exception(server, err, &exception); |
| 2958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2960 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | return err; |
| 2962 | } |
| 2963 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2964 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2965 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2966 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2967 | struct rpc_auth_create_args auth_args = { |
| 2968 | .pseudoflavor = flavor, |
| 2969 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2970 | struct rpc_auth *auth; |
| 2971 | int ret; |
| 2972 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2973 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2974 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2975 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2976 | goto out; |
| 2977 | } |
| 2978 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2979 | out: |
| 2980 | return ret; |
| 2981 | } |
| 2982 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2983 | /* |
| 2984 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2985 | * |
| 2986 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2987 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2988 | * |
| 2989 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2990 | * negative errno value. |
| 2991 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2992 | 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] | 2993 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2995 | /* Per 3530bis 15.33.5 */ |
| 2996 | static const rpc_authflavor_t flav_array[] = { |
| 2997 | RPC_AUTH_GSS_KRB5P, |
| 2998 | RPC_AUTH_GSS_KRB5I, |
| 2999 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3000 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3001 | RPC_AUTH_NULL, |
| 3002 | }; |
| 3003 | int status = -EPERM; |
| 3004 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3006 | if (server->auth_info.flavor_len > 0) { |
| 3007 | /* try each flavor specified by user */ |
| 3008 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3009 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3010 | server->auth_info.flavors[i]); |
| 3011 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3012 | continue; |
| 3013 | break; |
| 3014 | } |
| 3015 | } else { |
| 3016 | /* no flavors specified by user, try default list */ |
| 3017 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3018 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3019 | flav_array[i]); |
| 3020 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3021 | continue; |
| 3022 | break; |
| 3023 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3024 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3025 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3026 | /* |
| 3027 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3028 | * to access the mount. It could also mean that we tried to mount |
| 3029 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3030 | * existing mount programs don't handle -EACCES very well so it should |
| 3031 | * be mapped to -EPERM instead. |
| 3032 | */ |
| 3033 | if (status == -EACCES) |
| 3034 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3035 | return status; |
| 3036 | } |
| 3037 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3038 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 3039 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 3040 | { |
| 3041 | int mv = server->nfs_client->cl_minorversion; |
| 3042 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 3043 | } |
| 3044 | |
| 3045 | /** |
| 3046 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3047 | * @server: initialized nfs_server handle |
| 3048 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3049 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3050 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3051 | * |
| 3052 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3053 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3054 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3055 | struct nfs_fsinfo *info, |
| 3056 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3057 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3058 | int status; |
| 3059 | |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3060 | switch (auth_probe) { |
| 3061 | case false: |
| 3062 | status = nfs4_lookup_root(server, fhandle, info); |
| 3063 | if (status != -NFS4ERR_WRONGSEC) |
| 3064 | break; |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3065 | default: |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3066 | status = nfs4_do_find_root_sec(server, fhandle, info); |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3067 | } |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | if (status == 0) |
| 3070 | status = nfs4_server_capabilities(server, fhandle); |
| 3071 | if (status == 0) |
| 3072 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3073 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3074 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | } |
| 3076 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3077 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3078 | struct nfs_fsinfo *info) |
| 3079 | { |
| 3080 | int error; |
| 3081 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3082 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3083 | |
| 3084 | error = nfs4_server_capabilities(server, mntfh); |
| 3085 | if (error < 0) { |
| 3086 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3087 | return error; |
| 3088 | } |
| 3089 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3090 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3091 | if (IS_ERR(label)) |
| 3092 | return PTR_ERR(label); |
| 3093 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3094 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3095 | if (error < 0) { |
| 3096 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3097 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3101 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3102 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3103 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3104 | err_free_label: |
| 3105 | nfs4_label_free(label); |
| 3106 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3107 | return error; |
| 3108 | } |
| 3109 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3110 | /* |
| 3111 | * Get locations and (maybe) other attributes of a referral. |
| 3112 | * Note that we'll actually follow the referral later when |
| 3113 | * we detect fsid mismatch in inode revalidation |
| 3114 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3115 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3116 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3117 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3118 | { |
| 3119 | int status = -ENOMEM; |
| 3120 | struct page *page = NULL; |
| 3121 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3122 | |
| 3123 | page = alloc_page(GFP_KERNEL); |
| 3124 | if (page == NULL) |
| 3125 | goto out; |
| 3126 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3127 | if (locations == NULL) |
| 3128 | goto out; |
| 3129 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3130 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3131 | if (status != 0) |
| 3132 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3133 | |
| 3134 | /* |
| 3135 | * If the fsid didn't change, this is a migration event, not a |
| 3136 | * referral. Cause us to drop into the exception handler, which |
| 3137 | * will kick off migration recovery. |
| 3138 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3139 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3140 | dprintk("%s: server did not return a different fsid for" |
| 3141 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3142 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3143 | goto out; |
| 3144 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3145 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3146 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3147 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3148 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3149 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3150 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3151 | out: |
| 3152 | if (page) |
| 3153 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3154 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3155 | return status; |
| 3156 | } |
| 3157 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3158 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3159 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | { |
| 3161 | struct nfs4_getattr_arg args = { |
| 3162 | .fh = fhandle, |
| 3163 | .bitmask = server->attr_bitmask, |
| 3164 | }; |
| 3165 | struct nfs4_getattr_res res = { |
| 3166 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3167 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | .server = server, |
| 3169 | }; |
| 3170 | struct rpc_message msg = { |
| 3171 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3172 | .rpc_argp = &args, |
| 3173 | .rpc_resp = &res, |
| 3174 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3175 | |
| 3176 | args.bitmask = nfs4_bitmask(server, label); |
| 3177 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3178 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3179 | 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] | 3180 | } |
| 3181 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3182 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3183 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | { |
| 3185 | struct nfs4_exception exception = { }; |
| 3186 | int err; |
| 3187 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3188 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3189 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3190 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | &exception); |
| 3192 | } while (exception.retry); |
| 3193 | return err; |
| 3194 | } |
| 3195 | |
| 3196 | /* |
| 3197 | * The file is not closed if it is opened due to the a request to change |
| 3198 | * the size of the file. The open call will not be needed once the |
| 3199 | * VFS layer lookup-intents are implemented. |
| 3200 | * |
| 3201 | * Close is called when the inode is destroyed. |
| 3202 | * If we haven't opened the file for O_WRONLY, we |
| 3203 | * need to in the size_change case to obtain a stateid. |
| 3204 | * |
| 3205 | * Got race? |
| 3206 | * Because OPEN is always done by name in nfsv4, it is |
| 3207 | * possible that we opened a different file by the same |
| 3208 | * name. We can recognize this race condition, but we |
| 3209 | * can't do anything about it besides returning an error. |
| 3210 | * |
| 3211 | * This will be fixed with VFS changes (lookup-intent). |
| 3212 | */ |
| 3213 | static int |
| 3214 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3215 | struct iattr *sattr) |
| 3216 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3217 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3218 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3219 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3220 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | int status; |
| 3222 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3223 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3224 | sattr->ia_valid & ATTR_SIZE && |
| 3225 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3226 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3227 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3228 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3230 | /* Deal with open(O_TRUNC) */ |
| 3231 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3232 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3233 | |
| 3234 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3235 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3236 | return 0; |
| 3237 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3238 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3239 | if (sattr->ia_valid & ATTR_FILE) { |
| 3240 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3241 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3242 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3243 | if (ctx) { |
| 3244 | cred = ctx->cred; |
| 3245 | state = ctx->state; |
| 3246 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3247 | } |
| 3248 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3249 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3250 | if (IS_ERR(label)) |
| 3251 | return PTR_ERR(label); |
| 3252 | |
| 3253 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3254 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 3255 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3256 | nfs_setsecurity(inode, fattr, label); |
| 3257 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3258 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | return status; |
| 3260 | } |
| 3261 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3262 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3263 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3264 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3265 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3266 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3267 | int status; |
| 3268 | struct nfs4_lookup_arg args = { |
| 3269 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3270 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3271 | .name = name, |
| 3272 | }; |
| 3273 | struct nfs4_lookup_res res = { |
| 3274 | .server = server, |
| 3275 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3276 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3277 | .fh = fhandle, |
| 3278 | }; |
| 3279 | struct rpc_message msg = { |
| 3280 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3281 | .rpc_argp = &args, |
| 3282 | .rpc_resp = &res, |
| 3283 | }; |
| 3284 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3285 | args.bitmask = nfs4_bitmask(server, label); |
| 3286 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3287 | nfs_fattr_init(fattr); |
| 3288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3290 | 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] | 3291 | dprintk("NFS reply lookup: %d\n", status); |
| 3292 | return status; |
| 3293 | } |
| 3294 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3295 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3296 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3297 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3298 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3299 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3300 | fattr->nlink = 2; |
| 3301 | } |
| 3302 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3303 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3304 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3305 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3306 | { |
| 3307 | struct nfs4_exception exception = { }; |
| 3308 | struct rpc_clnt *client = *clnt; |
| 3309 | int err; |
| 3310 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3311 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3312 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3313 | switch (err) { |
| 3314 | case -NFS4ERR_BADNAME: |
| 3315 | err = -ENOENT; |
| 3316 | goto out; |
| 3317 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3318 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3319 | goto out; |
| 3320 | case -NFS4ERR_WRONGSEC: |
| 3321 | err = -EPERM; |
| 3322 | if (client != *clnt) |
| 3323 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3324 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3325 | if (IS_ERR(client)) |
| 3326 | return PTR_ERR(client); |
| 3327 | |
| 3328 | exception.retry = 1; |
| 3329 | break; |
| 3330 | default: |
| 3331 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3332 | } |
| 3333 | } while (exception.retry); |
| 3334 | |
| 3335 | out: |
| 3336 | if (err == 0) |
| 3337 | *clnt = client; |
| 3338 | else if (client != *clnt) |
| 3339 | rpc_shutdown_client(client); |
| 3340 | |
| 3341 | return err; |
| 3342 | } |
| 3343 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3344 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3345 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3346 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3348 | int status; |
| 3349 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3350 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3351 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3352 | if (client != NFS_CLIENT(dir)) { |
| 3353 | rpc_shutdown_client(client); |
| 3354 | nfs_fixup_secinfo_attributes(fattr); |
| 3355 | } |
| 3356 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3359 | struct rpc_clnt * |
| 3360 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3361 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3362 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3363 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3364 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3365 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3366 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3367 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3368 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3369 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3370 | } |
| 3371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3373 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3374 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | struct nfs4_accessargs args = { |
| 3376 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3377 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3379 | struct nfs4_accessres res = { |
| 3380 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3381 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | struct rpc_message msg = { |
| 3383 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3384 | .rpc_argp = &args, |
| 3385 | .rpc_resp = &res, |
| 3386 | .rpc_cred = entry->cred, |
| 3387 | }; |
| 3388 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3389 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | |
| 3391 | /* |
| 3392 | * Determine which access bits we want to ask for... |
| 3393 | */ |
| 3394 | if (mode & MAY_READ) |
| 3395 | args.access |= NFS4_ACCESS_READ; |
| 3396 | if (S_ISDIR(inode->i_mode)) { |
| 3397 | if (mode & MAY_WRITE) |
| 3398 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3399 | if (mode & MAY_EXEC) |
| 3400 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3401 | } else { |
| 3402 | if (mode & MAY_WRITE) |
| 3403 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3404 | if (mode & MAY_EXEC) |
| 3405 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3406 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3407 | |
| 3408 | res.fattr = nfs_alloc_fattr(); |
| 3409 | if (res.fattr == NULL) |
| 3410 | return -ENOMEM; |
| 3411 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3412 | 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] | 3413 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3414 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3415 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3417 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | return status; |
| 3419 | } |
| 3420 | |
| 3421 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3422 | { |
| 3423 | struct nfs4_exception exception = { }; |
| 3424 | int err; |
| 3425 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3426 | err = _nfs4_proc_access(inode, entry); |
| 3427 | trace_nfs4_access(inode, err); |
| 3428 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | &exception); |
| 3430 | } while (exception.retry); |
| 3431 | return err; |
| 3432 | } |
| 3433 | |
| 3434 | /* |
| 3435 | * TODO: For the time being, we don't try to get any attributes |
| 3436 | * along with any of the zero-copy operations READ, READDIR, |
| 3437 | * READLINK, WRITE. |
| 3438 | * |
| 3439 | * In the case of the first three, we want to put the GETATTR |
| 3440 | * after the read-type operation -- this is because it is hard |
| 3441 | * to predict the length of a GETATTR response in v4, and thus |
| 3442 | * align the READ data correctly. This means that the GETATTR |
| 3443 | * may end up partially falling into the page cache, and we should |
| 3444 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3445 | * To do this efficiently, we need to know the total length |
| 3446 | * of data received, which doesn't seem to be available outside |
| 3447 | * of the RPC layer. |
| 3448 | * |
| 3449 | * In the case of WRITE, we also want to put the GETATTR after |
| 3450 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3451 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | * |
| 3453 | * Both of these changes to the XDR layer would in fact be quite |
| 3454 | * minor, but I decided to leave them for a subsequent patch. |
| 3455 | */ |
| 3456 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3457 | unsigned int pgbase, unsigned int pglen) |
| 3458 | { |
| 3459 | struct nfs4_readlink args = { |
| 3460 | .fh = NFS_FH(inode), |
| 3461 | .pgbase = pgbase, |
| 3462 | .pglen = pglen, |
| 3463 | .pages = &page, |
| 3464 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3465 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | struct rpc_message msg = { |
| 3467 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3468 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3469 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | }; |
| 3471 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3472 | 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] | 3473 | } |
| 3474 | |
| 3475 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3476 | unsigned int pgbase, unsigned int pglen) |
| 3477 | { |
| 3478 | struct nfs4_exception exception = { }; |
| 3479 | int err; |
| 3480 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3481 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3482 | trace_nfs4_readlink(inode, err); |
| 3483 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | &exception); |
| 3485 | } while (exception.retry); |
| 3486 | return err; |
| 3487 | } |
| 3488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3490 | * 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] | 3491 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | static int |
| 3493 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3494 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3496 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3497 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | struct nfs4_state *state; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3499 | int opened = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | int status = 0; |
| 3501 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3502 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3503 | if (IS_ERR(ctx)) |
| 3504 | return PTR_ERR(ctx); |
| 3505 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3506 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3507 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3508 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3509 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, &opened); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | if (IS_ERR(state)) { |
| 3511 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3512 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3515 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3516 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | return status; |
| 3518 | } |
| 3519 | |
| 3520 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3521 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3522 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3523 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3525 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3527 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3528 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3529 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3532 | .rpc_argp = &args, |
| 3533 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3535 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3536 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3537 | 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] | 3538 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3539 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | return status; |
| 3541 | } |
| 3542 | |
| 3543 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3544 | { |
| 3545 | struct nfs4_exception exception = { }; |
| 3546 | int err; |
| 3547 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3548 | err = _nfs4_proc_remove(dir, name); |
| 3549 | trace_nfs4_remove(dir, name, err); |
| 3550 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | &exception); |
| 3552 | } while (exception.retry); |
| 3553 | return err; |
| 3554 | } |
| 3555 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3556 | 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] | 3557 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3558 | struct nfs_server *server = NFS_SERVER(dir); |
| 3559 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3560 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3562 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3564 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3565 | |
| 3566 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3569 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3570 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3571 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3572 | &data->args.seq_args, |
| 3573 | &data->res.seq_res, |
| 3574 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3577 | 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] | 3578 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3579 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3580 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3581 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3582 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3583 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3584 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3585 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3586 | return 0; |
| 3587 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3588 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3591 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3592 | { |
| 3593 | struct nfs_server *server = NFS_SERVER(dir); |
| 3594 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3595 | struct nfs_renameres *res = msg->rpc_resp; |
| 3596 | |
| 3597 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3598 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3599 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3600 | } |
| 3601 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3602 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3603 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3604 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3605 | &data->args.seq_args, |
| 3606 | &data->res.seq_res, |
| 3607 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3611 | struct inode *new_dir) |
| 3612 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3613 | struct nfs_renamedata *data = task->tk_calldata; |
| 3614 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3615 | |
| 3616 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3617 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3618 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3619 | return 0; |
| 3620 | |
| 3621 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3622 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3623 | return 1; |
| 3624 | } |
| 3625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3627 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3628 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | struct nfs4_link_arg arg = { |
| 3630 | .fh = NFS_FH(inode), |
| 3631 | .dir_fh = NFS_FH(dir), |
| 3632 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3633 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3635 | struct nfs4_link_res res = { |
| 3636 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3637 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3638 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | struct rpc_message msg = { |
| 3640 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3641 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3642 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3644 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3646 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3647 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3648 | goto out; |
| 3649 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3650 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3651 | if (IS_ERR(res.label)) { |
| 3652 | status = PTR_ERR(res.label); |
| 3653 | goto out; |
| 3654 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3655 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3656 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3657 | 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] | 3658 | if (!status) { |
| 3659 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3660 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3661 | if (!status) |
| 3662 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3663 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3664 | |
| 3665 | |
| 3666 | nfs4_label_free(res.label); |
| 3667 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3668 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3669 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | return status; |
| 3671 | } |
| 3672 | |
| 3673 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3674 | { |
| 3675 | struct nfs4_exception exception = { }; |
| 3676 | int err; |
| 3677 | do { |
| 3678 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3679 | _nfs4_proc_link(inode, dir, name), |
| 3680 | &exception); |
| 3681 | } while (exception.retry); |
| 3682 | return err; |
| 3683 | } |
| 3684 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3685 | struct nfs4_createdata { |
| 3686 | struct rpc_message msg; |
| 3687 | struct nfs4_create_arg arg; |
| 3688 | struct nfs4_create_res res; |
| 3689 | struct nfs_fh fh; |
| 3690 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3691 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3692 | }; |
| 3693 | |
| 3694 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3695 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3696 | { |
| 3697 | struct nfs4_createdata *data; |
| 3698 | |
| 3699 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3700 | if (data != NULL) { |
| 3701 | struct nfs_server *server = NFS_SERVER(dir); |
| 3702 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3703 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3704 | if (IS_ERR(data->label)) |
| 3705 | goto out_free; |
| 3706 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3707 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3708 | data->msg.rpc_argp = &data->arg; |
| 3709 | data->msg.rpc_resp = &data->res; |
| 3710 | data->arg.dir_fh = NFS_FH(dir); |
| 3711 | data->arg.server = server; |
| 3712 | data->arg.name = name; |
| 3713 | data->arg.attrs = sattr; |
| 3714 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3715 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3716 | data->res.server = server; |
| 3717 | data->res.fh = &data->fh; |
| 3718 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3719 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3720 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3721 | } |
| 3722 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3723 | out_free: |
| 3724 | kfree(data); |
| 3725 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3729 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3730 | 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] | 3731 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3732 | if (status == 0) { |
| 3733 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3734 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3735 | } |
| 3736 | return status; |
| 3737 | } |
| 3738 | |
| 3739 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3740 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3741 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3742 | kfree(data); |
| 3743 | } |
| 3744 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3745 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3746 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3747 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3749 | struct nfs4_createdata *data; |
| 3750 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3752 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3753 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3754 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3755 | status = -ENOMEM; |
| 3756 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3757 | if (data == NULL) |
| 3758 | goto out; |
| 3759 | |
| 3760 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3761 | data->arg.u.symlink.pages = &page; |
| 3762 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3763 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3765 | status = nfs4_do_create(dir, dentry, data); |
| 3766 | |
| 3767 | nfs4_free_createdata(data); |
| 3768 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | return status; |
| 3770 | } |
| 3771 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3772 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3773 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | { |
| 3775 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3776 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3778 | |
| 3779 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3782 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3783 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3784 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | &exception); |
| 3786 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3787 | |
| 3788 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | return err; |
| 3790 | } |
| 3791 | |
| 3792 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3793 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3795 | struct nfs4_createdata *data; |
| 3796 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3798 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3799 | if (data == NULL) |
| 3800 | goto out; |
| 3801 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3802 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3803 | status = nfs4_do_create(dir, dentry, data); |
| 3804 | |
| 3805 | nfs4_free_createdata(data); |
| 3806 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | return status; |
| 3808 | } |
| 3809 | |
| 3810 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3811 | struct iattr *sattr) |
| 3812 | { |
| 3813 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3814 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3816 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3817 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3818 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3819 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3821 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3822 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3823 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | &exception); |
| 3825 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3826 | nfs4_label_release_security(label); |
| 3827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | return err; |
| 3829 | } |
| 3830 | |
| 3831 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3832 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | { |
| 3834 | struct inode *dir = dentry->d_inode; |
| 3835 | struct nfs4_readdir_arg args = { |
| 3836 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3837 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | .pgbase = 0, |
| 3839 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3840 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3841 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | }; |
| 3843 | struct nfs4_readdir_res res; |
| 3844 | struct rpc_message msg = { |
| 3845 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3846 | .rpc_argp = &args, |
| 3847 | .rpc_resp = &res, |
| 3848 | .rpc_cred = cred, |
| 3849 | }; |
| 3850 | int status; |
| 3851 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 3852 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 3853 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3854 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3855 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3857 | 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] | 3858 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3859 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3860 | status += args.pgbase; |
| 3861 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3862 | |
| 3863 | nfs_invalidate_atime(dir); |
| 3864 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3865 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | return status; |
| 3867 | } |
| 3868 | |
| 3869 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3870 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | { |
| 3872 | struct nfs4_exception exception = { }; |
| 3873 | int err; |
| 3874 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3875 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3876 | pages, count, plus); |
| 3877 | trace_nfs4_readdir(dentry->d_inode, err); |
| 3878 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | &exception); |
| 3880 | } while (exception.retry); |
| 3881 | return err; |
| 3882 | } |
| 3883 | |
| 3884 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3885 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3887 | struct nfs4_createdata *data; |
| 3888 | int mode = sattr->ia_mode; |
| 3889 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3891 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3892 | if (data == NULL) |
| 3893 | goto out; |
| 3894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3896 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3898 | data->arg.ftype = NF4BLK; |
| 3899 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3900 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | } |
| 3902 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3903 | data->arg.ftype = NF4CHR; |
| 3904 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3905 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3906 | } else if (!S_ISSOCK(mode)) { |
| 3907 | status = -EINVAL; |
| 3908 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3910 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3911 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3912 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3913 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3914 | nfs4_free_createdata(data); |
| 3915 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | return status; |
| 3917 | } |
| 3918 | |
| 3919 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3920 | struct iattr *sattr, dev_t rdev) |
| 3921 | { |
| 3922 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3923 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3925 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3926 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3927 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3928 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3930 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3931 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3932 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | &exception); |
| 3934 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3935 | |
| 3936 | nfs4_label_release_security(label); |
| 3937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | return err; |
| 3939 | } |
| 3940 | |
| 3941 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3942 | struct nfs_fsstat *fsstat) |
| 3943 | { |
| 3944 | struct nfs4_statfs_arg args = { |
| 3945 | .fh = fhandle, |
| 3946 | .bitmask = server->attr_bitmask, |
| 3947 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3948 | struct nfs4_statfs_res res = { |
| 3949 | .fsstat = fsstat, |
| 3950 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | struct rpc_message msg = { |
| 3952 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3953 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3954 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | }; |
| 3956 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3957 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3958 | 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] | 3959 | } |
| 3960 | |
| 3961 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3962 | { |
| 3963 | struct nfs4_exception exception = { }; |
| 3964 | int err; |
| 3965 | do { |
| 3966 | err = nfs4_handle_exception(server, |
| 3967 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3968 | &exception); |
| 3969 | } while (exception.retry); |
| 3970 | return err; |
| 3971 | } |
| 3972 | |
| 3973 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3974 | struct nfs_fsinfo *fsinfo) |
| 3975 | { |
| 3976 | struct nfs4_fsinfo_arg args = { |
| 3977 | .fh = fhandle, |
| 3978 | .bitmask = server->attr_bitmask, |
| 3979 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3980 | struct nfs4_fsinfo_res res = { |
| 3981 | .fsinfo = fsinfo, |
| 3982 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | struct rpc_message msg = { |
| 3984 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3985 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3986 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | }; |
| 3988 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3989 | 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] | 3990 | } |
| 3991 | |
| 3992 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3993 | { |
| 3994 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3995 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | int err; |
| 3997 | |
| 3998 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3999 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4000 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4001 | if (err == 0) { |
| 4002 | struct nfs_client *clp = server->nfs_client; |
| 4003 | |
| 4004 | spin_lock(&clp->cl_lock); |
| 4005 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 4006 | clp->cl_last_renewal = now; |
| 4007 | spin_unlock(&clp->cl_lock); |
| 4008 | break; |
| 4009 | } |
| 4010 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | } while (exception.retry); |
| 4012 | return err; |
| 4013 | } |
| 4014 | |
| 4015 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4016 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4017 | int error; |
| 4018 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4019 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4020 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4021 | if (error == 0) { |
| 4022 | /* block layout checks this! */ |
| 4023 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4024 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4025 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4026 | |
| 4027 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4031 | struct nfs_pathconf *pathconf) |
| 4032 | { |
| 4033 | struct nfs4_pathconf_arg args = { |
| 4034 | .fh = fhandle, |
| 4035 | .bitmask = server->attr_bitmask, |
| 4036 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4037 | struct nfs4_pathconf_res res = { |
| 4038 | .pathconf = pathconf, |
| 4039 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | struct rpc_message msg = { |
| 4041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4042 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4043 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | }; |
| 4045 | |
| 4046 | /* None of the pathconf attributes are mandatory to implement */ |
| 4047 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4048 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4049 | return 0; |
| 4050 | } |
| 4051 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4052 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4053 | 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] | 4054 | } |
| 4055 | |
| 4056 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4057 | struct nfs_pathconf *pathconf) |
| 4058 | { |
| 4059 | struct nfs4_exception exception = { }; |
| 4060 | int err; |
| 4061 | |
| 4062 | do { |
| 4063 | err = nfs4_handle_exception(server, |
| 4064 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4065 | &exception); |
| 4066 | } while (exception.retry); |
| 4067 | return err; |
| 4068 | } |
| 4069 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4070 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4071 | const struct nfs_open_context *ctx, |
| 4072 | const struct nfs_lock_context *l_ctx, |
| 4073 | fmode_t fmode) |
| 4074 | { |
| 4075 | const struct nfs_lockowner *lockowner = NULL; |
| 4076 | |
| 4077 | if (l_ctx != NULL) |
| 4078 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4079 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4080 | } |
| 4081 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4082 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4083 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4084 | const struct nfs_open_context *ctx, |
| 4085 | const struct nfs_lock_context *l_ctx, |
| 4086 | fmode_t fmode) |
| 4087 | { |
| 4088 | nfs4_stateid current_stateid; |
| 4089 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4090 | /* If the current stateid represents a lost lock, then exit */ |
| 4091 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4092 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4093 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4094 | } |
| 4095 | |
| 4096 | static bool nfs4_error_stateid_expired(int err) |
| 4097 | { |
| 4098 | switch (err) { |
| 4099 | case -NFS4ERR_DELEG_REVOKED: |
| 4100 | case -NFS4ERR_ADMIN_REVOKED: |
| 4101 | case -NFS4ERR_BAD_STATEID: |
| 4102 | case -NFS4ERR_STALE_STATEID: |
| 4103 | case -NFS4ERR_OLD_STATEID: |
| 4104 | case -NFS4ERR_OPENMODE: |
| 4105 | case -NFS4ERR_EXPIRED: |
| 4106 | return true; |
| 4107 | } |
| 4108 | return false; |
| 4109 | } |
| 4110 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4111 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4112 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4113 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4114 | } |
| 4115 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4116 | static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4118 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4120 | trace_nfs4_read(hdr, task->tk_status); |
| 4121 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4122 | hdr->args.context->state, |
| 4123 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4124 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4125 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4127 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4128 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4130 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4131 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | } |
| 4133 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4134 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4135 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4136 | { |
| 4137 | |
| 4138 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4139 | nfs4_stateid_is_current(&args->stateid, |
| 4140 | args->context, |
| 4141 | args->lock_context, |
| 4142 | FMODE_READ)) |
| 4143 | return false; |
| 4144 | rpc_restart_call_prepare(task); |
| 4145 | return true; |
| 4146 | } |
| 4147 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4148 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4149 | { |
| 4150 | |
| 4151 | dprintk("--> %s\n", __func__); |
| 4152 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4153 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4154 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4155 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4156 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4157 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4158 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4161 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4162 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4164 | hdr->timestamp = jiffies; |
| 4165 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4166 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4167 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4170 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4171 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4172 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4173 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4174 | &hdr->args.seq_args, |
| 4175 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4176 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4177 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4178 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4179 | hdr->args.lock_context, |
| 4180 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4181 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4182 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4183 | return -EIO; |
| 4184 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4187 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4188 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4190 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4191 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4192 | trace_nfs4_write(hdr, task->tk_status); |
| 4193 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4194 | hdr->args.context->state, |
| 4195 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4196 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4197 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4199 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4200 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
| 4201 | nfs_post_op_update_inode_force_wcc(inode, &hdr->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4202 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4203 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4206 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4207 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4208 | { |
| 4209 | |
| 4210 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4211 | nfs4_stateid_is_current(&args->stateid, |
| 4212 | args->context, |
| 4213 | args->lock_context, |
| 4214 | FMODE_WRITE)) |
| 4215 | return false; |
| 4216 | rpc_restart_call_prepare(task); |
| 4217 | return true; |
| 4218 | } |
| 4219 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4220 | static int nfs4_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4221 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4222 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4223 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4224 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4225 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4226 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4227 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4228 | } |
| 4229 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4230 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4231 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4232 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4233 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4234 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4235 | return false; |
| 4236 | /* Otherwise, request attributes if and only if we don't hold |
| 4237 | * a delegation |
| 4238 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4239 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4240 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4241 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4242 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4243 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4245 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4246 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4247 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4248 | hdr->args.bitmask = NULL; |
| 4249 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4250 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4251 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4252 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4253 | if (!hdr->pgio_done_cb) |
| 4254 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4255 | hdr->res.server = server; |
| 4256 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4258 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4259 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4262 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4263 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4264 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4265 | &data->args.seq_args, |
| 4266 | &data->res.seq_res, |
| 4267 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4270 | 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] | 4271 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4273 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4274 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4275 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4276 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4277 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4278 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4280 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | } |
| 4282 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4283 | 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] | 4284 | { |
| 4285 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4286 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4287 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4288 | } |
| 4289 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4290 | 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] | 4291 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4292 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4293 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4294 | if (data->commit_done_cb == NULL) |
| 4295 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4296 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4297 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4298 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4301 | struct nfs4_renewdata { |
| 4302 | struct nfs_client *client; |
| 4303 | unsigned long timestamp; |
| 4304 | }; |
| 4305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | /* |
| 4307 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4308 | * standalone procedure for queueing an asynchronous RENEW. |
| 4309 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4310 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4311 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4312 | struct nfs4_renewdata *data = calldata; |
| 4313 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4314 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4315 | if (atomic_read(&clp->cl_count) > 1) |
| 4316 | nfs4_schedule_state_renewal(clp); |
| 4317 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4318 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4321 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4323 | struct nfs4_renewdata *data = calldata; |
| 4324 | struct nfs_client *clp = data->client; |
| 4325 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4327 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4328 | switch (task->tk_status) { |
| 4329 | case 0: |
| 4330 | break; |
| 4331 | case -NFS4ERR_LEASE_MOVED: |
| 4332 | nfs4_schedule_lease_moved_recovery(clp); |
| 4333 | break; |
| 4334 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4335 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4336 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4337 | return; |
| 4338 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4339 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4340 | return; |
| 4341 | } |
| 4342 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4344 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | } |
| 4346 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4347 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4348 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4349 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4350 | }; |
| 4351 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4352 | 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] | 4353 | { |
| 4354 | struct rpc_message msg = { |
| 4355 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4356 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4357 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4359 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4361 | if (renew_flags == 0) |
| 4362 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4363 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4364 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4365 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4366 | if (data == NULL) |
| 4367 | return -ENOMEM; |
| 4368 | data->client = clp; |
| 4369 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4370 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4371 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4372 | } |
| 4373 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4374 | 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] | 4375 | { |
| 4376 | struct rpc_message msg = { |
| 4377 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4378 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4379 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | }; |
| 4381 | unsigned long now = jiffies; |
| 4382 | int status; |
| 4383 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4384 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | if (status < 0) |
| 4386 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4387 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | return 0; |
| 4389 | } |
| 4390 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4391 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4392 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4393 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4394 | } |
| 4395 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4396 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4397 | * 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] | 4398 | * the stack. |
| 4399 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4400 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4401 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4402 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4403 | struct page **pages, unsigned int *pgbase) |
| 4404 | { |
| 4405 | struct page *newpage, **spages; |
| 4406 | int rc = 0; |
| 4407 | size_t len; |
| 4408 | spages = pages; |
| 4409 | |
| 4410 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4411 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4412 | newpage = alloc_page(GFP_KERNEL); |
| 4413 | |
| 4414 | if (newpage == NULL) |
| 4415 | goto unwind; |
| 4416 | memcpy(page_address(newpage), buf, len); |
| 4417 | buf += len; |
| 4418 | buflen -= len; |
| 4419 | *pages++ = newpage; |
| 4420 | rc++; |
| 4421 | } while (buflen != 0); |
| 4422 | |
| 4423 | return rc; |
| 4424 | |
| 4425 | unwind: |
| 4426 | for(; rc > 0; rc--) |
| 4427 | __free_page(spages[rc-1]); |
| 4428 | return -ENOMEM; |
| 4429 | } |
| 4430 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4431 | struct nfs4_cached_acl { |
| 4432 | int cached; |
| 4433 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4434 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4435 | }; |
| 4436 | |
| 4437 | 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] | 4438 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4439 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4440 | |
| 4441 | spin_lock(&inode->i_lock); |
| 4442 | kfree(nfsi->nfs4_acl); |
| 4443 | nfsi->nfs4_acl = acl; |
| 4444 | spin_unlock(&inode->i_lock); |
| 4445 | } |
| 4446 | |
| 4447 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4448 | { |
| 4449 | nfs4_set_cached_acl(inode, NULL); |
| 4450 | } |
| 4451 | |
| 4452 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4453 | { |
| 4454 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4455 | struct nfs4_cached_acl *acl; |
| 4456 | int ret = -ENOENT; |
| 4457 | |
| 4458 | spin_lock(&inode->i_lock); |
| 4459 | acl = nfsi->nfs4_acl; |
| 4460 | if (acl == NULL) |
| 4461 | goto out; |
| 4462 | if (buf == NULL) /* user is just asking for length */ |
| 4463 | goto out_len; |
| 4464 | if (acl->cached == 0) |
| 4465 | goto out; |
| 4466 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4467 | if (acl->len > buflen) |
| 4468 | goto out; |
| 4469 | memcpy(buf, acl->data, acl->len); |
| 4470 | out_len: |
| 4471 | ret = acl->len; |
| 4472 | out: |
| 4473 | spin_unlock(&inode->i_lock); |
| 4474 | return ret; |
| 4475 | } |
| 4476 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4477 | 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] | 4478 | { |
| 4479 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4480 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4481 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4482 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4483 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4484 | if (acl == NULL) |
| 4485 | goto out; |
| 4486 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4487 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4488 | } else { |
| 4489 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4490 | if (acl == NULL) |
| 4491 | goto out; |
| 4492 | acl->cached = 0; |
| 4493 | } |
| 4494 | acl->len = acl_len; |
| 4495 | out: |
| 4496 | nfs4_set_cached_acl(inode, acl); |
| 4497 | } |
| 4498 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4499 | /* |
| 4500 | * The getxattr API returns the required buffer length when called with a |
| 4501 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4502 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4503 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4504 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4505 | * the cache. If not so, we throw away the page, and cache the required |
| 4506 | * length. The next getxattr call will then produce another round trip to |
| 4507 | * the server, this time with the input buf of the required size. |
| 4508 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4509 | 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] | 4510 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4511 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4512 | struct nfs_getaclargs args = { |
| 4513 | .fh = NFS_FH(inode), |
| 4514 | .acl_pages = pages, |
| 4515 | .acl_len = buflen, |
| 4516 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4517 | struct nfs_getaclres res = { |
| 4518 | .acl_len = buflen, |
| 4519 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4520 | struct rpc_message msg = { |
| 4521 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4522 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4523 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4524 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4525 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4526 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4527 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4528 | /* As long as we're doing a round trip to the server anyway, |
| 4529 | * let's be prepared for a page of acl data. */ |
| 4530 | if (npages == 0) |
| 4531 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4532 | if (npages > ARRAY_SIZE(pages)) |
| 4533 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4534 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4535 | for (i = 0; i < npages; i++) { |
| 4536 | pages[i] = alloc_page(GFP_KERNEL); |
| 4537 | if (!pages[i]) |
| 4538 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4539 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4540 | |
| 4541 | /* for decoding across pages */ |
| 4542 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4543 | if (!res.acl_scratch) |
| 4544 | goto out_free; |
| 4545 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4546 | args.acl_len = npages * PAGE_SIZE; |
| 4547 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4548 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4549 | 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] | 4550 | __func__, buf, buflen, npages, args.acl_len); |
| 4551 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4552 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4553 | if (ret) |
| 4554 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4555 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4556 | /* Handle the case where the passed-in buffer is too short */ |
| 4557 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4558 | /* Did the user only issue a request for the acl length? */ |
| 4559 | if (buf == NULL) |
| 4560 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4561 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4562 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4563 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4564 | 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] | 4565 | if (buf) { |
| 4566 | if (res.acl_len > buflen) { |
| 4567 | ret = -ERANGE; |
| 4568 | goto out_free; |
| 4569 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4570 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4571 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4572 | out_ok: |
| 4573 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4574 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4575 | for (i = 0; i < npages; i++) |
| 4576 | if (pages[i]) |
| 4577 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4578 | if (res.acl_scratch) |
| 4579 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4580 | return ret; |
| 4581 | } |
| 4582 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4583 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4584 | { |
| 4585 | struct nfs4_exception exception = { }; |
| 4586 | ssize_t ret; |
| 4587 | do { |
| 4588 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4589 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4590 | if (ret >= 0) |
| 4591 | break; |
| 4592 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4593 | } while (exception.retry); |
| 4594 | return ret; |
| 4595 | } |
| 4596 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4597 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4598 | { |
| 4599 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4600 | int ret; |
| 4601 | |
| 4602 | if (!nfs4_server_supports_acls(server)) |
| 4603 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4604 | ret = nfs_revalidate_inode(server, inode); |
| 4605 | if (ret < 0) |
| 4606 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4607 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4608 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4609 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4610 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4611 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4612 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4613 | return ret; |
| 4614 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4615 | } |
| 4616 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4617 | 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] | 4618 | { |
| 4619 | struct nfs_server *server = NFS_SERVER(inode); |
| 4620 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4621 | struct nfs_setaclargs arg = { |
| 4622 | .fh = NFS_FH(inode), |
| 4623 | .acl_pages = pages, |
| 4624 | .acl_len = buflen, |
| 4625 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4626 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4627 | struct rpc_message msg = { |
| 4628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4629 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4630 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4631 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4632 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4633 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4634 | |
| 4635 | if (!nfs4_server_supports_acls(server)) |
| 4636 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4637 | if (npages > ARRAY_SIZE(pages)) |
| 4638 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4639 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4640 | if (i < 0) |
| 4641 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4642 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4643 | 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] | 4644 | |
| 4645 | /* |
| 4646 | * Free each page after tx, so the only ref left is |
| 4647 | * held by the network stack |
| 4648 | */ |
| 4649 | for (; i > 0; i--) |
| 4650 | put_page(pages[i-1]); |
| 4651 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4652 | /* |
| 4653 | * Acl update can result in inode attribute update. |
| 4654 | * so mark the attribute cache invalid. |
| 4655 | */ |
| 4656 | spin_lock(&inode->i_lock); |
| 4657 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4658 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4659 | nfs_access_zap_cache(inode); |
| 4660 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4661 | return ret; |
| 4662 | } |
| 4663 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4664 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4665 | { |
| 4666 | struct nfs4_exception exception = { }; |
| 4667 | int err; |
| 4668 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4669 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4670 | trace_nfs4_set_acl(inode, err); |
| 4671 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4672 | &exception); |
| 4673 | } while (exception.retry); |
| 4674 | return err; |
| 4675 | } |
| 4676 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4677 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4678 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4679 | size_t buflen) |
| 4680 | { |
| 4681 | struct nfs_server *server = NFS_SERVER(inode); |
| 4682 | struct nfs_fattr fattr; |
| 4683 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4684 | |
| 4685 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4686 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4687 | .fh = NFS_FH(inode), |
| 4688 | .bitmask = bitmask, |
| 4689 | }; |
| 4690 | struct nfs4_getattr_res res = { |
| 4691 | .fattr = &fattr, |
| 4692 | .label = &label, |
| 4693 | .server = server, |
| 4694 | }; |
| 4695 | struct rpc_message msg = { |
| 4696 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4697 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4698 | .rpc_resp = &res, |
| 4699 | }; |
| 4700 | int ret; |
| 4701 | |
| 4702 | nfs_fattr_init(&fattr); |
| 4703 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4704 | ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4705 | if (ret) |
| 4706 | return ret; |
| 4707 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4708 | return -ENOENT; |
| 4709 | if (buflen < label.len) |
| 4710 | return -ERANGE; |
| 4711 | return 0; |
| 4712 | } |
| 4713 | |
| 4714 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4715 | size_t buflen) |
| 4716 | { |
| 4717 | struct nfs4_exception exception = { }; |
| 4718 | int err; |
| 4719 | |
| 4720 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4721 | return -EOPNOTSUPP; |
| 4722 | |
| 4723 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4724 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4725 | trace_nfs4_get_security_label(inode, err); |
| 4726 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4727 | &exception); |
| 4728 | } while (exception.retry); |
| 4729 | return err; |
| 4730 | } |
| 4731 | |
| 4732 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4733 | struct nfs4_label *ilabel, |
| 4734 | struct nfs_fattr *fattr, |
| 4735 | struct nfs4_label *olabel) |
| 4736 | { |
| 4737 | |
| 4738 | struct iattr sattr = {0}; |
| 4739 | struct nfs_server *server = NFS_SERVER(inode); |
| 4740 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4741 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4742 | .fh = NFS_FH(inode), |
| 4743 | .iap = &sattr, |
| 4744 | .server = server, |
| 4745 | .bitmask = bitmask, |
| 4746 | .label = ilabel, |
| 4747 | }; |
| 4748 | struct nfs_setattrres res = { |
| 4749 | .fattr = fattr, |
| 4750 | .label = olabel, |
| 4751 | .server = server, |
| 4752 | }; |
| 4753 | struct rpc_message msg = { |
| 4754 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4755 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4756 | .rpc_resp = &res, |
| 4757 | }; |
| 4758 | int status; |
| 4759 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4760 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4761 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4762 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4763 | if (status) |
| 4764 | dprintk("%s failed: %d\n", __func__, status); |
| 4765 | |
| 4766 | return status; |
| 4767 | } |
| 4768 | |
| 4769 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4770 | struct nfs4_label *ilabel, |
| 4771 | struct nfs_fattr *fattr, |
| 4772 | struct nfs4_label *olabel) |
| 4773 | { |
| 4774 | struct nfs4_exception exception = { }; |
| 4775 | int err; |
| 4776 | |
| 4777 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4778 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4779 | fattr, olabel); |
| 4780 | trace_nfs4_set_security_label(inode, err); |
| 4781 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4782 | &exception); |
| 4783 | } while (exception.retry); |
| 4784 | return err; |
| 4785 | } |
| 4786 | |
| 4787 | static int |
| 4788 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4789 | { |
| 4790 | struct nfs4_label ilabel, *olabel = NULL; |
| 4791 | struct nfs_fattr fattr; |
| 4792 | struct rpc_cred *cred; |
| 4793 | struct inode *inode = dentry->d_inode; |
| 4794 | int status; |
| 4795 | |
| 4796 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4797 | return -EOPNOTSUPP; |
| 4798 | |
| 4799 | nfs_fattr_init(&fattr); |
| 4800 | |
| 4801 | ilabel.pi = 0; |
| 4802 | ilabel.lfs = 0; |
| 4803 | ilabel.label = (char *)buf; |
| 4804 | ilabel.len = buflen; |
| 4805 | |
| 4806 | cred = rpc_lookup_cred(); |
| 4807 | if (IS_ERR(cred)) |
| 4808 | return PTR_ERR(cred); |
| 4809 | |
| 4810 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4811 | if (IS_ERR(olabel)) { |
| 4812 | status = -PTR_ERR(olabel); |
| 4813 | goto out; |
| 4814 | } |
| 4815 | |
| 4816 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4817 | if (status == 0) |
| 4818 | nfs_setsecurity(inode, &fattr, olabel); |
| 4819 | |
| 4820 | nfs4_label_free(olabel); |
| 4821 | out: |
| 4822 | put_rpccred(cred); |
| 4823 | return status; |
| 4824 | } |
| 4825 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4826 | |
| 4827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | static int |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4829 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, |
| 4830 | struct nfs4_state *state, long *timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4832 | struct nfs_client *clp = server->nfs_client; |
| 4833 | |
| 4834 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | return 0; |
| 4836 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4837 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4838 | case -NFS4ERR_ADMIN_REVOKED: |
| 4839 | case -NFS4ERR_BAD_STATEID: |
| 4840 | case -NFS4ERR_OPENMODE: |
| 4841 | if (state == NULL) |
| 4842 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4843 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4844 | goto recovery_failed; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4845 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4846 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4847 | if (state != NULL) { |
| 4848 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4849 | goto recovery_failed; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4850 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4852 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4853 | nfs4_schedule_lease_recovery(clp); |
| 4854 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4855 | case -NFS4ERR_MOVED: |
| 4856 | if (nfs4_schedule_migration_recovery(server) < 0) |
| 4857 | goto recovery_failed; |
| 4858 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 4859 | case -NFS4ERR_LEASE_MOVED: |
| 4860 | nfs4_schedule_lease_moved_recovery(clp); |
| 4861 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4862 | #if defined(CONFIG_NFS_V4_1) |
| 4863 | case -NFS4ERR_BADSESSION: |
| 4864 | case -NFS4ERR_BADSLOT: |
| 4865 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4866 | case -NFS4ERR_DEADSESSION: |
| 4867 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4868 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4869 | case -NFS4ERR_SEQ_MISORDERED: |
| 4870 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4871 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4872 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4a82fd7 | 2013-11-15 16:36:16 -0500 | [diff] [blame] | 4873 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4874 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4876 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4877 | rpc_delay(task, nfs4_update_delay(timeout)); |
| 4878 | goto restart_call; |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4879 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4881 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | case -NFS4ERR_OLD_STATEID: |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4883 | goto restart_call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | } |
| 4885 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4886 | return 0; |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4887 | recovery_failed: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4888 | task->tk_status = -EIO; |
| 4889 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4890 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4891 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4892 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4893 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4894 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 4895 | goto recovery_failed; |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4896 | restart_call: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4897 | task->tk_status = 0; |
| 4898 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4901 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4902 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4903 | { |
| 4904 | __be32 verf[2]; |
| 4905 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4906 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4907 | /* An impossible timestamp guarantees this value |
| 4908 | * will never match a generated boot time. */ |
| 4909 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4910 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4911 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4912 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4913 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4914 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4915 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4916 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4917 | } |
| 4918 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4919 | static unsigned int |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4920 | nfs4_init_nonuniform_client_string(struct nfs_client *clp, |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4921 | char *buf, size_t len) |
| 4922 | { |
| 4923 | unsigned int result; |
| 4924 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4925 | if (clp->cl_owner_id != NULL) |
| 4926 | return strlcpy(buf, clp->cl_owner_id, len); |
| 4927 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4928 | rcu_read_lock(); |
| 4929 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4930 | clp->cl_ipaddr, |
| 4931 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4932 | RPC_DISPLAY_ADDR), |
| 4933 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4934 | RPC_DISPLAY_PROTO)); |
| 4935 | rcu_read_unlock(); |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4936 | clp->cl_owner_id = kstrdup(buf, GFP_KERNEL); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4937 | return result; |
| 4938 | } |
| 4939 | |
| 4940 | static unsigned int |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4941 | nfs4_init_uniform_client_string(struct nfs_client *clp, |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4942 | char *buf, size_t len) |
| 4943 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4944 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4945 | unsigned int result; |
| 4946 | |
| 4947 | if (clp->cl_owner_id != NULL) |
| 4948 | return strlcpy(buf, clp->cl_owner_id, len); |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4949 | |
| 4950 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4951 | result = scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4952 | clp->rpc_ops->version, |
| 4953 | clp->cl_minorversion, |
| 4954 | nfs4_client_id_uniquifier, |
| 4955 | nodename); |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4956 | else |
| 4957 | result = scnprintf(buf, len, "Linux NFSv%u.%u %s", |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4958 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4959 | nodename); |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame^] | 4960 | clp->cl_owner_id = kstrdup(buf, GFP_KERNEL); |
| 4961 | return result; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4962 | } |
| 4963 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 4964 | /* |
| 4965 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 4966 | * services. Advertise one based on the address family of the |
| 4967 | * clientaddr. |
| 4968 | */ |
| 4969 | static unsigned int |
| 4970 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 4971 | { |
| 4972 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 4973 | return scnprintf(buf, len, "tcp6"); |
| 4974 | else |
| 4975 | return scnprintf(buf, len, "tcp"); |
| 4976 | } |
| 4977 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 4978 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 4979 | { |
| 4980 | struct nfs4_setclientid *sc = calldata; |
| 4981 | |
| 4982 | if (task->tk_status == 0) |
| 4983 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 4984 | } |
| 4985 | |
| 4986 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 4987 | .rpc_call_done = nfs4_setclientid_done, |
| 4988 | }; |
| 4989 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4990 | /** |
| 4991 | * nfs4_proc_setclientid - Negotiate client ID |
| 4992 | * @clp: state data structure |
| 4993 | * @program: RPC program for NFSv4 callback service |
| 4994 | * @port: IP port number for NFS4 callback service |
| 4995 | * @cred: RPC credential to use for this call |
| 4996 | * @res: where to place the result |
| 4997 | * |
| 4998 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4999 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5000 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5001 | unsigned short port, struct rpc_cred *cred, |
| 5002 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | { |
| 5004 | nfs4_verifier sc_verifier; |
| 5005 | struct nfs4_setclientid setclientid = { |
| 5006 | .sc_verifier = &sc_verifier, |
| 5007 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 5008 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5009 | }; |
| 5010 | struct rpc_message msg = { |
| 5011 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5012 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5013 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5014 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5016 | struct rpc_task *task; |
| 5017 | struct rpc_task_setup task_setup_data = { |
| 5018 | .rpc_client = clp->cl_rpcclient, |
| 5019 | .rpc_message = &msg, |
| 5020 | .callback_ops = &nfs4_setclientid_ops, |
| 5021 | .callback_data = &setclientid, |
| 5022 | .flags = RPC_TASK_TIMEOUT, |
| 5023 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5024 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5026 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5027 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5028 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5029 | setclientid.sc_name_len = |
| 5030 | nfs4_init_uniform_client_string(clp, |
| 5031 | setclientid.sc_name, |
| 5032 | sizeof(setclientid.sc_name)); |
| 5033 | else |
| 5034 | setclientid.sc_name_len = |
| 5035 | nfs4_init_nonuniform_client_string(clp, |
| 5036 | setclientid.sc_name, |
| 5037 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5038 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5039 | setclientid.sc_netid_len = |
| 5040 | nfs4_init_callback_netid(clp, |
| 5041 | setclientid.sc_netid, |
| 5042 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5043 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5044 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5046 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5047 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 5048 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5049 | setclientid.sc_name_len, setclientid.sc_name); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5050 | task = rpc_run_task(&task_setup_data); |
| 5051 | if (IS_ERR(task)) { |
| 5052 | status = PTR_ERR(task); |
| 5053 | goto out; |
| 5054 | } |
| 5055 | status = task->tk_status; |
| 5056 | if (setclientid.sc_cred) { |
| 5057 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5058 | put_rpccred(setclientid.sc_cred); |
| 5059 | } |
| 5060 | rpc_put_task(task); |
| 5061 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5062 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5063 | dprintk("NFS reply setclientid: %d\n", status); |
| 5064 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | } |
| 5066 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5067 | /** |
| 5068 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5069 | * @clp: state data structure |
| 5070 | * @res: result of a previous SETCLIENTID |
| 5071 | * @cred: RPC credential to use for this call |
| 5072 | * |
| 5073 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5074 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5075 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5076 | struct nfs4_setclientid_res *arg, |
| 5077 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5078 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | struct rpc_message msg = { |
| 5080 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5081 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5082 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5084 | int status; |
| 5085 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5086 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5087 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5088 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5089 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5090 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5091 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | return status; |
| 5093 | } |
| 5094 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5095 | struct nfs4_delegreturndata { |
| 5096 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5097 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5098 | struct nfs_fh fh; |
| 5099 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5100 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5101 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5102 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5103 | struct inode *inode; |
| 5104 | bool roc; |
| 5105 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5106 | }; |
| 5107 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5108 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5109 | { |
| 5110 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5111 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5112 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5113 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5114 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5115 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5116 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5117 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5118 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5119 | case -NFS4ERR_ADMIN_REVOKED: |
| 5120 | case -NFS4ERR_DELEG_REVOKED: |
| 5121 | case -NFS4ERR_BAD_STATEID: |
| 5122 | case -NFS4ERR_OLD_STATEID: |
| 5123 | case -NFS4ERR_STALE_STATEID: |
| 5124 | case -NFS4ERR_EXPIRED: |
| 5125 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5126 | if (data->roc) |
| 5127 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5128 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5129 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5130 | if (nfs4_async_handle_error(task, data->res.server, |
| 5131 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5132 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5133 | return; |
| 5134 | } |
| 5135 | } |
| 5136 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5137 | } |
| 5138 | |
| 5139 | static void nfs4_delegreturn_release(void *calldata) |
| 5140 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5141 | struct nfs4_delegreturndata *data = calldata; |
| 5142 | |
| 5143 | if (data->roc) |
| 5144 | pnfs_roc_release(data->inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5145 | kfree(calldata); |
| 5146 | } |
| 5147 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5148 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5149 | { |
| 5150 | struct nfs4_delegreturndata *d_data; |
| 5151 | |
| 5152 | d_data = (struct nfs4_delegreturndata *)data; |
| 5153 | |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5154 | if (d_data->roc && |
| 5155 | pnfs_roc_drain(d_data->inode, &d_data->roc_barrier, task)) |
| 5156 | return; |
| 5157 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5158 | nfs4_setup_sequence(d_data->res.server, |
| 5159 | &d_data->args.seq_args, |
| 5160 | &d_data->res.seq_res, |
| 5161 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5162 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5163 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5164 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5165 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5166 | .rpc_call_done = nfs4_delegreturn_done, |
| 5167 | .rpc_release = nfs4_delegreturn_release, |
| 5168 | }; |
| 5169 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5170 | 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] | 5171 | { |
| 5172 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5173 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5174 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5175 | struct rpc_message msg = { |
| 5176 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5177 | .rpc_cred = cred, |
| 5178 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5179 | struct rpc_task_setup task_setup_data = { |
| 5180 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5181 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5182 | .callback_ops = &nfs4_delegreturn_ops, |
| 5183 | .flags = RPC_TASK_ASYNC, |
| 5184 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5185 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5186 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5187 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5188 | if (data == NULL) |
| 5189 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5190 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5191 | data->args.fhandle = &data->fh; |
| 5192 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5193 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5194 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5195 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5196 | data->res.fattr = &data->fattr; |
| 5197 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5198 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5199 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5200 | data->rpc_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5201 | data->inode = inode; |
| 5202 | data->roc = list_empty(&NFS_I(inode)->open_files) ? |
| 5203 | pnfs_roc(inode) : false; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5204 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5205 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5206 | msg.rpc_argp = &data->args; |
| 5207 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5208 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5209 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5210 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5211 | if (!issync) |
| 5212 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5213 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5214 | if (status != 0) |
| 5215 | goto out; |
| 5216 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5217 | if (status == 0) |
| 5218 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5219 | else |
| 5220 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5221 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5222 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5223 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5226 | 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] | 5227 | { |
| 5228 | struct nfs_server *server = NFS_SERVER(inode); |
| 5229 | struct nfs4_exception exception = { }; |
| 5230 | int err; |
| 5231 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5232 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5233 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | switch (err) { |
| 5235 | case -NFS4ERR_STALE_STATEID: |
| 5236 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 | case 0: |
| 5238 | return 0; |
| 5239 | } |
| 5240 | err = nfs4_handle_exception(server, err, &exception); |
| 5241 | } while (exception.retry); |
| 5242 | return err; |
| 5243 | } |
| 5244 | |
| 5245 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5246 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5247 | |
| 5248 | /* |
| 5249 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5250 | */ |
| 5251 | static unsigned long |
| 5252 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5253 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5254 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5255 | timeout <<= 1; |
| 5256 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5257 | return NFS4_LOCK_MAXTIMEOUT; |
| 5258 | return timeout; |
| 5259 | } |
| 5260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5262 | { |
| 5263 | struct inode *inode = state->inode; |
| 5264 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5265 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5266 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5267 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5268 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5270 | struct nfs_lockt_res res = { |
| 5271 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | }; |
| 5273 | struct rpc_message msg = { |
| 5274 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5275 | .rpc_argp = &arg, |
| 5276 | .rpc_resp = &res, |
| 5277 | .rpc_cred = state->owner->so_cred, |
| 5278 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | struct nfs4_lock_state *lsp; |
| 5280 | int status; |
| 5281 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5282 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5283 | status = nfs4_set_lock_state(state, request); |
| 5284 | if (status != 0) |
| 5285 | goto out; |
| 5286 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5287 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5288 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5289 | 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] | 5290 | switch (status) { |
| 5291 | case 0: |
| 5292 | request->fl_type = F_UNLCK; |
| 5293 | break; |
| 5294 | case -NFS4ERR_DENIED: |
| 5295 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5297 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5298 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5299 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5300 | return status; |
| 5301 | } |
| 5302 | |
| 5303 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5304 | { |
| 5305 | struct nfs4_exception exception = { }; |
| 5306 | int err; |
| 5307 | |
| 5308 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5309 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5310 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5311 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | &exception); |
| 5313 | } while (exception.retry); |
| 5314 | return err; |
| 5315 | } |
| 5316 | |
| 5317 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5318 | { |
| 5319 | int res = 0; |
| 5320 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5321 | case FL_POSIX: |
| 5322 | res = posix_lock_file_wait(file, fl); |
| 5323 | break; |
| 5324 | case FL_FLOCK: |
| 5325 | res = flock_lock_file_wait(file, fl); |
| 5326 | break; |
| 5327 | default: |
| 5328 | BUG(); |
| 5329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | return res; |
| 5331 | } |
| 5332 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5333 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5334 | struct nfs_locku_args arg; |
| 5335 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5336 | struct nfs4_lock_state *lsp; |
| 5337 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5338 | struct file_lock fl; |
| 5339 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5340 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5341 | }; |
| 5342 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5343 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5344 | struct nfs_open_context *ctx, |
| 5345 | struct nfs4_lock_state *lsp, |
| 5346 | struct nfs_seqid *seqid) |
| 5347 | { |
| 5348 | struct nfs4_unlockdata *p; |
| 5349 | struct inode *inode = lsp->ls_state->inode; |
| 5350 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5351 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5352 | if (p == NULL) |
| 5353 | return NULL; |
| 5354 | p->arg.fh = NFS_FH(inode); |
| 5355 | p->arg.fl = &p->fl; |
| 5356 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5357 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5358 | p->arg.stateid = &lsp->ls_stateid; |
| 5359 | p->lsp = lsp; |
| 5360 | atomic_inc(&lsp->ls_count); |
| 5361 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5362 | p->ctx = get_nfs_open_context(ctx); |
| 5363 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5364 | p->server = NFS_SERVER(inode); |
| 5365 | return p; |
| 5366 | } |
| 5367 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5368 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5369 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5370 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5371 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5372 | nfs4_put_lock_state(calldata->lsp); |
| 5373 | put_nfs_open_context(calldata->ctx); |
| 5374 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5375 | } |
| 5376 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5377 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5378 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5379 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5380 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5381 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5382 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5383 | switch (task->tk_status) { |
| 5384 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5385 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5386 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5387 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5388 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5389 | case -NFS4ERR_BAD_STATEID: |
| 5390 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5391 | case -NFS4ERR_STALE_STATEID: |
| 5392 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5393 | break; |
| 5394 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5395 | if (nfs4_async_handle_error(task, calldata->server, |
| 5396 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5397 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5398 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5399 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5400 | } |
| 5401 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5402 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5403 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5404 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5406 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5407 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5408 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5409 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5410 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5411 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5412 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5413 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5414 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5415 | &calldata->res.seq_res, |
| 5416 | task) != 0) |
| 5417 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5418 | return; |
| 5419 | out_no_action: |
| 5420 | task->tk_action = NULL; |
| 5421 | out_wait: |
| 5422 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | } |
| 5424 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5425 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5426 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5427 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5428 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5429 | }; |
| 5430 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5431 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5432 | struct nfs_open_context *ctx, |
| 5433 | struct nfs4_lock_state *lsp, |
| 5434 | struct nfs_seqid *seqid) |
| 5435 | { |
| 5436 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5437 | struct rpc_message msg = { |
| 5438 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5439 | .rpc_cred = ctx->cred, |
| 5440 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5441 | struct rpc_task_setup task_setup_data = { |
| 5442 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5443 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5444 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5445 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5446 | .flags = RPC_TASK_ASYNC, |
| 5447 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5448 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5449 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5450 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5451 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5452 | /* Ensure this is an unlock - when canceling a lock, the |
| 5453 | * canceled lock is passed in, and it won't be an unlock. |
| 5454 | */ |
| 5455 | fl->fl_type = F_UNLCK; |
| 5456 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5457 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5458 | if (data == NULL) { |
| 5459 | nfs_free_seqid(seqid); |
| 5460 | return ERR_PTR(-ENOMEM); |
| 5461 | } |
| 5462 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5463 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5464 | msg.rpc_argp = &data->arg; |
| 5465 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5466 | task_setup_data.callback_data = data; |
| 5467 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5471 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5472 | struct inode *inode = state->inode; |
| 5473 | struct nfs4_state_owner *sp = state->owner; |
| 5474 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5475 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5476 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5477 | struct rpc_task *task; |
| 5478 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5479 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5481 | status = nfs4_set_lock_state(state, request); |
| 5482 | /* Unlock _before_ we do the RPC call */ |
| 5483 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5484 | /* Exclude nfs_delegation_claim_locks() */ |
| 5485 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5486 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5487 | down_read(&nfsi->rwsem); |
| 5488 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5489 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5490 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5491 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5492 | } |
| 5493 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5494 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5495 | if (status != 0) |
| 5496 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5497 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5498 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5499 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5500 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5501 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5502 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5503 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5504 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5505 | 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] | 5506 | status = PTR_ERR(task); |
| 5507 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5508 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5509 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5510 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5511 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5512 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5513 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5514 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | } |
| 5516 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5517 | struct nfs4_lockdata { |
| 5518 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5519 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5520 | struct nfs4_lock_state *lsp; |
| 5521 | struct nfs_open_context *ctx; |
| 5522 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5523 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5524 | int rpc_status; |
| 5525 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5526 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5527 | }; |
| 5528 | |
| 5529 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5530 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5531 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5532 | { |
| 5533 | struct nfs4_lockdata *p; |
| 5534 | struct inode *inode = lsp->ls_state->inode; |
| 5535 | struct nfs_server *server = NFS_SERVER(inode); |
| 5536 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5537 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5538 | if (p == NULL) |
| 5539 | return NULL; |
| 5540 | |
| 5541 | p->arg.fh = NFS_FH(inode); |
| 5542 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5543 | 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] | 5544 | if (p->arg.open_seqid == NULL) |
| 5545 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5546 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5547 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5548 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5549 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5550 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5551 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5552 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5553 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5554 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5555 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5556 | atomic_inc(&lsp->ls_count); |
| 5557 | p->ctx = get_nfs_open_context(ctx); |
| 5558 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5559 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5560 | out_free_seqid: |
| 5561 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5562 | out_free: |
| 5563 | kfree(p); |
| 5564 | return NULL; |
| 5565 | } |
| 5566 | |
| 5567 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5568 | { |
| 5569 | struct nfs4_lockdata *data = calldata; |
| 5570 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5572 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5573 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5574 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5575 | /* Do we need to do an open_to_lock_owner? */ |
| 5576 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5577 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5578 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5579 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5580 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5581 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5582 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5583 | } else |
| 5584 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5585 | if (!nfs4_valid_open_stateid(state)) { |
| 5586 | data->rpc_status = -EBADF; |
| 5587 | task->tk_action = NULL; |
| 5588 | goto out_release_open_seqid; |
| 5589 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5590 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5591 | if (nfs4_setup_sequence(data->server, |
| 5592 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5593 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5594 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5595 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5596 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5597 | nfs_release_seqid(data->arg.open_seqid); |
| 5598 | out_release_lock_seqid: |
| 5599 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5600 | out_wait: |
| 5601 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5602 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5603 | } |
| 5604 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5605 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5606 | { |
| 5607 | struct nfs4_lockdata *data = calldata; |
| 5608 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5609 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5610 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5611 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5612 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5613 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5614 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5615 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5616 | if (data->rpc_status == 0) |
| 5617 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5618 | else |
| 5619 | goto out; |
| 5620 | } |
| 5621 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5622 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5623 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5624 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5625 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5626 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5627 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | static void nfs4_lock_release(void *calldata) |
| 5631 | { |
| 5632 | struct nfs4_lockdata *data = calldata; |
| 5633 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5634 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5635 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5636 | if (data->cancelled != 0) { |
| 5637 | struct rpc_task *task; |
| 5638 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5639 | data->arg.lock_seqid); |
| 5640 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5641 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5642 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5643 | } else |
| 5644 | nfs_free_seqid(data->arg.lock_seqid); |
| 5645 | nfs4_put_lock_state(data->lsp); |
| 5646 | put_nfs_open_context(data->ctx); |
| 5647 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5648 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5652 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5653 | .rpc_call_done = nfs4_lock_done, |
| 5654 | .rpc_release = nfs4_lock_release, |
| 5655 | }; |
| 5656 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5657 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5658 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5659 | switch (error) { |
| 5660 | case -NFS4ERR_ADMIN_REVOKED: |
| 5661 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5662 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5663 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5664 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5665 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5666 | break; |
| 5667 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5668 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5669 | case -NFS4ERR_EXPIRED: |
| 5670 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5671 | }; |
| 5672 | } |
| 5673 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5674 | 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] | 5675 | { |
| 5676 | struct nfs4_lockdata *data; |
| 5677 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5678 | struct rpc_message msg = { |
| 5679 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5680 | .rpc_cred = state->owner->so_cred, |
| 5681 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5682 | struct rpc_task_setup task_setup_data = { |
| 5683 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5684 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5685 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5686 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5687 | .flags = RPC_TASK_ASYNC, |
| 5688 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5689 | int ret; |
| 5690 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5691 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5692 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5693 | fl->fl_u.nfs4_fl.owner, |
| 5694 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5695 | if (data == NULL) |
| 5696 | return -ENOMEM; |
| 5697 | if (IS_SETLKW(cmd)) |
| 5698 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5699 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5700 | msg.rpc_argp = &data->arg; |
| 5701 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5702 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5703 | if (recovery_type > NFS_LOCK_NEW) { |
| 5704 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5705 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5706 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5707 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5708 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5709 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5710 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5711 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5712 | if (ret == 0) { |
| 5713 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5714 | if (ret) |
| 5715 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5716 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5717 | } else |
| 5718 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5719 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5720 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5721 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5725 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5726 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5727 | struct nfs4_exception exception = { |
| 5728 | .inode = state->inode, |
| 5729 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5730 | int err; |
| 5731 | |
| 5732 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5733 | /* Cache the lock if possible... */ |
| 5734 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5735 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5736 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5737 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5738 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5739 | break; |
| 5740 | nfs4_handle_exception(server, err, &exception); |
| 5741 | } while (exception.retry); |
| 5742 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5743 | } |
| 5744 | |
| 5745 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5746 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5747 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5748 | struct nfs4_exception exception = { |
| 5749 | .inode = state->inode, |
| 5750 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5751 | int err; |
| 5752 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5753 | err = nfs4_set_lock_state(state, request); |
| 5754 | if (err != 0) |
| 5755 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 5756 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5757 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 5758 | return 0; |
| 5759 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5760 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5761 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5762 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5763 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5764 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5765 | switch (err) { |
| 5766 | default: |
| 5767 | goto out; |
| 5768 | case -NFS4ERR_GRACE: |
| 5769 | case -NFS4ERR_DELAY: |
| 5770 | nfs4_handle_exception(server, err, &exception); |
| 5771 | err = 0; |
| 5772 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5773 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5774 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5775 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5776 | } |
| 5777 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5778 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5779 | /** |
| 5780 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5781 | * |
| 5782 | * @state: NFSv4 state for an inode |
| 5783 | * |
| 5784 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5785 | * Otherwise a negative NFS4ERR value is returned. |
| 5786 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5787 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5788 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5789 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5790 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5791 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5792 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5793 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5794 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5795 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5796 | |
| 5797 | status = nfs41_test_stateid(server, |
| 5798 | &lsp->ls_stateid, |
| 5799 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5800 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5801 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5802 | /* Free the stateid unless the server |
| 5803 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5804 | if (status != -NFS4ERR_BAD_STATEID) |
| 5805 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5806 | &lsp->ls_stateid, |
| 5807 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5808 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5809 | ret = status; |
| 5810 | } |
| 5811 | } |
| 5812 | }; |
| 5813 | |
| 5814 | return ret; |
| 5815 | } |
| 5816 | |
| 5817 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5818 | { |
| 5819 | int status = NFS_OK; |
| 5820 | |
| 5821 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5822 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5823 | if (status != NFS_OK) |
| 5824 | status = nfs4_lock_expired(state, request); |
| 5825 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5826 | } |
| 5827 | #endif |
| 5828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5830 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5831 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5832 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5833 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5834 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5835 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5837 | if ((fl_flags & FL_POSIX) && |
| 5838 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5839 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5840 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5841 | status = nfs4_set_lock_state(state, request); |
| 5842 | if (status != 0) |
| 5843 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5844 | request->fl_flags |= FL_ACCESS; |
| 5845 | status = do_vfs_lock(request->fl_file, request); |
| 5846 | if (status < 0) |
| 5847 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5848 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5849 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5850 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5851 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5852 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5853 | status = do_vfs_lock(request->fl_file, request); |
| 5854 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5855 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5856 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5857 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5858 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5859 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5860 | goto out; |
| 5861 | down_read(&nfsi->rwsem); |
| 5862 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5863 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5864 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5865 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5866 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5867 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5868 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5869 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5870 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5871 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5872 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5873 | out: |
| 5874 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5875 | return status; |
| 5876 | } |
| 5877 | |
| 5878 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5879 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5880 | struct nfs4_exception exception = { |
| 5881 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5882 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5883 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5884 | int err; |
| 5885 | |
| 5886 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5887 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5888 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5889 | if (err == -NFS4ERR_DENIED) |
| 5890 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5891 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5892 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | } while (exception.retry); |
| 5894 | return err; |
| 5895 | } |
| 5896 | |
| 5897 | static int |
| 5898 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5899 | { |
| 5900 | struct nfs_open_context *ctx; |
| 5901 | struct nfs4_state *state; |
| 5902 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5903 | int status; |
| 5904 | |
| 5905 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5906 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5907 | state = ctx->state; |
| 5908 | |
| 5909 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5910 | return -EINVAL; |
| 5911 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5912 | if (IS_GETLK(cmd)) { |
| 5913 | if (state != NULL) |
| 5914 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5915 | return 0; |
| 5916 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5917 | |
| 5918 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5919 | return -EINVAL; |
| 5920 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5921 | if (request->fl_type == F_UNLCK) { |
| 5922 | if (state != NULL) |
| 5923 | return nfs4_proc_unlck(state, cmd, request); |
| 5924 | return 0; |
| 5925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5927 | if (state == NULL) |
| 5928 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5929 | /* |
| 5930 | * Don't rely on the VFS having checked the file open mode, |
| 5931 | * since it won't do this for flock() locks. |
| 5932 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5933 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5934 | case F_RDLCK: |
| 5935 | if (!(filp->f_mode & FMODE_READ)) |
| 5936 | return -EBADF; |
| 5937 | break; |
| 5938 | case F_WRLCK: |
| 5939 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5940 | return -EBADF; |
| 5941 | } |
| 5942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5943 | do { |
| 5944 | status = nfs4_proc_setlk(state, cmd, request); |
| 5945 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5946 | break; |
| 5947 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5948 | status = -ERESTARTSYS; |
| 5949 | if (signalled()) |
| 5950 | break; |
| 5951 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5952 | return status; |
| 5953 | } |
| 5954 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5955 | 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] | 5956 | { |
| 5957 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5958 | int err; |
| 5959 | |
| 5960 | err = nfs4_set_lock_state(state, fl); |
| 5961 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5962 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5963 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5964 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5965 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5966 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5967 | struct nfs_release_lockowner_data { |
| 5968 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5969 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5970 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 5971 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5972 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5973 | }; |
| 5974 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5975 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 5976 | { |
| 5977 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 5978 | struct nfs_server *server = data->server; |
| 5979 | nfs40_setup_sequence(server, &data->args.seq_args, |
| 5980 | &data->res.seq_res, task); |
| 5981 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5982 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 5986 | { |
| 5987 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5988 | struct nfs_server *server = data->server; |
| 5989 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 5990 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5991 | |
| 5992 | switch (task->tk_status) { |
| 5993 | case 0: |
| 5994 | renew_lease(server, data->timestamp); |
| 5995 | break; |
| 5996 | case -NFS4ERR_STALE_CLIENTID: |
| 5997 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 5998 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5999 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6000 | case -NFS4ERR_LEASE_MOVED: |
| 6001 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6002 | if (nfs4_async_handle_error(task, server, |
| 6003 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6004 | rpc_restart_call_prepare(task); |
| 6005 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6006 | } |
| 6007 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6008 | static void nfs4_release_lockowner_release(void *calldata) |
| 6009 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6010 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6011 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6012 | kfree(calldata); |
| 6013 | } |
| 6014 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6015 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6016 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6017 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6018 | .rpc_release = nfs4_release_lockowner_release, |
| 6019 | }; |
| 6020 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6021 | static void |
| 6022 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6023 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6024 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6025 | struct rpc_message msg = { |
| 6026 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6027 | }; |
| 6028 | |
| 6029 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6030 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6031 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6032 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6033 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6034 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6035 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6036 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6037 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6038 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6039 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6040 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6041 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6042 | msg.rpc_resp = &data->res; |
| 6043 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6044 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6045 | } |
| 6046 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6047 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6048 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6049 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 6050 | const void *buf, size_t buflen, |
| 6051 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6052 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6053 | if (strcmp(key, "") != 0) |
| 6054 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6055 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6056 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6059 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 6060 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6061 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6062 | if (strcmp(key, "") != 0) |
| 6063 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6064 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6065 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6066 | } |
| 6067 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6068 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 6069 | size_t list_len, const char *name, |
| 6070 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6071 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6072 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6073 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 6074 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 6075 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6076 | |
| 6077 | if (list && len <= list_len) |
| 6078 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6079 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6080 | } |
| 6081 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6082 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 6083 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 6084 | { |
| 6085 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 6086 | } |
| 6087 | |
| 6088 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 6089 | const void *buf, size_t buflen, |
| 6090 | int flags, int type) |
| 6091 | { |
| 6092 | if (security_ismaclabel(key)) |
| 6093 | return nfs4_set_security_label(dentry, buf, buflen); |
| 6094 | |
| 6095 | return -EOPNOTSUPP; |
| 6096 | } |
| 6097 | |
| 6098 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 6099 | void *buf, size_t buflen, int type) |
| 6100 | { |
| 6101 | if (security_ismaclabel(key)) |
| 6102 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 6103 | return -EOPNOTSUPP; |
| 6104 | } |
| 6105 | |
| 6106 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 6107 | size_t list_len, const char *name, |
| 6108 | size_t name_len, int type) |
| 6109 | { |
| 6110 | size_t len = 0; |
| 6111 | |
| 6112 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 6113 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 6114 | if (list && len <= list_len) |
| 6115 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 6116 | } |
| 6117 | return len; |
| 6118 | } |
| 6119 | |
| 6120 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6121 | .prefix = XATTR_SECURITY_PREFIX, |
| 6122 | .list = nfs4_xattr_list_nfs4_label, |
| 6123 | .get = nfs4_xattr_get_nfs4_label, |
| 6124 | .set = nfs4_xattr_set_nfs4_label, |
| 6125 | }; |
| 6126 | #endif |
| 6127 | |
| 6128 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6129 | /* |
| 6130 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6131 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6132 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6133 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6134 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6135 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6136 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6137 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6138 | return; |
| 6139 | |
| 6140 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6141 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6142 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6143 | fattr->nlink = 2; |
| 6144 | } |
| 6145 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6146 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6147 | const struct qstr *name, |
| 6148 | struct nfs4_fs_locations *fs_locations, |
| 6149 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6150 | { |
| 6151 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6152 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6153 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6154 | }; |
| 6155 | struct nfs4_fs_locations_arg args = { |
| 6156 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6157 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6158 | .page = page, |
| 6159 | .bitmask = bitmask, |
| 6160 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6161 | struct nfs4_fs_locations_res res = { |
| 6162 | .fs_locations = fs_locations, |
| 6163 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6164 | struct rpc_message msg = { |
| 6165 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6166 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6167 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6168 | }; |
| 6169 | int status; |
| 6170 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6171 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6172 | |
| 6173 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6174 | * is not supported */ |
| 6175 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6176 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6177 | else |
| 6178 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6179 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6180 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6181 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6182 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6183 | 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] | 6184 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6185 | return status; |
| 6186 | } |
| 6187 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6188 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6189 | const struct qstr *name, |
| 6190 | struct nfs4_fs_locations *fs_locations, |
| 6191 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6192 | { |
| 6193 | struct nfs4_exception exception = { }; |
| 6194 | int err; |
| 6195 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6196 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6197 | fs_locations, page); |
| 6198 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6199 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6200 | &exception); |
| 6201 | } while (exception.retry); |
| 6202 | return err; |
| 6203 | } |
| 6204 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6205 | /* |
| 6206 | * This operation also signals the server that this client is |
| 6207 | * performing migration recovery. The server can stop returning |
| 6208 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6209 | * appended to this compound to identify the client ID which is |
| 6210 | * performing recovery. |
| 6211 | */ |
| 6212 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6213 | struct nfs4_fs_locations *locations, |
| 6214 | struct page *page, struct rpc_cred *cred) |
| 6215 | { |
| 6216 | struct nfs_server *server = NFS_SERVER(inode); |
| 6217 | struct rpc_clnt *clnt = server->client; |
| 6218 | u32 bitmask[2] = { |
| 6219 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6220 | }; |
| 6221 | struct nfs4_fs_locations_arg args = { |
| 6222 | .clientid = server->nfs_client->cl_clientid, |
| 6223 | .fh = NFS_FH(inode), |
| 6224 | .page = page, |
| 6225 | .bitmask = bitmask, |
| 6226 | .migration = 1, /* skip LOOKUP */ |
| 6227 | .renew = 1, /* append RENEW */ |
| 6228 | }; |
| 6229 | struct nfs4_fs_locations_res res = { |
| 6230 | .fs_locations = locations, |
| 6231 | .migration = 1, |
| 6232 | .renew = 1, |
| 6233 | }; |
| 6234 | struct rpc_message msg = { |
| 6235 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6236 | .rpc_argp = &args, |
| 6237 | .rpc_resp = &res, |
| 6238 | .rpc_cred = cred, |
| 6239 | }; |
| 6240 | unsigned long now = jiffies; |
| 6241 | int status; |
| 6242 | |
| 6243 | nfs_fattr_init(&locations->fattr); |
| 6244 | locations->server = server; |
| 6245 | locations->nlocations = 0; |
| 6246 | |
| 6247 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6248 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6249 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6250 | &args.seq_args, &res.seq_res); |
| 6251 | if (status) |
| 6252 | return status; |
| 6253 | |
| 6254 | renew_lease(server, now); |
| 6255 | return 0; |
| 6256 | } |
| 6257 | |
| 6258 | #ifdef CONFIG_NFS_V4_1 |
| 6259 | |
| 6260 | /* |
| 6261 | * This operation also signals the server that this client is |
| 6262 | * performing migration recovery. The server can stop asserting |
| 6263 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6264 | * performing this operation is identified in the SEQUENCE |
| 6265 | * operation in this compound. |
| 6266 | * |
| 6267 | * When the client supports GETATTR(fs_locations_info), it can |
| 6268 | * be plumbed in here. |
| 6269 | */ |
| 6270 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6271 | struct nfs4_fs_locations *locations, |
| 6272 | struct page *page, struct rpc_cred *cred) |
| 6273 | { |
| 6274 | struct nfs_server *server = NFS_SERVER(inode); |
| 6275 | struct rpc_clnt *clnt = server->client; |
| 6276 | u32 bitmask[2] = { |
| 6277 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6278 | }; |
| 6279 | struct nfs4_fs_locations_arg args = { |
| 6280 | .fh = NFS_FH(inode), |
| 6281 | .page = page, |
| 6282 | .bitmask = bitmask, |
| 6283 | .migration = 1, /* skip LOOKUP */ |
| 6284 | }; |
| 6285 | struct nfs4_fs_locations_res res = { |
| 6286 | .fs_locations = locations, |
| 6287 | .migration = 1, |
| 6288 | }; |
| 6289 | struct rpc_message msg = { |
| 6290 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6291 | .rpc_argp = &args, |
| 6292 | .rpc_resp = &res, |
| 6293 | .rpc_cred = cred, |
| 6294 | }; |
| 6295 | int status; |
| 6296 | |
| 6297 | nfs_fattr_init(&locations->fattr); |
| 6298 | locations->server = server; |
| 6299 | locations->nlocations = 0; |
| 6300 | |
| 6301 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6302 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6303 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6304 | &args.seq_args, &res.seq_res); |
| 6305 | if (status == NFS4_OK && |
| 6306 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6307 | status = -NFS4ERR_LEASE_MOVED; |
| 6308 | return status; |
| 6309 | } |
| 6310 | |
| 6311 | #endif /* CONFIG_NFS_V4_1 */ |
| 6312 | |
| 6313 | /** |
| 6314 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6315 | * @inode: inode on FSID that is migrating |
| 6316 | * @locations: result of query |
| 6317 | * @page: buffer |
| 6318 | * @cred: credential to use for this operation |
| 6319 | * |
| 6320 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6321 | * operation failed, or a negative errno if a local error occurred. |
| 6322 | * |
| 6323 | * On success, "locations" is filled in, but if the server has |
| 6324 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6325 | * asserted. |
| 6326 | * |
| 6327 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6328 | * from this client that require migration recovery. |
| 6329 | */ |
| 6330 | int nfs4_proc_get_locations(struct inode *inode, |
| 6331 | struct nfs4_fs_locations *locations, |
| 6332 | struct page *page, struct rpc_cred *cred) |
| 6333 | { |
| 6334 | struct nfs_server *server = NFS_SERVER(inode); |
| 6335 | struct nfs_client *clp = server->nfs_client; |
| 6336 | const struct nfs4_mig_recovery_ops *ops = |
| 6337 | clp->cl_mvops->mig_recovery_ops; |
| 6338 | struct nfs4_exception exception = { }; |
| 6339 | int status; |
| 6340 | |
| 6341 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6342 | (unsigned long long)server->fsid.major, |
| 6343 | (unsigned long long)server->fsid.minor, |
| 6344 | clp->cl_hostname); |
| 6345 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6346 | |
| 6347 | do { |
| 6348 | status = ops->get_locations(inode, locations, page, cred); |
| 6349 | if (status != -NFS4ERR_DELAY) |
| 6350 | break; |
| 6351 | nfs4_handle_exception(server, status, &exception); |
| 6352 | } while (exception.retry); |
| 6353 | return status; |
| 6354 | } |
| 6355 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6356 | /* |
| 6357 | * This operation also signals the server that this client is |
| 6358 | * performing "lease moved" recovery. The server can stop |
| 6359 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6360 | * is appended to this compound to identify the client ID which is |
| 6361 | * performing recovery. |
| 6362 | */ |
| 6363 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6364 | { |
| 6365 | struct nfs_server *server = NFS_SERVER(inode); |
| 6366 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6367 | struct rpc_clnt *clnt = server->client; |
| 6368 | struct nfs4_fsid_present_arg args = { |
| 6369 | .fh = NFS_FH(inode), |
| 6370 | .clientid = clp->cl_clientid, |
| 6371 | .renew = 1, /* append RENEW */ |
| 6372 | }; |
| 6373 | struct nfs4_fsid_present_res res = { |
| 6374 | .renew = 1, |
| 6375 | }; |
| 6376 | struct rpc_message msg = { |
| 6377 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6378 | .rpc_argp = &args, |
| 6379 | .rpc_resp = &res, |
| 6380 | .rpc_cred = cred, |
| 6381 | }; |
| 6382 | unsigned long now = jiffies; |
| 6383 | int status; |
| 6384 | |
| 6385 | res.fh = nfs_alloc_fhandle(); |
| 6386 | if (res.fh == NULL) |
| 6387 | return -ENOMEM; |
| 6388 | |
| 6389 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6390 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6391 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6392 | &args.seq_args, &res.seq_res); |
| 6393 | nfs_free_fhandle(res.fh); |
| 6394 | if (status) |
| 6395 | return status; |
| 6396 | |
| 6397 | do_renew_lease(clp, now); |
| 6398 | return 0; |
| 6399 | } |
| 6400 | |
| 6401 | #ifdef CONFIG_NFS_V4_1 |
| 6402 | |
| 6403 | /* |
| 6404 | * This operation also signals the server that this client is |
| 6405 | * performing "lease moved" recovery. The server can stop asserting |
| 6406 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6407 | * this operation is identified in the SEQUENCE operation in this |
| 6408 | * compound. |
| 6409 | */ |
| 6410 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6411 | { |
| 6412 | struct nfs_server *server = NFS_SERVER(inode); |
| 6413 | struct rpc_clnt *clnt = server->client; |
| 6414 | struct nfs4_fsid_present_arg args = { |
| 6415 | .fh = NFS_FH(inode), |
| 6416 | }; |
| 6417 | struct nfs4_fsid_present_res res = { |
| 6418 | }; |
| 6419 | struct rpc_message msg = { |
| 6420 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6421 | .rpc_argp = &args, |
| 6422 | .rpc_resp = &res, |
| 6423 | .rpc_cred = cred, |
| 6424 | }; |
| 6425 | int status; |
| 6426 | |
| 6427 | res.fh = nfs_alloc_fhandle(); |
| 6428 | if (res.fh == NULL) |
| 6429 | return -ENOMEM; |
| 6430 | |
| 6431 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6432 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6433 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6434 | &args.seq_args, &res.seq_res); |
| 6435 | nfs_free_fhandle(res.fh); |
| 6436 | if (status == NFS4_OK && |
| 6437 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6438 | status = -NFS4ERR_LEASE_MOVED; |
| 6439 | return status; |
| 6440 | } |
| 6441 | |
| 6442 | #endif /* CONFIG_NFS_V4_1 */ |
| 6443 | |
| 6444 | /** |
| 6445 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6446 | * @inode: inode on FSID to check |
| 6447 | * @cred: credential to use for this operation |
| 6448 | * |
| 6449 | * Server indicates whether the FSID is present, moved, or not |
| 6450 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6451 | * condition for this client ID. |
| 6452 | * |
| 6453 | * Returns NFS4_OK if the FSID is present on this server, |
| 6454 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6455 | * NFS4ERR code if some error occurred on the server, or a |
| 6456 | * negative errno if a local failure occurred. |
| 6457 | */ |
| 6458 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6459 | { |
| 6460 | struct nfs_server *server = NFS_SERVER(inode); |
| 6461 | struct nfs_client *clp = server->nfs_client; |
| 6462 | const struct nfs4_mig_recovery_ops *ops = |
| 6463 | clp->cl_mvops->mig_recovery_ops; |
| 6464 | struct nfs4_exception exception = { }; |
| 6465 | int status; |
| 6466 | |
| 6467 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6468 | (unsigned long long)server->fsid.major, |
| 6469 | (unsigned long long)server->fsid.minor, |
| 6470 | clp->cl_hostname); |
| 6471 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6472 | |
| 6473 | do { |
| 6474 | status = ops->fsid_present(inode, cred); |
| 6475 | if (status != -NFS4ERR_DELAY) |
| 6476 | break; |
| 6477 | nfs4_handle_exception(server, status, &exception); |
| 6478 | } while (exception.retry); |
| 6479 | return status; |
| 6480 | } |
| 6481 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6482 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6483 | * If 'use_integrity' is true and the state managment nfs_client |
| 6484 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6485 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6486 | * Considerations sections. Otherwise, just use the user cred with the |
| 6487 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6488 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6489 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6490 | { |
| 6491 | int status; |
| 6492 | struct nfs4_secinfo_arg args = { |
| 6493 | .dir_fh = NFS_FH(dir), |
| 6494 | .name = name, |
| 6495 | }; |
| 6496 | struct nfs4_secinfo_res res = { |
| 6497 | .flavors = flavors, |
| 6498 | }; |
| 6499 | struct rpc_message msg = { |
| 6500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6501 | .rpc_argp = &args, |
| 6502 | .rpc_resp = &res, |
| 6503 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6504 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6505 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6506 | |
| 6507 | if (use_integrity) { |
| 6508 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6509 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6510 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6511 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6512 | |
| 6513 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6514 | |
| 6515 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6516 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6517 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6518 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6519 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6520 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6521 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6522 | if (cred) |
| 6523 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6524 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6525 | return status; |
| 6526 | } |
| 6527 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6528 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6529 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6530 | { |
| 6531 | struct nfs4_exception exception = { }; |
| 6532 | int err; |
| 6533 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6534 | err = -NFS4ERR_WRONGSEC; |
| 6535 | |
| 6536 | /* try to use integrity protection with machine cred */ |
| 6537 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6538 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6539 | |
| 6540 | /* |
| 6541 | * if unable to use integrity protection, or SECINFO with |
| 6542 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6543 | * disallowed by spec, but exists in deployed servers) use |
| 6544 | * the current filesystem's rpc_client and the user cred. |
| 6545 | */ |
| 6546 | if (err == -NFS4ERR_WRONGSEC) |
| 6547 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6548 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6549 | trace_nfs4_secinfo(dir, name, err); |
| 6550 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6551 | &exception); |
| 6552 | } while (exception.retry); |
| 6553 | return err; |
| 6554 | } |
| 6555 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6556 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6557 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6558 | * Check the exchange flags returned by the server for invalid flags, having |
| 6559 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6560 | * DS flags set. |
| 6561 | */ |
| 6562 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6563 | { |
| 6564 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6565 | goto out_inval; |
| 6566 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6567 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6568 | goto out_inval; |
| 6569 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6570 | goto out_inval; |
| 6571 | return NFS_OK; |
| 6572 | out_inval: |
| 6573 | return -NFS4ERR_INVAL; |
| 6574 | } |
| 6575 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6576 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6577 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6578 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6579 | { |
| 6580 | if (a->server_scope_sz == b->server_scope_sz && |
| 6581 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6582 | return true; |
| 6583 | |
| 6584 | return false; |
| 6585 | } |
| 6586 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6587 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6588 | * nfs4_proc_bind_conn_to_session() |
| 6589 | * |
| 6590 | * The 4.1 client currently uses the same TCP connection for the |
| 6591 | * fore and backchannel. |
| 6592 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6593 | 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] | 6594 | { |
| 6595 | int status; |
| 6596 | struct nfs41_bind_conn_to_session_res res; |
| 6597 | struct rpc_message msg = { |
| 6598 | .rpc_proc = |
| 6599 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 6600 | .rpc_argp = clp, |
| 6601 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6602 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6603 | }; |
| 6604 | |
| 6605 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6606 | |
| 6607 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 6608 | if (unlikely(res.session == NULL)) { |
| 6609 | status = -ENOMEM; |
| 6610 | goto out; |
| 6611 | } |
| 6612 | |
| 6613 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6614 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6615 | if (status == 0) { |
| 6616 | if (memcmp(res.session->sess_id.data, |
| 6617 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6618 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6619 | status = -EIO; |
| 6620 | goto out_session; |
| 6621 | } |
| 6622 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 6623 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6624 | __func__); |
| 6625 | status = -EIO; |
| 6626 | goto out_session; |
| 6627 | } |
| 6628 | if (res.use_conn_in_rdma_mode) { |
| 6629 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6630 | __func__); |
| 6631 | status = -EIO; |
| 6632 | goto out_session; |
| 6633 | } |
| 6634 | } |
| 6635 | out_session: |
| 6636 | kfree(res.session); |
| 6637 | out: |
| 6638 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6639 | return status; |
| 6640 | } |
| 6641 | |
| 6642 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6643 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6644 | * and operations we'd like to see to enable certain features in the allow map |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6645 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6646 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6647 | .how = SP4_MACH_CRED, |
| 6648 | .enforce.u.words = { |
| 6649 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6650 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6651 | 1 << (OP_CREATE_SESSION - 32) | |
| 6652 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6653 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6654 | }, |
| 6655 | .allow.u.words = { |
| 6656 | [0] = 1 << (OP_CLOSE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6657 | 1 << (OP_LOCKU) | |
| 6658 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6659 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6660 | 1 << (OP_SECINFO_NO_NAME - 32) | |
| 6661 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6662 | 1 << (OP_FREE_STATEID - 32) | |
| 6663 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6664 | } |
| 6665 | }; |
| 6666 | |
| 6667 | /* |
| 6668 | * Select the state protection mode for client `clp' given the server results |
| 6669 | * from exchange_id in `sp'. |
| 6670 | * |
| 6671 | * Returns 0 on success, negative errno otherwise. |
| 6672 | */ |
| 6673 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6674 | struct nfs41_state_protection *sp) |
| 6675 | { |
| 6676 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6677 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6678 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6679 | 1 << (OP_CREATE_SESSION - 32) | |
| 6680 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6681 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6682 | }; |
| 6683 | unsigned int i; |
| 6684 | |
| 6685 | if (sp->how == SP4_MACH_CRED) { |
| 6686 | /* Print state protect result */ |
| 6687 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6688 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6689 | if (test_bit(i, sp->enforce.u.longs)) |
| 6690 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6691 | if (test_bit(i, sp->allow.u.longs)) |
| 6692 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6693 | } |
| 6694 | |
| 6695 | /* make sure nothing is on enforce list that isn't supported */ |
| 6696 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6697 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6698 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6699 | return -EINVAL; |
| 6700 | } |
| 6701 | } |
| 6702 | |
| 6703 | /* |
| 6704 | * Minimal mode - state operations are allowed to use machine |
| 6705 | * credential. Note this already happens by default, so the |
| 6706 | * client doesn't have to do anything more than the negotiation. |
| 6707 | * |
| 6708 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6709 | * we're already using the machine cred for exchange_id |
| 6710 | * and will never use a different cred. |
| 6711 | */ |
| 6712 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6713 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6714 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6715 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6716 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6717 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6718 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 6719 | } else { |
| 6720 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6721 | return -EINVAL; |
| 6722 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6723 | |
| 6724 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
| 6725 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 6726 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 6727 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 6728 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6729 | |
| 6730 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 6731 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 6732 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 6733 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 6734 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6735 | |
| 6736 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 6737 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 6738 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 6739 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 6740 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6741 | |
| 6742 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 6743 | dfprintk(MOUNT, " write mode enabled\n"); |
| 6744 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 6745 | } |
| 6746 | |
| 6747 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 6748 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 6749 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 6750 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | return 0; |
| 6754 | } |
| 6755 | |
| 6756 | /* |
| 6757 | * _nfs4_proc_exchange_id() |
| 6758 | * |
| 6759 | * Wrapper for EXCHANGE_ID operation. |
| 6760 | */ |
| 6761 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 6762 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6763 | { |
| 6764 | nfs4_verifier verifier; |
| 6765 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6766 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6767 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6768 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6769 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6770 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 6771 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 6772 | #else |
| 6773 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 6774 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 6775 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6776 | }; |
| 6777 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6778 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6779 | }; |
| 6780 | int status; |
| 6781 | struct rpc_message msg = { |
| 6782 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 6783 | .rpc_argp = &args, |
| 6784 | .rpc_resp = &res, |
| 6785 | .rpc_cred = cred, |
| 6786 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6787 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6788 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6789 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 6790 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6791 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 6792 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6793 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6794 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6795 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6796 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6797 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6798 | status = -ENOMEM; |
| 6799 | goto out; |
| 6800 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6801 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6802 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6803 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6804 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6805 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6806 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6807 | } |
| 6808 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6809 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6810 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6811 | status = -ENOMEM; |
| 6812 | goto out_server_scope; |
| 6813 | } |
| 6814 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6815 | switch (sp4_how) { |
| 6816 | case SP4_NONE: |
| 6817 | args.state_protect.how = SP4_NONE; |
| 6818 | break; |
| 6819 | |
| 6820 | case SP4_MACH_CRED: |
| 6821 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 6822 | break; |
| 6823 | |
| 6824 | default: |
| 6825 | /* unsupported! */ |
| 6826 | WARN_ON_ONCE(1); |
| 6827 | status = -EINVAL; |
| 6828 | goto out_server_scope; |
| 6829 | } |
| 6830 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6831 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6832 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6833 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6834 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6835 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6836 | if (status == 0) |
| 6837 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 6838 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6839 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6840 | clp->cl_clientid = res.clientid; |
| 6841 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 6842 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 6843 | clp->cl_seqid = res.seqid; |
| 6844 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6845 | kfree(clp->cl_serverowner); |
| 6846 | clp->cl_serverowner = res.server_owner; |
| 6847 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6848 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6849 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6850 | kfree(clp->cl_implid); |
| 6851 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6852 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6853 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6854 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6855 | res.server_scope)) { |
| 6856 | dprintk("%s: server_scope mismatch detected\n", |
| 6857 | __func__); |
| 6858 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6859 | kfree(clp->cl_serverscope); |
| 6860 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6861 | } |
| 6862 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6863 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6864 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6865 | goto out; |
| 6866 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6867 | } else |
| 6868 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6869 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6870 | out_server_owner: |
| 6871 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6872 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6873 | kfree(res.server_scope); |
| 6874 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6875 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6876 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6877 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6878 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6879 | clp->cl_implid->date.seconds, |
| 6880 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6881 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6882 | return status; |
| 6883 | } |
| 6884 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6885 | /* |
| 6886 | * nfs4_proc_exchange_id() |
| 6887 | * |
| 6888 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6889 | * |
| 6890 | * Since the clientid has expired, all compounds using sessions |
| 6891 | * associated with the stale clientid will be returning |
| 6892 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 6893 | * be in some phase of session reset. |
| 6894 | * |
| 6895 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 6896 | */ |
| 6897 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 6898 | { |
| 6899 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 6900 | int status; |
| 6901 | |
| 6902 | /* try SP4_MACH_CRED if krb5i/p */ |
| 6903 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 6904 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 6905 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 6906 | if (!status) |
| 6907 | return 0; |
| 6908 | } |
| 6909 | |
| 6910 | /* try SP4_NONE */ |
| 6911 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 6912 | } |
| 6913 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6914 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6915 | struct rpc_cred *cred) |
| 6916 | { |
| 6917 | struct rpc_message msg = { |
| 6918 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6919 | .rpc_argp = clp, |
| 6920 | .rpc_cred = cred, |
| 6921 | }; |
| 6922 | int status; |
| 6923 | |
| 6924 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6925 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6926 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6927 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6928 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6929 | return status; |
| 6930 | } |
| 6931 | |
| 6932 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6933 | struct rpc_cred *cred) |
| 6934 | { |
| 6935 | unsigned int loop; |
| 6936 | int ret; |
| 6937 | |
| 6938 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6939 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6940 | switch (ret) { |
| 6941 | case -NFS4ERR_DELAY: |
| 6942 | case -NFS4ERR_CLIENTID_BUSY: |
| 6943 | ssleep(1); |
| 6944 | break; |
| 6945 | default: |
| 6946 | return ret; |
| 6947 | } |
| 6948 | } |
| 6949 | return 0; |
| 6950 | } |
| 6951 | |
| 6952 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6953 | { |
| 6954 | struct rpc_cred *cred; |
| 6955 | int ret = 0; |
| 6956 | |
| 6957 | if (clp->cl_mvops->minor_version < 1) |
| 6958 | goto out; |
| 6959 | if (clp->cl_exchange_flags == 0) |
| 6960 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6961 | if (clp->cl_preserve_clid) |
| 6962 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6963 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6964 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6965 | if (cred) |
| 6966 | put_rpccred(cred); |
| 6967 | switch (ret) { |
| 6968 | case 0: |
| 6969 | case -NFS4ERR_STALE_CLIENTID: |
| 6970 | clp->cl_exchange_flags = 0; |
| 6971 | } |
| 6972 | out: |
| 6973 | return ret; |
| 6974 | } |
| 6975 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6976 | struct nfs4_get_lease_time_data { |
| 6977 | struct nfs4_get_lease_time_args *args; |
| 6978 | struct nfs4_get_lease_time_res *res; |
| 6979 | struct nfs_client *clp; |
| 6980 | }; |
| 6981 | |
| 6982 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6983 | void *calldata) |
| 6984 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6985 | struct nfs4_get_lease_time_data *data = |
| 6986 | (struct nfs4_get_lease_time_data *)calldata; |
| 6987 | |
| 6988 | dprintk("--> %s\n", __func__); |
| 6989 | /* just setup sequence, do not trigger session recovery |
| 6990 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6991 | nfs41_setup_sequence(data->clp->cl_session, |
| 6992 | &data->args->la_seq_args, |
| 6993 | &data->res->lr_seq_res, |
| 6994 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6995 | dprintk("<-- %s\n", __func__); |
| 6996 | } |
| 6997 | |
| 6998 | /* |
| 6999 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7000 | * from sequence operation or clientid errors. |
| 7001 | */ |
| 7002 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7003 | { |
| 7004 | struct nfs4_get_lease_time_data *data = |
| 7005 | (struct nfs4_get_lease_time_data *)calldata; |
| 7006 | |
| 7007 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7008 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7009 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7010 | switch (task->tk_status) { |
| 7011 | case -NFS4ERR_DELAY: |
| 7012 | case -NFS4ERR_GRACE: |
| 7013 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7014 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7015 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7016 | /* fall through */ |
| 7017 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7018 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7019 | return; |
| 7020 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7021 | dprintk("<-- %s\n", __func__); |
| 7022 | } |
| 7023 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7024 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7025 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7026 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7027 | }; |
| 7028 | |
| 7029 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7030 | { |
| 7031 | struct rpc_task *task; |
| 7032 | struct nfs4_get_lease_time_args args; |
| 7033 | struct nfs4_get_lease_time_res res = { |
| 7034 | .lr_fsinfo = fsinfo, |
| 7035 | }; |
| 7036 | struct nfs4_get_lease_time_data data = { |
| 7037 | .args = &args, |
| 7038 | .res = &res, |
| 7039 | .clp = clp, |
| 7040 | }; |
| 7041 | struct rpc_message msg = { |
| 7042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7043 | .rpc_argp = &args, |
| 7044 | .rpc_resp = &res, |
| 7045 | }; |
| 7046 | struct rpc_task_setup task_setup = { |
| 7047 | .rpc_client = clp->cl_rpcclient, |
| 7048 | .rpc_message = &msg, |
| 7049 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7050 | .callback_data = &data, |
| 7051 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7052 | }; |
| 7053 | int status; |
| 7054 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7055 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7056 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7057 | dprintk("--> %s\n", __func__); |
| 7058 | task = rpc_run_task(&task_setup); |
| 7059 | |
| 7060 | if (IS_ERR(task)) |
| 7061 | status = PTR_ERR(task); |
| 7062 | else { |
| 7063 | status = task->tk_status; |
| 7064 | rpc_put_task(task); |
| 7065 | } |
| 7066 | dprintk("<-- %s return %d\n", __func__, status); |
| 7067 | |
| 7068 | return status; |
| 7069 | } |
| 7070 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7071 | /* |
| 7072 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7073 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7074 | * use them. |
| 7075 | * |
| 7076 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7077 | * always set csa_cachethis to FALSE because the current implementation |
| 7078 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7079 | */ |
| 7080 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 7081 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7082 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7083 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7084 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7085 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7086 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7087 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7088 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7089 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7090 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7091 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7092 | |
| 7093 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7094 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7095 | __func__, |
| 7096 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7097 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7098 | |
| 7099 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7100 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 7101 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 7102 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7103 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 7104 | args->bc_attrs.max_reqs = 1; |
| 7105 | |
| 7106 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7107 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7108 | __func__, |
| 7109 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7110 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7111 | args->bc_attrs.max_reqs); |
| 7112 | } |
| 7113 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7114 | 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] | 7115 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7116 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 7117 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 7118 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7119 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7120 | return -EINVAL; |
| 7121 | /* |
| 7122 | * Our requested max_ops is the minimum we need; we're not |
| 7123 | * prepared to break up compounds into smaller pieces than that. |
| 7124 | * So, no point even trying to continue if the server won't |
| 7125 | * cooperate: |
| 7126 | */ |
| 7127 | if (rcvd->max_ops < sent->max_ops) |
| 7128 | return -EINVAL; |
| 7129 | if (rcvd->max_reqs == 0) |
| 7130 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7131 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7132 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7133 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7134 | } |
| 7135 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7136 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 7137 | { |
| 7138 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 7139 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7140 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7141 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7142 | return -EINVAL; |
| 7143 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7144 | return -EINVAL; |
| 7145 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7146 | return -EINVAL; |
| 7147 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7148 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7149 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7150 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7151 | return -EINVAL; |
| 7152 | return 0; |
| 7153 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7154 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7155 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 7156 | struct nfs4_session *session) |
| 7157 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7158 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7159 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7160 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 7161 | if (ret) |
| 7162 | return ret; |
| 7163 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7164 | } |
| 7165 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7166 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7167 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7168 | { |
| 7169 | struct nfs4_session *session = clp->cl_session; |
| 7170 | struct nfs41_create_session_args args = { |
| 7171 | .client = clp, |
| 7172 | .cb_program = NFS4_CALLBACK, |
| 7173 | }; |
| 7174 | struct nfs41_create_session_res res = { |
| 7175 | .client = clp, |
| 7176 | }; |
| 7177 | struct rpc_message msg = { |
| 7178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7179 | .rpc_argp = &args, |
| 7180 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7181 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7182 | }; |
| 7183 | int status; |
| 7184 | |
| 7185 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7186 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7187 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7188 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7189 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7190 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7191 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7192 | /* Verify the session's negotiated channel_attrs values */ |
| 7193 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7194 | /* Increment the clientid slot sequence id */ |
| 7195 | clp->cl_seqid++; |
| 7196 | } |
| 7197 | |
| 7198 | return status; |
| 7199 | } |
| 7200 | |
| 7201 | /* |
| 7202 | * Issues a CREATE_SESSION operation to the server. |
| 7203 | * It is the responsibility of the caller to verify the session is |
| 7204 | * expired before calling this routine. |
| 7205 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7206 | 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] | 7207 | { |
| 7208 | int status; |
| 7209 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7210 | struct nfs4_session *session = clp->cl_session; |
| 7211 | |
| 7212 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7213 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7214 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7215 | if (status) |
| 7216 | goto out; |
| 7217 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7218 | /* Init or reset the session slot tables */ |
| 7219 | status = nfs4_setup_session_slot_tables(session); |
| 7220 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7221 | if (status) |
| 7222 | goto out; |
| 7223 | |
| 7224 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7225 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7226 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7227 | out: |
| 7228 | dprintk("<-- %s\n", __func__); |
| 7229 | return status; |
| 7230 | } |
| 7231 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7232 | /* |
| 7233 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7234 | * The caller must serialize access to this routine. |
| 7235 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7236 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7237 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7238 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7239 | struct rpc_message msg = { |
| 7240 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7241 | .rpc_argp = session, |
| 7242 | .rpc_cred = cred, |
| 7243 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7244 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7245 | |
| 7246 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7247 | |
| 7248 | /* session is still being setup */ |
| 7249 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 7250 | return status; |
| 7251 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7252 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7253 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7254 | |
| 7255 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7256 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7257 | "Session has been destroyed regardless...\n", status); |
| 7258 | |
| 7259 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7260 | return status; |
| 7261 | } |
| 7262 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7263 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7264 | * Renew the cl_session lease. |
| 7265 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7266 | struct nfs4_sequence_data { |
| 7267 | struct nfs_client *clp; |
| 7268 | struct nfs4_sequence_args args; |
| 7269 | struct nfs4_sequence_res res; |
| 7270 | }; |
| 7271 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7272 | static void nfs41_sequence_release(void *data) |
| 7273 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7274 | struct nfs4_sequence_data *calldata = data; |
| 7275 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7276 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7277 | if (atomic_read(&clp->cl_count) > 1) |
| 7278 | nfs4_schedule_state_renewal(clp); |
| 7279 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7280 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7281 | } |
| 7282 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7283 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7284 | { |
| 7285 | switch(task->tk_status) { |
| 7286 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7287 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7288 | return -EAGAIN; |
| 7289 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7290 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7291 | } |
| 7292 | return 0; |
| 7293 | } |
| 7294 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7295 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7296 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7297 | struct nfs4_sequence_data *calldata = data; |
| 7298 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7299 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7300 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7301 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7302 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7303 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7304 | if (task->tk_status < 0) { |
| 7305 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7306 | if (atomic_read(&clp->cl_count) == 1) |
| 7307 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7308 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7309 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7310 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7311 | return; |
| 7312 | } |
| 7313 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7314 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7315 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7316 | dprintk("<-- %s\n", __func__); |
| 7317 | } |
| 7318 | |
| 7319 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7320 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7321 | struct nfs4_sequence_data *calldata = data; |
| 7322 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7323 | struct nfs4_sequence_args *args; |
| 7324 | struct nfs4_sequence_res *res; |
| 7325 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7326 | args = task->tk_msg.rpc_argp; |
| 7327 | res = task->tk_msg.rpc_resp; |
| 7328 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7329 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7330 | } |
| 7331 | |
| 7332 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7333 | .rpc_call_done = nfs41_sequence_call_done, |
| 7334 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7335 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7336 | }; |
| 7337 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7338 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7339 | struct rpc_cred *cred, |
| 7340 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7341 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7342 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7343 | struct rpc_message msg = { |
| 7344 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7345 | .rpc_cred = cred, |
| 7346 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7347 | struct rpc_task_setup task_setup_data = { |
| 7348 | .rpc_client = clp->cl_rpcclient, |
| 7349 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7350 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7351 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7352 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7353 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7354 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7355 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7356 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7357 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7358 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7359 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7360 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7361 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7362 | if (is_privileged) |
| 7363 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7364 | msg.rpc_argp = &calldata->args; |
| 7365 | msg.rpc_resp = &calldata->res; |
| 7366 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7367 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7368 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7369 | return rpc_run_task(&task_setup_data); |
| 7370 | } |
| 7371 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7372 | 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] | 7373 | { |
| 7374 | struct rpc_task *task; |
| 7375 | int ret = 0; |
| 7376 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7377 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7378 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7379 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7380 | if (IS_ERR(task)) |
| 7381 | ret = PTR_ERR(task); |
| 7382 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7383 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7384 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7385 | return ret; |
| 7386 | } |
| 7387 | |
| 7388 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7389 | { |
| 7390 | struct rpc_task *task; |
| 7391 | int ret; |
| 7392 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7393 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7394 | if (IS_ERR(task)) { |
| 7395 | ret = PTR_ERR(task); |
| 7396 | goto out; |
| 7397 | } |
| 7398 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7399 | if (!ret) { |
| 7400 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 7401 | |
| 7402 | if (task->tk_status == 0) |
| 7403 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7404 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7405 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7406 | rpc_put_task(task); |
| 7407 | out: |
| 7408 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7409 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7410 | } |
| 7411 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7412 | struct nfs4_reclaim_complete_data { |
| 7413 | struct nfs_client *clp; |
| 7414 | struct nfs41_reclaim_complete_args arg; |
| 7415 | struct nfs41_reclaim_complete_res res; |
| 7416 | }; |
| 7417 | |
| 7418 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7419 | { |
| 7420 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7421 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7422 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7423 | &calldata->arg.seq_args, |
| 7424 | &calldata->res.seq_res, |
| 7425 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7426 | } |
| 7427 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7428 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7429 | { |
| 7430 | switch(task->tk_status) { |
| 7431 | case 0: |
| 7432 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7433 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7434 | break; |
| 7435 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7436 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7437 | /* fall through */ |
| 7438 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7439 | return -EAGAIN; |
| 7440 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7441 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7442 | } |
| 7443 | return 0; |
| 7444 | } |
| 7445 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7446 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7447 | { |
| 7448 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7449 | struct nfs_client *clp = calldata->clp; |
| 7450 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7451 | |
| 7452 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7453 | if (!nfs41_sequence_done(task, res)) |
| 7454 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7455 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7456 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7457 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7458 | rpc_restart_call_prepare(task); |
| 7459 | return; |
| 7460 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7461 | dprintk("<-- %s\n", __func__); |
| 7462 | } |
| 7463 | |
| 7464 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7465 | { |
| 7466 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7467 | |
| 7468 | kfree(calldata); |
| 7469 | } |
| 7470 | |
| 7471 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7472 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7473 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7474 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7475 | }; |
| 7476 | |
| 7477 | /* |
| 7478 | * Issue a global reclaim complete. |
| 7479 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7480 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7481 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7482 | { |
| 7483 | struct nfs4_reclaim_complete_data *calldata; |
| 7484 | struct rpc_task *task; |
| 7485 | struct rpc_message msg = { |
| 7486 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7487 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7488 | }; |
| 7489 | struct rpc_task_setup task_setup_data = { |
| 7490 | .rpc_client = clp->cl_rpcclient, |
| 7491 | .rpc_message = &msg, |
| 7492 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7493 | .flags = RPC_TASK_ASYNC, |
| 7494 | }; |
| 7495 | int status = -ENOMEM; |
| 7496 | |
| 7497 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7498 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7499 | if (calldata == NULL) |
| 7500 | goto out; |
| 7501 | calldata->clp = clp; |
| 7502 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7503 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7504 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7505 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7506 | msg.rpc_argp = &calldata->arg; |
| 7507 | msg.rpc_resp = &calldata->res; |
| 7508 | task_setup_data.callback_data = calldata; |
| 7509 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7510 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7511 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7512 | goto out; |
| 7513 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7514 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7515 | if (status == 0) |
| 7516 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7517 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7518 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7519 | out: |
| 7520 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7521 | return status; |
| 7522 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7523 | |
| 7524 | static void |
| 7525 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7526 | { |
| 7527 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7528 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7529 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7530 | |
| 7531 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7532 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 7533 | * right now covering the LAYOUTGET we are about to send. |
| 7534 | * However, that is not so catastrophic, and there seems |
| 7535 | * to be no way to prevent it completely. |
| 7536 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7537 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7538 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7539 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7540 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7541 | NFS_I(lgp->args.inode)->layout, |
| 7542 | lgp->args.ctx->state)) { |
| 7543 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7544 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7545 | } |
| 7546 | |
| 7547 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7548 | { |
| 7549 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7550 | struct inode *inode = lgp->args.inode; |
| 7551 | struct nfs_server *server = NFS_SERVER(inode); |
| 7552 | struct pnfs_layout_hdr *lo; |
| 7553 | struct nfs4_state *state = NULL; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7554 | unsigned long timeo, now, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7555 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7556 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7557 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7558 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7559 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7560 | |
| 7561 | switch (task->tk_status) { |
| 7562 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7563 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7564 | /* |
| 7565 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
| 7566 | * (or clients) writing to the same RAID stripe |
| 7567 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7568 | case -NFS4ERR_LAYOUTTRYLATER: |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7569 | /* |
| 7570 | * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall |
| 7571 | * existing layout before getting a new one). |
| 7572 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7573 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7574 | timeo = rpc_get_timeout(task->tk_client); |
| 7575 | giveup = lgp->args.timestamp + timeo; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7576 | now = jiffies; |
| 7577 | if (time_after(giveup, now)) { |
| 7578 | unsigned long delay; |
| 7579 | |
| 7580 | /* Delay for: |
| 7581 | * - Not less then NFS4_POLL_RETRY_MIN. |
| 7582 | * - One last time a jiffie before we give up |
| 7583 | * - exponential backoff (time_now minus start_attempt) |
| 7584 | */ |
| 7585 | delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN, |
| 7586 | min((giveup - now - 1), |
| 7587 | now - lgp->args.timestamp)); |
| 7588 | |
| 7589 | dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n", |
| 7590 | __func__, delay); |
| 7591 | rpc_delay(task, delay); |
| 7592 | task->tk_status = 0; |
| 7593 | rpc_restart_call_prepare(task); |
| 7594 | goto out; /* Do not call nfs4_async_handle_error() */ |
| 7595 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7596 | break; |
| 7597 | case -NFS4ERR_EXPIRED: |
| 7598 | case -NFS4ERR_BAD_STATEID: |
| 7599 | spin_lock(&inode->i_lock); |
| 7600 | lo = NFS_I(inode)->layout; |
| 7601 | if (!lo || list_empty(&lo->plh_segs)) { |
| 7602 | spin_unlock(&inode->i_lock); |
| 7603 | /* If the open stateid was bad, then recover it. */ |
| 7604 | state = lgp->args.ctx->state; |
| 7605 | } else { |
| 7606 | LIST_HEAD(head); |
| 7607 | |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7608 | /* |
| 7609 | * Mark the bad layout state as invalid, then retry |
| 7610 | * with the current stateid. |
| 7611 | */ |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7612 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 7613 | spin_unlock(&inode->i_lock); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7614 | pnfs_free_lseg_list(&head); |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7615 | |
| 7616 | task->tk_status = 0; |
| 7617 | rpc_restart_call_prepare(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7618 | } |
| 7619 | } |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7620 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7621 | rpc_restart_call_prepare(task); |
| 7622 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7623 | dprintk("<-- %s\n", __func__); |
| 7624 | } |
| 7625 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7626 | static size_t max_response_pages(struct nfs_server *server) |
| 7627 | { |
| 7628 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7629 | return nfs_page_array_len(0, max_resp_sz); |
| 7630 | } |
| 7631 | |
| 7632 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7633 | { |
| 7634 | int i; |
| 7635 | |
| 7636 | if (!pages) |
| 7637 | return; |
| 7638 | |
| 7639 | for (i = 0; i < size; i++) { |
| 7640 | if (!pages[i]) |
| 7641 | break; |
| 7642 | __free_page(pages[i]); |
| 7643 | } |
| 7644 | kfree(pages); |
| 7645 | } |
| 7646 | |
| 7647 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7648 | { |
| 7649 | struct page **pages; |
| 7650 | int i; |
| 7651 | |
| 7652 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7653 | if (!pages) { |
| 7654 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7655 | return NULL; |
| 7656 | } |
| 7657 | |
| 7658 | for (i = 0; i < size; i++) { |
| 7659 | pages[i] = alloc_page(gfp_flags); |
| 7660 | if (!pages[i]) { |
| 7661 | dprintk("%s: failed to allocate page\n", __func__); |
| 7662 | nfs4_free_pages(pages, size); |
| 7663 | return NULL; |
| 7664 | } |
| 7665 | } |
| 7666 | |
| 7667 | return pages; |
| 7668 | } |
| 7669 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7670 | static void nfs4_layoutget_release(void *calldata) |
| 7671 | { |
| 7672 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7673 | struct inode *inode = lgp->args.inode; |
| 7674 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7675 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7676 | |
| 7677 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7678 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7679 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7680 | put_nfs_open_context(lgp->args.ctx); |
| 7681 | kfree(calldata); |
| 7682 | dprintk("<-- %s\n", __func__); |
| 7683 | } |
| 7684 | |
| 7685 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 7686 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 7687 | .rpc_call_done = nfs4_layoutget_done, |
| 7688 | .rpc_release = nfs4_layoutget_release, |
| 7689 | }; |
| 7690 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7691 | struct pnfs_layout_segment * |
| 7692 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7693 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7694 | struct inode *inode = lgp->args.inode; |
| 7695 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7696 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7697 | struct rpc_task *task; |
| 7698 | struct rpc_message msg = { |
| 7699 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 7700 | .rpc_argp = &lgp->args, |
| 7701 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7702 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7703 | }; |
| 7704 | struct rpc_task_setup task_setup_data = { |
| 7705 | .rpc_client = server->client, |
| 7706 | .rpc_message = &msg, |
| 7707 | .callback_ops = &nfs4_layoutget_call_ops, |
| 7708 | .callback_data = lgp, |
| 7709 | .flags = RPC_TASK_ASYNC, |
| 7710 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7711 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7712 | int status = 0; |
| 7713 | |
| 7714 | dprintk("--> %s\n", __func__); |
| 7715 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 7716 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 7717 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 7718 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7719 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 7720 | if (!lgp->args.layout.pages) { |
| 7721 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7722 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7723 | } |
| 7724 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7725 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7726 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 7727 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7728 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7729 | nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7730 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7731 | task = rpc_run_task(&task_setup_data); |
| 7732 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7733 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7734 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7735 | if (status == 0) |
| 7736 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7737 | trace_nfs4_layoutget(lgp->args.ctx, |
| 7738 | &lgp->args.range, |
| 7739 | &lgp->res.range, |
| 7740 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 7741 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 7742 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7743 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7744 | rpc_put_task(task); |
| 7745 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7746 | if (status) |
| 7747 | return ERR_PTR(status); |
| 7748 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7749 | } |
| 7750 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7751 | static void |
| 7752 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 7753 | { |
| 7754 | struct nfs4_layoutreturn *lrp = calldata; |
| 7755 | |
| 7756 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7757 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 7758 | &lrp->args.seq_args, |
| 7759 | &lrp->res.seq_res, |
| 7760 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7761 | } |
| 7762 | |
| 7763 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 7764 | { |
| 7765 | struct nfs4_layoutreturn *lrp = calldata; |
| 7766 | struct nfs_server *server; |
| 7767 | |
| 7768 | dprintk("--> %s\n", __func__); |
| 7769 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7770 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7771 | return; |
| 7772 | |
| 7773 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7774 | switch (task->tk_status) { |
| 7775 | default: |
| 7776 | task->tk_status = 0; |
| 7777 | case 0: |
| 7778 | break; |
| 7779 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7780 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7781 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7782 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7783 | return; |
| 7784 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7785 | dprintk("<-- %s\n", __func__); |
| 7786 | } |
| 7787 | |
| 7788 | static void nfs4_layoutreturn_release(void *calldata) |
| 7789 | { |
| 7790 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7791 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7792 | |
| 7793 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7794 | spin_lock(&lo->plh_inode->i_lock); |
| 7795 | if (lrp->res.lrs_present) |
| 7796 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 7797 | lo->plh_block_lgets--; |
| 7798 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 7799 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7800 | kfree(calldata); |
| 7801 | dprintk("<-- %s\n", __func__); |
| 7802 | } |
| 7803 | |
| 7804 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 7805 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 7806 | .rpc_call_done = nfs4_layoutreturn_done, |
| 7807 | .rpc_release = nfs4_layoutreturn_release, |
| 7808 | }; |
| 7809 | |
| 7810 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 7811 | { |
| 7812 | struct rpc_task *task; |
| 7813 | struct rpc_message msg = { |
| 7814 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 7815 | .rpc_argp = &lrp->args, |
| 7816 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 7817 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7818 | }; |
| 7819 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 7820 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7821 | .rpc_message = &msg, |
| 7822 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 7823 | .callback_data = lrp, |
| 7824 | }; |
| 7825 | int status; |
| 7826 | |
| 7827 | dprintk("--> %s\n", __func__); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7828 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7829 | task = rpc_run_task(&task_setup_data); |
| 7830 | if (IS_ERR(task)) |
| 7831 | return PTR_ERR(task); |
| 7832 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7833 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7834 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7835 | rpc_put_task(task); |
| 7836 | return status; |
| 7837 | } |
| 7838 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7839 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7840 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7841 | struct pnfs_device *pdev, |
| 7842 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7843 | { |
| 7844 | struct nfs4_getdeviceinfo_args args = { |
| 7845 | .pdev = pdev, |
| 7846 | }; |
| 7847 | struct nfs4_getdeviceinfo_res res = { |
| 7848 | .pdev = pdev, |
| 7849 | }; |
| 7850 | struct rpc_message msg = { |
| 7851 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7852 | .rpc_argp = &args, |
| 7853 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7854 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7855 | }; |
| 7856 | int status; |
| 7857 | |
| 7858 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7859 | 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] | 7860 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7861 | |
| 7862 | return status; |
| 7863 | } |
| 7864 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7865 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7866 | struct pnfs_device *pdev, |
| 7867 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7868 | { |
| 7869 | struct nfs4_exception exception = { }; |
| 7870 | int err; |
| 7871 | |
| 7872 | do { |
| 7873 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7874 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7875 | &exception); |
| 7876 | } while (exception.retry); |
| 7877 | return err; |
| 7878 | } |
| 7879 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7880 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7881 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7882 | { |
| 7883 | struct nfs4_layoutcommit_data *data = calldata; |
| 7884 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7885 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7886 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7887 | nfs41_setup_sequence(session, |
| 7888 | &data->args.seq_args, |
| 7889 | &data->res.seq_res, |
| 7890 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7891 | } |
| 7892 | |
| 7893 | static void |
| 7894 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7895 | { |
| 7896 | struct nfs4_layoutcommit_data *data = calldata; |
| 7897 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7898 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7899 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7900 | return; |
| 7901 | |
| 7902 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7903 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7904 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7905 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7906 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7907 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7908 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7909 | break; |
| 7910 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7911 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7912 | rpc_restart_call_prepare(task); |
| 7913 | return; |
| 7914 | } |
| 7915 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7916 | } |
| 7917 | |
| 7918 | static void nfs4_layoutcommit_release(void *calldata) |
| 7919 | { |
| 7920 | struct nfs4_layoutcommit_data *data = calldata; |
| 7921 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7922 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 7923 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7924 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7925 | put_rpccred(data->cred); |
| 7926 | kfree(data); |
| 7927 | } |
| 7928 | |
| 7929 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7930 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7931 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7932 | .rpc_release = nfs4_layoutcommit_release, |
| 7933 | }; |
| 7934 | |
| 7935 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7936 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7937 | { |
| 7938 | struct rpc_message msg = { |
| 7939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7940 | .rpc_argp = &data->args, |
| 7941 | .rpc_resp = &data->res, |
| 7942 | .rpc_cred = data->cred, |
| 7943 | }; |
| 7944 | struct rpc_task_setup task_setup_data = { |
| 7945 | .task = &data->task, |
| 7946 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7947 | .rpc_message = &msg, |
| 7948 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7949 | .callback_data = data, |
| 7950 | .flags = RPC_TASK_ASYNC, |
| 7951 | }; |
| 7952 | struct rpc_task *task; |
| 7953 | int status = 0; |
| 7954 | |
| 7955 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7956 | "lbw: %llu inode %lu\n", |
| 7957 | data->task.tk_pid, sync, |
| 7958 | data->args.lastbytewritten, |
| 7959 | data->args.inode->i_ino); |
| 7960 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7961 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7962 | task = rpc_run_task(&task_setup_data); |
| 7963 | if (IS_ERR(task)) |
| 7964 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7965 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7966 | goto out; |
| 7967 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7968 | if (status != 0) |
| 7969 | goto out; |
| 7970 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7971 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7972 | out: |
| 7973 | dprintk("%s: status %d\n", __func__, status); |
| 7974 | rpc_put_task(task); |
| 7975 | return status; |
| 7976 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7977 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7978 | /** |
| 7979 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7980 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7981 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7982 | static int |
| 7983 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7984 | struct nfs_fsinfo *info, |
| 7985 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7986 | { |
| 7987 | struct nfs41_secinfo_no_name_args args = { |
| 7988 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7989 | }; |
| 7990 | struct nfs4_secinfo_res res = { |
| 7991 | .flavors = flavors, |
| 7992 | }; |
| 7993 | struct rpc_message msg = { |
| 7994 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7995 | .rpc_argp = &args, |
| 7996 | .rpc_resp = &res, |
| 7997 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7998 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7999 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8000 | int status; |
| 8001 | |
| 8002 | if (use_integrity) { |
| 8003 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8004 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8005 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8006 | } |
| 8007 | |
| 8008 | dprintk("--> %s\n", __func__); |
| 8009 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8010 | &res.seq_res, 0); |
| 8011 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8012 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8013 | if (cred) |
| 8014 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8015 | |
| 8016 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8017 | } |
| 8018 | |
| 8019 | static int |
| 8020 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8021 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8022 | { |
| 8023 | struct nfs4_exception exception = { }; |
| 8024 | int err; |
| 8025 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8026 | /* first try using integrity protection */ |
| 8027 | err = -NFS4ERR_WRONGSEC; |
| 8028 | |
| 8029 | /* try to use integrity protection with machine cred */ |
| 8030 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8031 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8032 | flavors, true); |
| 8033 | |
| 8034 | /* |
| 8035 | * if unable to use integrity protection, or SECINFO with |
| 8036 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8037 | * disallowed by spec, but exists in deployed servers) use |
| 8038 | * the current filesystem's rpc_client and the user cred. |
| 8039 | */ |
| 8040 | if (err == -NFS4ERR_WRONGSEC) |
| 8041 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8042 | flavors, false); |
| 8043 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8044 | switch (err) { |
| 8045 | case 0: |
| 8046 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8047 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8048 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8049 | default: |
| 8050 | err = nfs4_handle_exception(server, err, &exception); |
| 8051 | } |
| 8052 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8053 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8054 | return err; |
| 8055 | } |
| 8056 | |
| 8057 | static int |
| 8058 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8059 | struct nfs_fsinfo *info) |
| 8060 | { |
| 8061 | int err; |
| 8062 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8063 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8064 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8065 | struct nfs4_secinfo4 *secinfo; |
| 8066 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8067 | |
| 8068 | page = alloc_page(GFP_KERNEL); |
| 8069 | if (!page) { |
| 8070 | err = -ENOMEM; |
| 8071 | goto out; |
| 8072 | } |
| 8073 | |
| 8074 | flavors = page_address(page); |
| 8075 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8076 | |
| 8077 | /* |
| 8078 | * Fall back on "guess and check" method if |
| 8079 | * the server doesn't support SECINFO_NO_NAME |
| 8080 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8081 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8082 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8083 | goto out_freepage; |
| 8084 | } |
| 8085 | if (err) |
| 8086 | goto out_freepage; |
| 8087 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8088 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8089 | secinfo = &flavors->flavors[i]; |
| 8090 | |
| 8091 | switch (secinfo->flavor) { |
| 8092 | case RPC_AUTH_NULL: |
| 8093 | case RPC_AUTH_UNIX: |
| 8094 | case RPC_AUTH_GSS: |
| 8095 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8096 | &secinfo->flavor_info); |
| 8097 | break; |
| 8098 | default: |
| 8099 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8100 | break; |
| 8101 | } |
| 8102 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8103 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8104 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8105 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8106 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8107 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8108 | info, flavor); |
| 8109 | if (!err) |
| 8110 | break; |
| 8111 | } |
| 8112 | } |
| 8113 | |
| 8114 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8115 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8116 | |
| 8117 | out_freepage: |
| 8118 | put_page(page); |
| 8119 | if (err == -EACCES) |
| 8120 | return -EPERM; |
| 8121 | out: |
| 8122 | return err; |
| 8123 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8124 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8125 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8126 | nfs4_stateid *stateid, |
| 8127 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8128 | { |
| 8129 | int status; |
| 8130 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8131 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8132 | }; |
| 8133 | struct nfs41_test_stateid_res res; |
| 8134 | struct rpc_message msg = { |
| 8135 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8136 | .rpc_argp = &args, |
| 8137 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8138 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8139 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8140 | struct rpc_clnt *rpc_client = server->client; |
| 8141 | |
| 8142 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8143 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8144 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8145 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8146 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8147 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8148 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8149 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8150 | if (status != NFS_OK) { |
| 8151 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8152 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8153 | } |
| 8154 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8155 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8156 | } |
| 8157 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8158 | /** |
| 8159 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8160 | * |
| 8161 | * @server: server / transport on which to perform the operation |
| 8162 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8163 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8164 | * |
| 8165 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8166 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8167 | * failed or the state ID is not currently valid. |
| 8168 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8169 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8170 | nfs4_stateid *stateid, |
| 8171 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8172 | { |
| 8173 | struct nfs4_exception exception = { }; |
| 8174 | int err; |
| 8175 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8176 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8177 | if (err != -NFS4ERR_DELAY) |
| 8178 | break; |
| 8179 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8180 | } while (exception.retry); |
| 8181 | return err; |
| 8182 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8183 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8184 | struct nfs_free_stateid_data { |
| 8185 | struct nfs_server *server; |
| 8186 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8187 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8188 | }; |
| 8189 | |
| 8190 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8191 | { |
| 8192 | struct nfs_free_stateid_data *data = calldata; |
| 8193 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8194 | &data->args.seq_args, |
| 8195 | &data->res.seq_res, |
| 8196 | task); |
| 8197 | } |
| 8198 | |
| 8199 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8200 | { |
| 8201 | struct nfs_free_stateid_data *data = calldata; |
| 8202 | |
| 8203 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8204 | |
| 8205 | switch (task->tk_status) { |
| 8206 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8207 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8208 | rpc_restart_call_prepare(task); |
| 8209 | } |
| 8210 | } |
| 8211 | |
| 8212 | static void nfs41_free_stateid_release(void *calldata) |
| 8213 | { |
| 8214 | kfree(calldata); |
| 8215 | } |
| 8216 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8217 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8218 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8219 | .rpc_call_done = nfs41_free_stateid_done, |
| 8220 | .rpc_release = nfs41_free_stateid_release, |
| 8221 | }; |
| 8222 | |
| 8223 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8224 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8225 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8226 | bool privileged) |
| 8227 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8228 | struct rpc_message msg = { |
| 8229 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8230 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8231 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8232 | struct rpc_task_setup task_setup = { |
| 8233 | .rpc_client = server->client, |
| 8234 | .rpc_message = &msg, |
| 8235 | .callback_ops = &nfs41_free_stateid_ops, |
| 8236 | .flags = RPC_TASK_ASYNC, |
| 8237 | }; |
| 8238 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8239 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8240 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8241 | &task_setup.rpc_client, &msg); |
| 8242 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8243 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8244 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8245 | if (!data) |
| 8246 | return ERR_PTR(-ENOMEM); |
| 8247 | data->server = server; |
| 8248 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8249 | |
| 8250 | task_setup.callback_data = data; |
| 8251 | |
| 8252 | msg.rpc_argp = &data->args; |
| 8253 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8254 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8255 | if (privileged) |
| 8256 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8257 | |
| 8258 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8259 | } |
| 8260 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8261 | /** |
| 8262 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8263 | * |
| 8264 | * @server: server / transport on which to perform the operation |
| 8265 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8266 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8267 | * |
| 8268 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8269 | * negative NFS4ERR value is returned. |
| 8270 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8271 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8272 | nfs4_stateid *stateid, |
| 8273 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8274 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8275 | struct rpc_task *task; |
| 8276 | int ret; |
| 8277 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8278 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8279 | if (IS_ERR(task)) |
| 8280 | return PTR_ERR(task); |
| 8281 | ret = rpc_wait_for_completion_task(task); |
| 8282 | if (!ret) |
| 8283 | ret = task->tk_status; |
| 8284 | rpc_put_task(task); |
| 8285 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8286 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8287 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8288 | static void |
| 8289 | nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8290 | { |
| 8291 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8292 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8293 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8294 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8295 | nfs4_free_lock_state(server, lsp); |
| 8296 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8297 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8298 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8299 | } |
| 8300 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8301 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8302 | const nfs4_stateid *s2) |
| 8303 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8304 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8305 | return false; |
| 8306 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8307 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8308 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8309 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8310 | return true; |
| 8311 | |
| 8312 | return false; |
| 8313 | } |
| 8314 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8315 | #endif /* CONFIG_NFS_V4_1 */ |
| 8316 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8317 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8318 | const nfs4_stateid *s2) |
| 8319 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8320 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8321 | } |
| 8322 | |
| 8323 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8324 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8325 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8326 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8327 | .recover_open = nfs4_open_reclaim, |
| 8328 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8329 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8330 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8331 | }; |
| 8332 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8333 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8334 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8335 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8336 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8337 | .recover_open = nfs4_open_reclaim, |
| 8338 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8339 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8340 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8341 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8342 | }; |
| 8343 | #endif /* CONFIG_NFS_V4_1 */ |
| 8344 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8345 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8346 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8347 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 8348 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8349 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8350 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8351 | }; |
| 8352 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8353 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8354 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8355 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8356 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8357 | .recover_open = nfs41_open_expired, |
| 8358 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8359 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8360 | }; |
| 8361 | #endif /* CONFIG_NFS_V4_1 */ |
| 8362 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8363 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8364 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8365 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8366 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8367 | }; |
| 8368 | |
| 8369 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8370 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8371 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8372 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8373 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8374 | }; |
| 8375 | #endif |
| 8376 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8377 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8378 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8379 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8380 | }; |
| 8381 | |
| 8382 | #if defined(CONFIG_NFS_V4_1) |
| 8383 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8384 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8385 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8386 | }; |
| 8387 | #endif /* CONFIG_NFS_V4_1 */ |
| 8388 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8389 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8390 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8391 | .init_caps = NFS_CAP_READDIRPLUS |
| 8392 | | NFS_CAP_ATOMIC_OPEN |
| 8393 | | NFS_CAP_CHANGE_ATTR |
| 8394 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8395 | .init_client = nfs40_init_client, |
| 8396 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8397 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8398 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8399 | .free_lock_state = nfs4_release_lockowner, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8400 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8401 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8402 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8403 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8404 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8405 | }; |
| 8406 | |
| 8407 | #if defined(CONFIG_NFS_V4_1) |
| 8408 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8409 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8410 | .init_caps = NFS_CAP_READDIRPLUS |
| 8411 | | NFS_CAP_ATOMIC_OPEN |
| 8412 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8413 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8414 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8415 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8416 | .init_client = nfs41_init_client, |
| 8417 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8418 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8419 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8420 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8421 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8422 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8423 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8424 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8425 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8426 | }; |
| 8427 | #endif |
| 8428 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8429 | #if defined(CONFIG_NFS_V4_2) |
| 8430 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8431 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8432 | .init_caps = NFS_CAP_READDIRPLUS |
| 8433 | | NFS_CAP_ATOMIC_OPEN |
| 8434 | | NFS_CAP_CHANGE_ATTR |
| 8435 | | NFS_CAP_POSIX_LOCK |
| 8436 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8437 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 8438 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 8439 | | NFS_CAP_DEALLOCATE |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8440 | | NFS_CAP_SEEK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8441 | .init_client = nfs41_init_client, |
| 8442 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8443 | .match_stateid = nfs41_match_stateid, |
| 8444 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8445 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8446 | .call_sync_ops = &nfs41_call_sync_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8447 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8448 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8449 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 8450 | }; |
| 8451 | #endif |
| 8452 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8453 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8454 | [0] = &nfs_v4_0_minor_ops, |
| 8455 | #if defined(CONFIG_NFS_V4_1) |
| 8456 | [1] = &nfs_v4_1_minor_ops, |
| 8457 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8458 | #if defined(CONFIG_NFS_V4_2) |
| 8459 | [2] = &nfs_v4_2_minor_ops, |
| 8460 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8461 | }; |
| 8462 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8463 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8464 | .create = nfs_create, |
| 8465 | .lookup = nfs_lookup, |
| 8466 | .atomic_open = nfs_atomic_open, |
| 8467 | .link = nfs_link, |
| 8468 | .unlink = nfs_unlink, |
| 8469 | .symlink = nfs_symlink, |
| 8470 | .mkdir = nfs_mkdir, |
| 8471 | .rmdir = nfs_rmdir, |
| 8472 | .mknod = nfs_mknod, |
| 8473 | .rename = nfs_rename, |
| 8474 | .permission = nfs_permission, |
| 8475 | .getattr = nfs_getattr, |
| 8476 | .setattr = nfs_setattr, |
| 8477 | .getxattr = generic_getxattr, |
| 8478 | .setxattr = generic_setxattr, |
| 8479 | .listxattr = generic_listxattr, |
| 8480 | .removexattr = generic_removexattr, |
| 8481 | }; |
| 8482 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8483 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8484 | .permission = nfs_permission, |
| 8485 | .getattr = nfs_getattr, |
| 8486 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8487 | .getxattr = generic_getxattr, |
| 8488 | .setxattr = generic_setxattr, |
| 8489 | .listxattr = generic_listxattr, |
| 8490 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8491 | }; |
| 8492 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8493 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8494 | .version = 4, /* protocol version */ |
| 8495 | .dentry_ops = &nfs4_dentry_operations, |
| 8496 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8497 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8498 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8499 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8500 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8501 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8502 | .getattr = nfs4_proc_getattr, |
| 8503 | .setattr = nfs4_proc_setattr, |
| 8504 | .lookup = nfs4_proc_lookup, |
| 8505 | .access = nfs4_proc_access, |
| 8506 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8507 | .create = nfs4_proc_create, |
| 8508 | .remove = nfs4_proc_remove, |
| 8509 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8510 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8511 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8512 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8513 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8514 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8515 | .link = nfs4_proc_link, |
| 8516 | .symlink = nfs4_proc_symlink, |
| 8517 | .mkdir = nfs4_proc_mkdir, |
| 8518 | .rmdir = nfs4_proc_remove, |
| 8519 | .readdir = nfs4_proc_readdir, |
| 8520 | .mknod = nfs4_proc_mknod, |
| 8521 | .statfs = nfs4_proc_statfs, |
| 8522 | .fsinfo = nfs4_proc_fsinfo, |
| 8523 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8524 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8525 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8526 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8527 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8528 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8529 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8530 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8531 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8532 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8533 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8534 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8535 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8536 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8537 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8538 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8539 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8540 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8541 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8542 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8543 | .create_server = nfs4_create_server, |
| 8544 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8545 | }; |
| 8546 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8547 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 8548 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 8549 | .list = nfs4_xattr_list_nfs4_acl, |
| 8550 | .get = nfs4_xattr_get_nfs4_acl, |
| 8551 | .set = nfs4_xattr_set_nfs4_acl, |
| 8552 | }; |
| 8553 | |
| 8554 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8555 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8556 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8557 | &nfs4_xattr_nfs4_label_handler, |
| 8558 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8559 | NULL |
| 8560 | }; |
| 8561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8562 | /* |
| 8563 | * Local variables: |
| 8564 | * c-basic-offset: 8 |
| 8565 | * End: |
| 8566 | */ |