Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
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; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 161 | case -NFS4ERR_ACCESS: |
| 162 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 163 | case -NFS4ERR_FILE_OPEN: |
| 164 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 165 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 167 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 168 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 170 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
| 174 | * This is our standard bitmap for GETATTR requests. |
| 175 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 176 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | FATTR4_WORD0_TYPE |
| 178 | | FATTR4_WORD0_CHANGE |
| 179 | | FATTR4_WORD0_SIZE |
| 180 | | FATTR4_WORD0_FSID |
| 181 | | FATTR4_WORD0_FILEID, |
| 182 | FATTR4_WORD1_MODE |
| 183 | | FATTR4_WORD1_NUMLINKS |
| 184 | | FATTR4_WORD1_OWNER |
| 185 | | FATTR4_WORD1_OWNER_GROUP |
| 186 | | FATTR4_WORD1_RAWDEV |
| 187 | | FATTR4_WORD1_SPACE_USED |
| 188 | | FATTR4_WORD1_TIME_ACCESS |
| 189 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 190 | | FATTR4_WORD1_TIME_MODIFY, |
| 191 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 192 | FATTR4_WORD2_SECURITY_LABEL |
| 193 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 196 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 197 | FATTR4_WORD0_TYPE |
| 198 | | FATTR4_WORD0_CHANGE |
| 199 | | FATTR4_WORD0_SIZE |
| 200 | | FATTR4_WORD0_FSID |
| 201 | | FATTR4_WORD0_FILEID, |
| 202 | FATTR4_WORD1_MODE |
| 203 | | FATTR4_WORD1_NUMLINKS |
| 204 | | FATTR4_WORD1_OWNER |
| 205 | | FATTR4_WORD1_OWNER_GROUP |
| 206 | | FATTR4_WORD1_RAWDEV |
| 207 | | FATTR4_WORD1_SPACE_USED |
| 208 | | FATTR4_WORD1_TIME_ACCESS |
| 209 | | FATTR4_WORD1_TIME_METADATA |
| 210 | | FATTR4_WORD1_TIME_MODIFY, |
| 211 | FATTR4_WORD2_MDSTHRESHOLD |
| 212 | }; |
| 213 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 214 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 215 | FATTR4_WORD0_TYPE |
| 216 | | FATTR4_WORD0_CHANGE |
| 217 | | FATTR4_WORD0_FILEID, |
| 218 | }; |
| 219 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 220 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | FATTR4_WORD0_FILES_AVAIL |
| 222 | | FATTR4_WORD0_FILES_FREE |
| 223 | | FATTR4_WORD0_FILES_TOTAL, |
| 224 | FATTR4_WORD1_SPACE_AVAIL |
| 225 | | FATTR4_WORD1_SPACE_FREE |
| 226 | | FATTR4_WORD1_SPACE_TOTAL |
| 227 | }; |
| 228 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 229 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | FATTR4_WORD0_MAXLINK |
| 231 | | FATTR4_WORD0_MAXNAME, |
| 232 | 0 |
| 233 | }; |
| 234 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 235 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | | FATTR4_WORD0_MAXREAD |
| 237 | | FATTR4_WORD0_MAXWRITE |
| 238 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 239 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 240 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 241 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 244 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 245 | FATTR4_WORD0_TYPE |
| 246 | | FATTR4_WORD0_CHANGE |
| 247 | | FATTR4_WORD0_SIZE |
| 248 | | FATTR4_WORD0_FSID |
| 249 | | FATTR4_WORD0_FILEID |
| 250 | | FATTR4_WORD0_FS_LOCATIONS, |
| 251 | FATTR4_WORD1_MODE |
| 252 | | FATTR4_WORD1_NUMLINKS |
| 253 | | FATTR4_WORD1_OWNER |
| 254 | | FATTR4_WORD1_OWNER_GROUP |
| 255 | | FATTR4_WORD1_RAWDEV |
| 256 | | FATTR4_WORD1_SPACE_USED |
| 257 | | FATTR4_WORD1_TIME_ACCESS |
| 258 | | FATTR4_WORD1_TIME_METADATA |
| 259 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 260 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 261 | }; |
| 262 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 263 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | struct nfs4_readdir_arg *readdir) |
| 265 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 266 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 269 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | readdir->cookie = 0; |
| 275 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 276 | if (cookie == 2) |
| 277 | return; |
| 278 | |
| 279 | /* |
| 280 | * NFSv4 servers do not return entries for '.' and '..' |
| 281 | * Therefore, we fake these entries here. We let '.' |
| 282 | * have cookie 0 and '..' have cookie 1. Note that |
| 283 | * when talking to the server, we always send cookie 0 |
| 284 | * instead of 1 or 2. |
| 285 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 286 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | if (cookie == 0) { |
| 289 | *p++ = xdr_one; /* next */ |
| 290 | *p++ = xdr_zero; /* cookie, first word */ |
| 291 | *p++ = xdr_one; /* cookie, second word */ |
| 292 | *p++ = xdr_one; /* entry len */ |
| 293 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 294 | p++; |
| 295 | *p++ = xdr_one; /* bitmap length */ |
| 296 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 297 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 298 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | *p++ = xdr_one; /* next */ |
| 302 | *p++ = xdr_zero; /* cookie, first word */ |
| 303 | *p++ = xdr_two; /* cookie, second word */ |
| 304 | *p++ = xdr_two; /* entry len */ |
| 305 | memcpy(p, "..\0\0", 4); /* entry */ |
| 306 | p++; |
| 307 | *p++ = xdr_one; /* bitmap length */ |
| 308 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 309 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | readdir->pgbase = (char *)p - (char *)start; |
| 313 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 314 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 317 | static long nfs4_update_delay(long *timeout) |
| 318 | { |
| 319 | long ret; |
| 320 | if (!timeout) |
| 321 | return NFS4_POLL_RETRY_MAX; |
| 322 | if (*timeout <= 0) |
| 323 | *timeout = NFS4_POLL_RETRY_MIN; |
| 324 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 325 | *timeout = NFS4_POLL_RETRY_MAX; |
| 326 | ret = *timeout; |
| 327 | *timeout <<= 1; |
| 328 | return ret; |
| 329 | } |
| 330 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 331 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 332 | { |
| 333 | int res = 0; |
| 334 | |
| 335 | might_sleep(); |
| 336 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 337 | freezable_schedule_timeout_killable_unsafe( |
| 338 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 339 | if (fatal_signal_pending(current)) |
| 340 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | return res; |
| 342 | } |
| 343 | |
| 344 | /* This is the error handling routine for processes that are allowed |
| 345 | * to sleep. |
| 346 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 347 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 348 | { |
| 349 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 350 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 351 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 352 | int ret = errorcode; |
| 353 | |
| 354 | exception->retry = 0; |
| 355 | switch(errorcode) { |
| 356 | case 0: |
| 357 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 358 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 359 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 360 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 361 | exception->retry = 1; |
| 362 | return 0; |
| 363 | } |
| 364 | if (state == NULL) |
| 365 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 366 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 367 | if (ret < 0) |
| 368 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 369 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 370 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 371 | case -NFS4ERR_ADMIN_REVOKED: |
| 372 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 373 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 374 | nfs_remove_bad_delegation(inode); |
| 375 | exception->retry = 1; |
| 376 | break; |
| 377 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 378 | if (state == NULL) |
| 379 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 380 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 381 | if (ret < 0) |
| 382 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 383 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 384 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 385 | if (state != NULL) { |
| 386 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 387 | if (ret < 0) |
| 388 | break; |
| 389 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 390 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 391 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 392 | nfs4_schedule_lease_recovery(clp); |
| 393 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 394 | case -NFS4ERR_MOVED: |
| 395 | ret = nfs4_schedule_migration_recovery(server); |
| 396 | if (ret < 0) |
| 397 | break; |
| 398 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 399 | case -NFS4ERR_LEASE_MOVED: |
| 400 | nfs4_schedule_lease_moved_recovery(clp); |
| 401 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 402 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 403 | case -NFS4ERR_BADSESSION: |
| 404 | case -NFS4ERR_BADSLOT: |
| 405 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 406 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 407 | case -NFS4ERR_DEADSESSION: |
| 408 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 409 | case -NFS4ERR_SEQ_MISORDERED: |
| 410 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 411 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 412 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 413 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 414 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 415 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 416 | if (exception->timeout > HZ) { |
| 417 | /* We have retried a decent amount, time to |
| 418 | * fail |
| 419 | */ |
| 420 | ret = -EBUSY; |
| 421 | break; |
| 422 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 423 | case -NFS4ERR_GRACE: |
| 424 | case -NFS4ERR_DELAY: |
| 425 | ret = nfs4_delay(server->client, &exception->timeout); |
| 426 | if (ret != 0) |
| 427 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 428 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 429 | case -NFS4ERR_OLD_STATEID: |
| 430 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 431 | break; |
| 432 | case -NFS4ERR_BADOWNER: |
| 433 | /* The following works around a Linux server bug! */ |
| 434 | case -NFS4ERR_BADNAME: |
| 435 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 436 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 437 | exception->retry = 1; |
| 438 | printk(KERN_WARNING "NFS: v4 server %s " |
| 439 | "does not accept raw " |
| 440 | "uid/gids. " |
| 441 | "Reenabling the idmapper.\n", |
| 442 | server->nfs_client->cl_hostname); |
| 443 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 444 | } |
| 445 | /* We failed to handle the error */ |
| 446 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 447 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 448 | ret = nfs4_wait_clnt_recover(clp); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 449 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 450 | return -EIO; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 451 | if (ret == 0) |
| 452 | exception->retry = 1; |
| 453 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 454 | } |
| 455 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 456 | /* |
| 457 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 458 | * or 'false' otherwise. |
| 459 | */ |
| 460 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 461 | { |
| 462 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 463 | |
| 464 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 465 | flavor == RPC_AUTH_GSS_KRB5P) |
| 466 | return true; |
| 467 | |
| 468 | return false; |
| 469 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 470 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 471 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | spin_lock(&clp->cl_lock); |
| 474 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 475 | clp->cl_last_renewal = timestamp; |
| 476 | spin_unlock(&clp->cl_lock); |
| 477 | } |
| 478 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 479 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 480 | { |
| 481 | do_renew_lease(server->nfs_client, timestamp); |
| 482 | } |
| 483 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 484 | struct nfs4_call_sync_data { |
| 485 | const struct nfs_server *seq_server; |
| 486 | struct nfs4_sequence_args *seq_args; |
| 487 | struct nfs4_sequence_res *seq_res; |
| 488 | }; |
| 489 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 490 | static void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 491 | struct nfs4_sequence_res *res, int cache_reply) |
| 492 | { |
| 493 | args->sa_slot = NULL; |
| 494 | args->sa_cache_this = cache_reply; |
| 495 | args->sa_privileged = 0; |
| 496 | |
| 497 | res->sr_slot = NULL; |
| 498 | } |
| 499 | |
| 500 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 501 | { |
| 502 | args->sa_privileged = 1; |
| 503 | } |
| 504 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 505 | static int nfs40_setup_sequence(const struct nfs_server *server, |
| 506 | struct nfs4_sequence_args *args, |
| 507 | struct nfs4_sequence_res *res, |
| 508 | struct rpc_task *task) |
| 509 | { |
| 510 | struct nfs4_slot_table *tbl = server->nfs_client->cl_slot_tbl; |
| 511 | struct nfs4_slot *slot; |
| 512 | |
| 513 | /* slot already allocated? */ |
| 514 | if (res->sr_slot != NULL) |
| 515 | goto out_start; |
| 516 | |
| 517 | spin_lock(&tbl->slot_tbl_lock); |
| 518 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 519 | goto out_sleep; |
| 520 | |
| 521 | slot = nfs4_alloc_slot(tbl); |
| 522 | if (IS_ERR(slot)) { |
| 523 | if (slot == ERR_PTR(-ENOMEM)) |
| 524 | task->tk_timeout = HZ >> 2; |
| 525 | goto out_sleep; |
| 526 | } |
| 527 | spin_unlock(&tbl->slot_tbl_lock); |
| 528 | |
| 529 | args->sa_slot = slot; |
| 530 | res->sr_slot = slot; |
| 531 | |
| 532 | out_start: |
| 533 | rpc_call_start(task); |
| 534 | return 0; |
| 535 | |
| 536 | out_sleep: |
| 537 | if (args->sa_privileged) |
| 538 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 539 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 540 | else |
| 541 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 542 | spin_unlock(&tbl->slot_tbl_lock); |
| 543 | return -EAGAIN; |
| 544 | } |
| 545 | |
| 546 | static int nfs40_sequence_done(struct rpc_task *task, |
| 547 | struct nfs4_sequence_res *res) |
| 548 | { |
| 549 | struct nfs4_slot *slot = res->sr_slot; |
| 550 | struct nfs4_slot_table *tbl; |
| 551 | |
Trond Myklebust | cab92c1 | 2014-01-29 12:12:15 -0500 | [diff] [blame] | 552 | if (slot == NULL) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 553 | goto out; |
| 554 | |
| 555 | tbl = slot->table; |
| 556 | spin_lock(&tbl->slot_tbl_lock); |
| 557 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 558 | nfs4_free_slot(tbl, slot); |
| 559 | spin_unlock(&tbl->slot_tbl_lock); |
| 560 | |
| 561 | res->sr_slot = NULL; |
| 562 | out: |
| 563 | return 1; |
| 564 | } |
| 565 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 566 | #if defined(CONFIG_NFS_V4_1) |
| 567 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 568 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 569 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 570 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 571 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 572 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 573 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 574 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 575 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 576 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 577 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 578 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 579 | /* Be nice to the server: try to ensure that the last transmitted |
| 580 | * value for highest_user_slotid <= target_highest_slotid |
| 581 | */ |
| 582 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 583 | send_new_highest_used_slotid = true; |
| 584 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 585 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 586 | send_new_highest_used_slotid = false; |
| 587 | goto out_unlock; |
| 588 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 589 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 590 | |
| 591 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 592 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 593 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 594 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 595 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 596 | if (send_new_highest_used_slotid) |
| 597 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 600 | 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] | 601 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 602 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 603 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 604 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 605 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 606 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 607 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 608 | if (slot == NULL) |
| 609 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 610 | /* don't increment the sequence number if the task wasn't sent */ |
| 611 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 612 | goto out; |
| 613 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 614 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 615 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 616 | if (slot->interrupted) { |
| 617 | slot->interrupted = 0; |
| 618 | interrupted = true; |
| 619 | } |
| 620 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 621 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 622 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 623 | switch (res->sr_status) { |
| 624 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 625 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 626 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 627 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 628 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 629 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 630 | if (res->sr_status_flags != 0) |
| 631 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 632 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 633 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 634 | case 1: |
| 635 | /* |
| 636 | * sr_status remains 1 if an RPC level error occurred. |
| 637 | * The server may or may not have processed the sequence |
| 638 | * operation.. |
| 639 | * Mark the slot as having hosted an interrupted RPC call. |
| 640 | */ |
| 641 | slot->interrupted = 1; |
| 642 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 643 | case -NFS4ERR_DELAY: |
| 644 | /* The server detected a resend of the RPC call and |
| 645 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 646 | * of RFC5661. |
| 647 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 648 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 649 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 650 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 651 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 652 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 653 | case -NFS4ERR_BADSLOT: |
| 654 | /* |
| 655 | * The slot id we used was probably retired. Try again |
| 656 | * using a different slot id. |
| 657 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 658 | goto retry_nowait; |
| 659 | case -NFS4ERR_SEQ_MISORDERED: |
| 660 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 661 | * Was the last operation on this sequence interrupted? |
| 662 | * If so, retry after bumping the sequence number. |
| 663 | */ |
| 664 | if (interrupted) { |
| 665 | ++slot->seq_nr; |
| 666 | goto retry_nowait; |
| 667 | } |
| 668 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 669 | * Could this slot have been previously retired? |
| 670 | * If so, then the server may be expecting seq_nr = 1! |
| 671 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 672 | if (slot->seq_nr != 1) { |
| 673 | slot->seq_nr = 1; |
| 674 | goto retry_nowait; |
| 675 | } |
| 676 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 677 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 678 | ++slot->seq_nr; |
| 679 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 680 | default: |
| 681 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 682 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 683 | } |
| 684 | out: |
| 685 | /* The session may be reset by one of the error handlers. */ |
| 686 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 687 | nfs41_sequence_free_slot(res); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 688 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 689 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 690 | retry_nowait: |
| 691 | if (rpc_restart_call_prepare(task)) { |
| 692 | task->tk_status = 0; |
| 693 | ret = 0; |
| 694 | } |
| 695 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 696 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 697 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 698 | goto out; |
| 699 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 700 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 701 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 702 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 703 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 704 | static int nfs4_sequence_done(struct rpc_task *task, |
| 705 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 706 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 707 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 708 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 709 | if (!res->sr_slot->table->session) |
| 710 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 711 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 712 | } |
| 713 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 714 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 715 | struct nfs4_sequence_args *args, |
| 716 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 717 | struct rpc_task *task) |
| 718 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 719 | struct nfs4_slot *slot; |
| 720 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 721 | |
| 722 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 723 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 724 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 725 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 726 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 727 | tbl = &session->fc_slot_table; |
| 728 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 729 | task->tk_timeout = 0; |
| 730 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 731 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 732 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 733 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 734 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 735 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 736 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 737 | } |
| 738 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 739 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 740 | if (IS_ERR(slot)) { |
| 741 | /* If out of memory, try again in 1/4 second */ |
| 742 | if (slot == ERR_PTR(-ENOMEM)) |
| 743 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 744 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 745 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 746 | } |
| 747 | spin_unlock(&tbl->slot_tbl_lock); |
| 748 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 749 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 750 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 751 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 752 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 753 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 754 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 755 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 756 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 757 | /* |
| 758 | * sr_status is only set in decode_sequence, and so will remain |
| 759 | * set to 1 if an rpc level failure occurs. |
| 760 | */ |
| 761 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 762 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 763 | out_success: |
| 764 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 765 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 766 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 767 | /* Privileged tasks are queued with top priority */ |
| 768 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 769 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 770 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 771 | else |
| 772 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 773 | spin_unlock(&tbl->slot_tbl_lock); |
| 774 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 775 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 776 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 777 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 778 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 779 | struct nfs4_sequence_args *args, |
| 780 | struct nfs4_sequence_res *res, |
| 781 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 782 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 783 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 784 | int ret = 0; |
| 785 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 786 | if (!session) |
| 787 | return nfs40_setup_sequence(server, args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 788 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 789 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 790 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 791 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 792 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 793 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 794 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 795 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 796 | return ret; |
| 797 | } |
| 798 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 799 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 800 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 801 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 802 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 803 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 804 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 805 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 806 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 807 | } |
| 808 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 809 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 810 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 811 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 812 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 813 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 814 | } |
| 815 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 816 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 817 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 818 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 819 | }; |
| 820 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 821 | #else /* !CONFIG_NFS_V4_1 */ |
| 822 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 823 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 824 | struct nfs4_sequence_args *args, |
| 825 | struct nfs4_sequence_res *res, |
| 826 | struct rpc_task *task) |
| 827 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 828 | return nfs40_setup_sequence(server, args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 829 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 830 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 831 | static int nfs4_sequence_done(struct rpc_task *task, |
| 832 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 833 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 834 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 835 | } |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 836 | |
| 837 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 838 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 839 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 840 | { |
| 841 | struct nfs4_call_sync_data *data = calldata; |
| 842 | nfs4_setup_sequence(data->seq_server, |
| 843 | data->seq_args, data->seq_res, task); |
| 844 | } |
| 845 | |
| 846 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 847 | { |
| 848 | struct nfs4_call_sync_data *data = calldata; |
| 849 | nfs4_sequence_done(task, data->seq_res); |
| 850 | } |
| 851 | |
| 852 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 853 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 854 | .rpc_call_done = nfs40_call_sync_done, |
| 855 | }; |
| 856 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 857 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 858 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 859 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 860 | struct nfs4_sequence_args *args, |
| 861 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 862 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 863 | int ret; |
| 864 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 865 | struct nfs_client *clp = server->nfs_client; |
| 866 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 867 | .seq_server = server, |
| 868 | .seq_args = args, |
| 869 | .seq_res = res, |
| 870 | }; |
| 871 | struct rpc_task_setup task_setup = { |
| 872 | .rpc_client = clnt, |
| 873 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 874 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 875 | .callback_data = &data |
| 876 | }; |
| 877 | |
| 878 | task = rpc_run_task(&task_setup); |
| 879 | if (IS_ERR(task)) |
| 880 | ret = PTR_ERR(task); |
| 881 | else { |
| 882 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 883 | rpc_put_task(task); |
| 884 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 885 | return ret; |
| 886 | } |
| 887 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 888 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 889 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 890 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 891 | struct rpc_message *msg, |
| 892 | struct nfs4_sequence_args *args, |
| 893 | struct nfs4_sequence_res *res, |
| 894 | int cache_reply) |
| 895 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 896 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 897 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 901 | { |
| 902 | struct nfs_inode *nfsi = NFS_I(dir); |
| 903 | |
| 904 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 905 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 906 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 908 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 909 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | spin_unlock(&dir->i_lock); |
| 911 | } |
| 912 | |
| 913 | struct nfs4_opendata { |
| 914 | struct kref kref; |
| 915 | struct nfs_openargs o_arg; |
| 916 | struct nfs_openres o_res; |
| 917 | struct nfs_open_confirmargs c_arg; |
| 918 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 919 | struct nfs4_string owner_name; |
| 920 | struct nfs4_string group_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 922 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 924 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | struct nfs4_state_owner *owner; |
| 926 | struct nfs4_state *state; |
| 927 | struct iattr attrs; |
| 928 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 929 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 930 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 931 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 932 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | int cancelled; |
| 934 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 935 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 936 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 937 | int err, struct nfs4_exception *exception) |
| 938 | { |
| 939 | if (err != -EINVAL) |
| 940 | return false; |
| 941 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 942 | return false; |
| 943 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 944 | exception->retry = 1; |
| 945 | return true; |
| 946 | } |
| 947 | |
| 948 | static enum open_claim_type4 |
| 949 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 950 | enum open_claim_type4 claim) |
| 951 | { |
| 952 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 953 | return claim; |
| 954 | switch (claim) { |
| 955 | default: |
| 956 | return claim; |
| 957 | case NFS4_OPEN_CLAIM_FH: |
| 958 | return NFS4_OPEN_CLAIM_NULL; |
| 959 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 960 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 961 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 962 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 963 | } |
| 964 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
| 966 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 967 | { |
| 968 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 969 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 970 | p->o_res.seqid = p->o_arg.seqid; |
| 971 | p->c_res.seqid = p->c_arg.seqid; |
| 972 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 973 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 974 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 975 | 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] | 976 | } |
| 977 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 978 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 979 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 980 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 981 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 982 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 983 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 984 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 985 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 986 | struct inode *dir = parent->d_inode; |
| 987 | struct nfs_server *server = NFS_SERVER(dir); |
| 988 | struct nfs4_opendata *p; |
| 989 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 990 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 991 | if (p == NULL) |
| 992 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 993 | |
| 994 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 995 | if (IS_ERR(p->f_label)) |
| 996 | goto err_free_p; |
| 997 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 998 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 999 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1000 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1001 | nfs_sb_active(dentry->d_sb); |
| 1002 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1003 | p->dir = parent; |
| 1004 | p->owner = sp; |
| 1005 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1006 | p->o_arg.open_flags = flags; |
| 1007 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1008 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1009 | * will return permission denied for all bits until close */ |
| 1010 | if (!(flags & O_EXCL)) { |
| 1011 | /* ask server to check for all possible rights as results |
| 1012 | * are cached */ |
| 1013 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1014 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1015 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1016 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1017 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1018 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1019 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1020 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1021 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1022 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1023 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1024 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1025 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1026 | case NFS4_OPEN_CLAIM_NULL: |
| 1027 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1028 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1029 | p->o_arg.fh = NFS_FH(dir); |
| 1030 | break; |
| 1031 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1032 | case NFS4_OPEN_CLAIM_FH: |
| 1033 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1034 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1035 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 1036 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1037 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1038 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1039 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1040 | p->o_arg.u.attrs = &p->attrs; |
| 1041 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1042 | |
| 1043 | verf[0] = jiffies; |
| 1044 | verf[1] = current->pid; |
| 1045 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1046 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1047 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1048 | p->c_arg.fh = &p->o_res.fh; |
| 1049 | p->c_arg.stateid = &p->o_res.stateid; |
| 1050 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1051 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1052 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1053 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1054 | |
| 1055 | err_free_label: |
| 1056 | nfs4_label_free(p->f_label); |
| 1057 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1058 | kfree(p); |
| 1059 | err: |
| 1060 | dput(parent); |
| 1061 | return NULL; |
| 1062 | } |
| 1063 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1064 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1065 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1066 | struct nfs4_opendata *p = container_of(kref, |
| 1067 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1068 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1069 | |
| 1070 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1071 | if (p->state != NULL) |
| 1072 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1073 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1074 | |
| 1075 | nfs4_label_free(p->f_label); |
| 1076 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1077 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1078 | dput(p->dentry); |
| 1079 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1080 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1081 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1082 | kfree(p); |
| 1083 | } |
| 1084 | |
| 1085 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1086 | { |
| 1087 | if (p != NULL) |
| 1088 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1091 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1092 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1093 | int ret; |
| 1094 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1095 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1096 | return ret; |
| 1097 | } |
| 1098 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1099 | 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] | 1100 | { |
| 1101 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1102 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1103 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1104 | goto out; |
| 1105 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1106 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1107 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1108 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1109 | break; |
| 1110 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1111 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1112 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1113 | break; |
| 1114 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1115 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1116 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1117 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1118 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1119 | return ret; |
| 1120 | } |
| 1121 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1122 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1123 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1124 | if (delegation == NULL) |
| 1125 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1126 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1127 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1128 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1129 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1130 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1131 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1132 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1133 | return 1; |
| 1134 | } |
| 1135 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1136 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1137 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1138 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1139 | case FMODE_WRITE: |
| 1140 | state->n_wronly++; |
| 1141 | break; |
| 1142 | case FMODE_READ: |
| 1143 | state->n_rdonly++; |
| 1144 | break; |
| 1145 | case FMODE_READ|FMODE_WRITE: |
| 1146 | state->n_rdwr++; |
| 1147 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1148 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1149 | } |
| 1150 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1151 | 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] | 1152 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1153 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1154 | bool need_recover = false; |
| 1155 | |
| 1156 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1157 | need_recover = true; |
| 1158 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1159 | need_recover = true; |
| 1160 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1161 | need_recover = true; |
| 1162 | if (need_recover) |
| 1163 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1164 | } |
| 1165 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1166 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1167 | nfs4_stateid *stateid) |
| 1168 | { |
| 1169 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1170 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1171 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1172 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1173 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1174 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1175 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1176 | return true; |
| 1177 | return false; |
| 1178 | } |
| 1179 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1180 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1181 | nfs4_stateid *stateid, fmode_t fmode) |
| 1182 | { |
| 1183 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1184 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1185 | case FMODE_WRITE: |
| 1186 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1187 | break; |
| 1188 | case FMODE_READ: |
| 1189 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1190 | break; |
| 1191 | case 0: |
| 1192 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1193 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1194 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1195 | } |
| 1196 | if (stateid == NULL) |
| 1197 | return; |
| 1198 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1199 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1200 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1201 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1202 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | static void nfs_clear_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1206 | { |
| 1207 | write_seqlock(&state->seqlock); |
| 1208 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
| 1209 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1210 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1211 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1212 | } |
| 1213 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1214 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1215 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1216 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1217 | case FMODE_READ: |
| 1218 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1219 | break; |
| 1220 | case FMODE_WRITE: |
| 1221 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1222 | break; |
| 1223 | case FMODE_READ|FMODE_WRITE: |
| 1224 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1225 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1226 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1227 | return; |
| 1228 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1229 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1230 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1233 | 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] | 1234 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1235 | /* |
| 1236 | * Protect the call to nfs4_state_set_mode_locked and |
| 1237 | * serialise the stateid update |
| 1238 | */ |
| 1239 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1240 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1241 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1242 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1243 | } |
| 1244 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1245 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1246 | write_sequnlock(&state->seqlock); |
| 1247 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1248 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1249 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1252 | 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] | 1253 | { |
| 1254 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1255 | struct nfs_delegation *deleg_cur; |
| 1256 | int ret = 0; |
| 1257 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1258 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1259 | |
| 1260 | rcu_read_lock(); |
| 1261 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1262 | if (deleg_cur == NULL) |
| 1263 | goto no_delegation; |
| 1264 | |
| 1265 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1266 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1267 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1268 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1269 | goto no_delegation_unlock; |
| 1270 | |
| 1271 | if (delegation == NULL) |
| 1272 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1273 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1274 | goto no_delegation_unlock; |
| 1275 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1276 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1277 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1278 | ret = 1; |
| 1279 | no_delegation_unlock: |
| 1280 | spin_unlock(&deleg_cur->lock); |
| 1281 | no_delegation: |
| 1282 | rcu_read_unlock(); |
| 1283 | |
| 1284 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1285 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1286 | ret = 1; |
| 1287 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1288 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1289 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1290 | |
| 1291 | return ret; |
| 1292 | } |
| 1293 | |
| 1294 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1295 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1296 | { |
| 1297 | struct nfs_delegation *delegation; |
| 1298 | |
| 1299 | rcu_read_lock(); |
| 1300 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1301 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1302 | rcu_read_unlock(); |
| 1303 | return; |
| 1304 | } |
| 1305 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1306 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1307 | } |
| 1308 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1309 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1310 | { |
| 1311 | struct nfs4_state *state = opendata->state; |
| 1312 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1313 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1314 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1315 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1316 | nfs4_stateid stateid; |
| 1317 | int ret = -EAGAIN; |
| 1318 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1319 | for (;;) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1320 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1321 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1322 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1323 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1324 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1325 | } |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1326 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1327 | rcu_read_lock(); |
| 1328 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1329 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1330 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1331 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1332 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1333 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1334 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1335 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1336 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1337 | if (!opendata->is_recover) { |
| 1338 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1339 | if (ret != 0) |
| 1340 | goto out; |
| 1341 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1342 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1343 | |
| 1344 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1345 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1346 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1347 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1348 | out: |
| 1349 | return ERR_PTR(ret); |
| 1350 | out_return_state: |
| 1351 | atomic_inc(&state->count); |
| 1352 | return state; |
| 1353 | } |
| 1354 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1355 | static void |
| 1356 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1357 | { |
| 1358 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1359 | struct nfs_delegation *delegation; |
| 1360 | int delegation_flags = 0; |
| 1361 | |
| 1362 | rcu_read_lock(); |
| 1363 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1364 | if (delegation) |
| 1365 | delegation_flags = delegation->flags; |
| 1366 | rcu_read_unlock(); |
| 1367 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1368 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1369 | "returning a delegation for " |
| 1370 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1371 | clp->cl_hostname); |
| 1372 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1373 | nfs_inode_set_delegation(state->inode, |
| 1374 | data->owner->so_cred, |
| 1375 | &data->o_res); |
| 1376 | else |
| 1377 | nfs_inode_reclaim_delegation(state->inode, |
| 1378 | data->owner->so_cred, |
| 1379 | &data->o_res); |
| 1380 | } |
| 1381 | |
| 1382 | /* |
| 1383 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1384 | * and update the nfs4_state. |
| 1385 | */ |
| 1386 | static struct nfs4_state * |
| 1387 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1388 | { |
| 1389 | struct inode *inode = data->state->inode; |
| 1390 | struct nfs4_state *state = data->state; |
| 1391 | int ret; |
| 1392 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1393 | if (!data->rpc_done) { |
| 1394 | if (data->rpc_status) { |
| 1395 | ret = data->rpc_status; |
| 1396 | goto err; |
| 1397 | } |
| 1398 | /* cached opens have already been processed */ |
| 1399 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1400 | } |
| 1401 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1402 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1403 | if (ret) |
| 1404 | goto err; |
| 1405 | |
| 1406 | if (data->o_res.delegation_type != 0) |
| 1407 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1408 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1409 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1410 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1411 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1412 | |
| 1413 | return state; |
| 1414 | err: |
| 1415 | return ERR_PTR(ret); |
| 1416 | |
| 1417 | } |
| 1418 | |
| 1419 | static struct nfs4_state * |
| 1420 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1421 | { |
| 1422 | struct inode *inode; |
| 1423 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1424 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1425 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1426 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1427 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1428 | goto out; |
| 1429 | } |
| 1430 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1431 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1432 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1433 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1434 | 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] | 1435 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1436 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1437 | goto err; |
| 1438 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1439 | state = nfs4_get_open_state(inode, data->owner); |
| 1440 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1441 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1442 | if (data->o_res.delegation_type != 0) |
| 1443 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1444 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1445 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1446 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1447 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1448 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1449 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1450 | err_put_inode: |
| 1451 | iput(inode); |
| 1452 | err: |
| 1453 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1454 | } |
| 1455 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1456 | static struct nfs4_state * |
| 1457 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1458 | { |
| 1459 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1460 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1461 | return _nfs4_opendata_to_nfs4_state(data); |
| 1462 | } |
| 1463 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1464 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1465 | { |
| 1466 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1467 | struct nfs_open_context *ctx; |
| 1468 | |
| 1469 | spin_lock(&state->inode->i_lock); |
| 1470 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1471 | if (ctx->state != state) |
| 1472 | continue; |
| 1473 | get_nfs_open_context(ctx); |
| 1474 | spin_unlock(&state->inode->i_lock); |
| 1475 | return ctx; |
| 1476 | } |
| 1477 | spin_unlock(&state->inode->i_lock); |
| 1478 | return ERR_PTR(-ENOENT); |
| 1479 | } |
| 1480 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1481 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1482 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1483 | { |
| 1484 | struct nfs4_opendata *opendata; |
| 1485 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1486 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1487 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1488 | if (opendata == NULL) |
| 1489 | return ERR_PTR(-ENOMEM); |
| 1490 | opendata->state = state; |
| 1491 | atomic_inc(&state->count); |
| 1492 | return opendata; |
| 1493 | } |
| 1494 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1495 | 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] | 1496 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1497 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1498 | int ret; |
| 1499 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1500 | opendata->o_arg.open_flags = 0; |
| 1501 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1502 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1503 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1504 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1505 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1506 | if (ret != 0) |
| 1507 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1508 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1509 | if (IS_ERR(newstate)) |
| 1510 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1511 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1512 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1513 | return 0; |
| 1514 | } |
| 1515 | |
| 1516 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1517 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1518 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1519 | int ret; |
| 1520 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1521 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1522 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1523 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1524 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1525 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1526 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1527 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1528 | smp_rmb(); |
| 1529 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1530 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1531 | if (ret != 0) |
| 1532 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1533 | if (newstate != state) |
| 1534 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1535 | } |
| 1536 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1537 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1538 | if (ret != 0) |
| 1539 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1540 | if (newstate != state) |
| 1541 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1542 | } |
| 1543 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1544 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1545 | if (ret != 0) |
| 1546 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1547 | if (newstate != state) |
| 1548 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1549 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1550 | /* |
| 1551 | * We may have performed cached opens for all three recoveries. |
| 1552 | * Check if we need to update the current stateid. |
| 1553 | */ |
| 1554 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1555 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1556 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1557 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1558 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1559 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1560 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1561 | return 0; |
| 1562 | } |
| 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | /* |
| 1565 | * OPEN_RECLAIM: |
| 1566 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1568 | 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] | 1569 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1570 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1571 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1572 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | int status; |
| 1574 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1575 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1576 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1577 | if (IS_ERR(opendata)) |
| 1578 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1579 | rcu_read_lock(); |
| 1580 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1581 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1582 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1583 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1584 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1585 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1586 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | return status; |
| 1588 | } |
| 1589 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1590 | 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] | 1591 | { |
| 1592 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1593 | struct nfs4_exception exception = { }; |
| 1594 | int err; |
| 1595 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1596 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1597 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1598 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1599 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1600 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1601 | break; |
| 1602 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | } while (exception.retry); |
| 1604 | return err; |
| 1605 | } |
| 1606 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1607 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1608 | { |
| 1609 | struct nfs_open_context *ctx; |
| 1610 | int ret; |
| 1611 | |
| 1612 | ctx = nfs4_state_find_open_context(state); |
| 1613 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1614 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1615 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1616 | put_nfs_open_context(ctx); |
| 1617 | return ret; |
| 1618 | } |
| 1619 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1620 | 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] | 1621 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1622 | switch (err) { |
| 1623 | default: |
| 1624 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1625 | "%d.\n", __func__, err); |
| 1626 | case 0: |
| 1627 | case -ENOENT: |
| 1628 | case -ESTALE: |
| 1629 | break; |
| 1630 | case -NFS4ERR_BADSESSION: |
| 1631 | case -NFS4ERR_BADSLOT: |
| 1632 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1633 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1634 | case -NFS4ERR_DEADSESSION: |
| 1635 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1636 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1637 | return -EAGAIN; |
| 1638 | case -NFS4ERR_STALE_CLIENTID: |
| 1639 | case -NFS4ERR_STALE_STATEID: |
| 1640 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1641 | case -NFS4ERR_EXPIRED: |
| 1642 | /* Don't recall a delegation if it was lost */ |
| 1643 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1644 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1645 | case -NFS4ERR_MOVED: |
| 1646 | nfs4_schedule_migration_recovery(server); |
| 1647 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1648 | case -NFS4ERR_LEASE_MOVED: |
| 1649 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1650 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1651 | case -NFS4ERR_DELEG_REVOKED: |
| 1652 | case -NFS4ERR_ADMIN_REVOKED: |
| 1653 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1654 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1655 | nfs_inode_find_state_and_recover(state->inode, |
| 1656 | stateid); |
| 1657 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1658 | return 0; |
| 1659 | case -NFS4ERR_DELAY: |
| 1660 | case -NFS4ERR_GRACE: |
| 1661 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1662 | ssleep(1); |
| 1663 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1664 | case -ENOMEM: |
| 1665 | case -NFS4ERR_DENIED: |
| 1666 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1667 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | return err; |
| 1670 | } |
| 1671 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1672 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1673 | { |
| 1674 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1675 | struct nfs4_opendata *opendata; |
| 1676 | int err; |
| 1677 | |
| 1678 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1679 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1680 | if (IS_ERR(opendata)) |
| 1681 | return PTR_ERR(opendata); |
| 1682 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1683 | err = nfs4_open_recover(opendata, state); |
| 1684 | nfs4_opendata_put(opendata); |
| 1685 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1686 | } |
| 1687 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1688 | static void nfs4_open_confirm_prepare(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_setup_sequence(data->o_arg.server, &data->c_arg.seq_args, |
| 1693 | &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1694 | } |
| 1695 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1696 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1697 | { |
| 1698 | struct nfs4_opendata *data = calldata; |
| 1699 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1700 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1701 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1702 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1703 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1704 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1705 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1706 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1707 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1708 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | static void nfs4_open_confirm_release(void *calldata) |
| 1712 | { |
| 1713 | struct nfs4_opendata *data = calldata; |
| 1714 | struct nfs4_state *state = NULL; |
| 1715 | |
| 1716 | /* If this request hasn't been cancelled, do nothing */ |
| 1717 | if (data->cancelled == 0) |
| 1718 | goto out_free; |
| 1719 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1720 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1721 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1722 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1723 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1724 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1725 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1726 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1730 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1731 | .rpc_call_done = nfs4_open_confirm_done, |
| 1732 | .rpc_release = nfs4_open_confirm_release, |
| 1733 | }; |
| 1734 | |
| 1735 | /* |
| 1736 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1737 | */ |
| 1738 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1739 | { |
| 1740 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1741 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1742 | struct rpc_message msg = { |
| 1743 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1744 | .rpc_argp = &data->c_arg, |
| 1745 | .rpc_resp = &data->c_res, |
| 1746 | .rpc_cred = data->owner->so_cred, |
| 1747 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1748 | struct rpc_task_setup task_setup_data = { |
| 1749 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1750 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1751 | .callback_ops = &nfs4_open_confirm_ops, |
| 1752 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1753 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1754 | .flags = RPC_TASK_ASYNC, |
| 1755 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | int status; |
| 1757 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1758 | 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] | 1759 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1760 | data->rpc_done = 0; |
| 1761 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1762 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1763 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1764 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1765 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1766 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1767 | if (status != 0) { |
| 1768 | data->cancelled = 1; |
| 1769 | smp_wmb(); |
| 1770 | } else |
| 1771 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1772 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | return status; |
| 1774 | } |
| 1775 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1776 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1778 | struct nfs4_opendata *data = calldata; |
| 1779 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1780 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1781 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1782 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1783 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1784 | /* |
| 1785 | * Check if we still need to send an OPEN call, or if we can use |
| 1786 | * a delegation instead. |
| 1787 | */ |
| 1788 | if (data->state != NULL) { |
| 1789 | struct nfs_delegation *delegation; |
| 1790 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1791 | 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] | 1792 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1793 | rcu_read_lock(); |
| 1794 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1795 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1796 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1797 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1798 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1799 | rcu_read_unlock(); |
| 1800 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1801 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1802 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1803 | switch (data->o_arg.claim) { |
| 1804 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1805 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1806 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1807 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1808 | case NFS4_OPEN_CLAIM_FH: |
| 1809 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1810 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1811 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1812 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1813 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1814 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1815 | &data->o_res.seq_res, |
| 1816 | task) != 0) |
| 1817 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1818 | |
| 1819 | /* Set the create mode (note dependency on the session type) */ |
| 1820 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1821 | if (data->o_arg.open_flags & O_EXCL) { |
| 1822 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1823 | if (nfs4_has_persistent_session(clp)) |
| 1824 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1825 | else if (clp->cl_mvops->minor_version > 0) |
| 1826 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1827 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1828 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1829 | unlock_no_action: |
| 1830 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1831 | out_no_action: |
| 1832 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1833 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1834 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1835 | } |
| 1836 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1837 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1838 | { |
| 1839 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1841 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1842 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1843 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1844 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1845 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1846 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1847 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1848 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1849 | case S_IFREG: |
| 1850 | break; |
| 1851 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1852 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1853 | break; |
| 1854 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1855 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1856 | break; |
| 1857 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1858 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1859 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1860 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1861 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1862 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1863 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1864 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1865 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1866 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1867 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1868 | static void nfs4_open_release(void *calldata) |
| 1869 | { |
| 1870 | struct nfs4_opendata *data = calldata; |
| 1871 | struct nfs4_state *state = NULL; |
| 1872 | |
| 1873 | /* If this request hasn't been cancelled, do nothing */ |
| 1874 | if (data->cancelled == 0) |
| 1875 | goto out_free; |
| 1876 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1877 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1878 | goto out_free; |
| 1879 | /* In case we need an open_confirm, no cleanup! */ |
| 1880 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1881 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1882 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1883 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1884 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1885 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1886 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1890 | .rpc_call_prepare = nfs4_open_prepare, |
| 1891 | .rpc_call_done = nfs4_open_done, |
| 1892 | .rpc_release = nfs4_open_release, |
| 1893 | }; |
| 1894 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1895 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1896 | { |
| 1897 | struct inode *dir = data->dir->d_inode; |
| 1898 | struct nfs_server *server = NFS_SERVER(dir); |
| 1899 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1900 | struct nfs_openres *o_res = &data->o_res; |
| 1901 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1902 | struct rpc_message msg = { |
| 1903 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1904 | .rpc_argp = o_arg, |
| 1905 | .rpc_resp = o_res, |
| 1906 | .rpc_cred = data->owner->so_cred, |
| 1907 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1908 | struct rpc_task_setup task_setup_data = { |
| 1909 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1910 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1911 | .callback_ops = &nfs4_open_ops, |
| 1912 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1913 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1914 | .flags = RPC_TASK_ASYNC, |
| 1915 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1916 | int status; |
| 1917 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1918 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1919 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1920 | data->rpc_done = 0; |
| 1921 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1922 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1923 | data->is_recover = 0; |
| 1924 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1925 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1926 | data->is_recover = 1; |
| 1927 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1928 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1929 | if (IS_ERR(task)) |
| 1930 | return PTR_ERR(task); |
| 1931 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1932 | if (status != 0) { |
| 1933 | data->cancelled = 1; |
| 1934 | smp_wmb(); |
| 1935 | } else |
| 1936 | status = data->rpc_status; |
| 1937 | rpc_put_task(task); |
| 1938 | |
| 1939 | return status; |
| 1940 | } |
| 1941 | |
| 1942 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1943 | { |
| 1944 | struct inode *dir = data->dir->d_inode; |
| 1945 | struct nfs_openres *o_res = &data->o_res; |
| 1946 | int status; |
| 1947 | |
| 1948 | status = nfs4_run_open_task(data, 1); |
| 1949 | if (status != 0 || !data->rpc_done) |
| 1950 | return status; |
| 1951 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1952 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1953 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1954 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1955 | status = _nfs4_proc_open_confirm(data); |
| 1956 | if (status != 0) |
| 1957 | return status; |
| 1958 | } |
| 1959 | |
| 1960 | return status; |
| 1961 | } |
| 1962 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1963 | /* |
| 1964 | * Additional permission checks in order to distinguish between an |
| 1965 | * open for read, and an open for execute. This works around the |
| 1966 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 1967 | * the same. |
| 1968 | * Note that in the non-execute case, we want to turn off permission |
| 1969 | * checking if we just created a new file (POSIX open() semantics). |
| 1970 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1971 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1972 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1973 | struct nfs4_state *state, fmode_t fmode, |
| 1974 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1975 | { |
| 1976 | struct nfs_access_entry cache; |
| 1977 | u32 mask; |
| 1978 | |
| 1979 | /* access call failed or for some reason the server doesn't |
| 1980 | * support any access modes -- defer access call until later */ |
| 1981 | if (opendata->o_res.access_supported == 0) |
| 1982 | return 0; |
| 1983 | |
| 1984 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1985 | /* |
| 1986 | * Use openflags to check for exec, because fmode won't |
| 1987 | * always have FMODE_EXEC set when file open for exec. |
| 1988 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1989 | if (openflags & __FMODE_EXEC) { |
| 1990 | /* ONLY check for exec rights */ |
| 1991 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1992 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1993 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1994 | |
| 1995 | cache.cred = cred; |
| 1996 | cache.jiffies = jiffies; |
| 1997 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1998 | nfs_access_add_cache(state->inode, &cache); |
| 1999 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2000 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2001 | return 0; |
| 2002 | |
| 2003 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2004 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2005 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2006 | } |
| 2007 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2008 | /* |
| 2009 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2010 | */ |
| 2011 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2012 | { |
| 2013 | struct inode *dir = data->dir->d_inode; |
| 2014 | struct nfs_server *server = NFS_SERVER(dir); |
| 2015 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2016 | struct nfs_openres *o_res = &data->o_res; |
| 2017 | int status; |
| 2018 | |
| 2019 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2020 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2021 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2022 | if (status != 0) { |
| 2023 | if (status == -NFS4ERR_BADNAME && |
| 2024 | !(o_arg->open_flags & O_CREAT)) |
| 2025 | return -ENOENT; |
| 2026 | return status; |
| 2027 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2028 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2029 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2030 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2031 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2032 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2033 | if (o_arg->open_flags & O_EXCL) |
| 2034 | data->file_created = 1; |
| 2035 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2036 | data->file_created = 1; |
| 2037 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2038 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2039 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2041 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2043 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | } |
| 2045 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2046 | 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] | 2047 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2050 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2051 | { |
| 2052 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2053 | } |
| 2054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | /* |
| 2056 | * OPEN_EXPIRED: |
| 2057 | * reclaim state on the server after a network partition. |
| 2058 | * Assumes caller holds the appropriate lock |
| 2059 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2060 | 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] | 2061 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2062 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2063 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2065 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2066 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2067 | if (IS_ERR(opendata)) |
| 2068 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2069 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2070 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2071 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2072 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2073 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2076 | 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] | 2077 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2078 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2079 | struct nfs4_exception exception = { }; |
| 2080 | int err; |
| 2081 | |
| 2082 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2083 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2084 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2085 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2086 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2087 | switch (err) { |
| 2088 | default: |
| 2089 | goto out; |
| 2090 | case -NFS4ERR_GRACE: |
| 2091 | case -NFS4ERR_DELAY: |
| 2092 | nfs4_handle_exception(server, err, &exception); |
| 2093 | err = 0; |
| 2094 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2095 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2096 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2097 | return err; |
| 2098 | } |
| 2099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2101 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2103 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2105 | ctx = nfs4_state_find_open_context(state); |
| 2106 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2107 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2108 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2109 | put_nfs_open_context(ctx); |
| 2110 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2113 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2114 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2115 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2116 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2117 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2118 | struct nfs_delegation *delegation; |
| 2119 | struct rpc_cred *cred = NULL; |
| 2120 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2121 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2122 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2123 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 2124 | return; |
| 2125 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2126 | /* Get the delegation credential for use by test/free_stateid */ |
| 2127 | rcu_read_lock(); |
| 2128 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 2129 | if (delegation != NULL && |
| 2130 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 2131 | cred = get_rpccred(delegation->cred); |
| 2132 | rcu_read_unlock(); |
| 2133 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2134 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2135 | } else |
| 2136 | rcu_read_unlock(); |
| 2137 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2138 | if (status != NFS_OK) { |
| 2139 | /* Free the stateid unless the server explicitly |
| 2140 | * informs us the stateid is unrecognized. */ |
| 2141 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2142 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2143 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2144 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2145 | write_seqlock(&state->seqlock); |
| 2146 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2147 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2148 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2149 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2150 | |
| 2151 | if (cred != NULL) |
| 2152 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | /** |
| 2156 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2157 | * |
| 2158 | * @state: NFSv4 state for an inode |
| 2159 | * |
| 2160 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2161 | * Otherwise a negative NFS4ERR value is returned. |
| 2162 | */ |
| 2163 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2164 | { |
| 2165 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2166 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2167 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2168 | int status; |
| 2169 | |
| 2170 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2171 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2172 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2173 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2174 | return -NFS4ERR_BAD_STATEID; |
| 2175 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2176 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2177 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2178 | if (status != NFS_OK) { |
| 2179 | /* Free the stateid unless the server explicitly |
| 2180 | * informs us the stateid is unrecognized. */ |
| 2181 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2182 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2183 | |
| 2184 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2185 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2186 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2187 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2188 | } |
| 2189 | return status; |
| 2190 | } |
| 2191 | |
| 2192 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2193 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2194 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2195 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2196 | nfs41_clear_delegation_stateid(state); |
| 2197 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2198 | if (status != NFS_OK) |
| 2199 | status = nfs4_open_expired(sp, state); |
| 2200 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2201 | } |
| 2202 | #endif |
| 2203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2205 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2206 | * fields corresponding to attributes that were used to store the verifier. |
| 2207 | * Make sure we clobber those fields in the later setattr call |
| 2208 | */ |
| 2209 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2210 | { |
| 2211 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2212 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2213 | sattr->ia_valid |= ATTR_ATIME; |
| 2214 | |
| 2215 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2216 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2217 | sattr->ia_valid |= ATTR_MTIME; |
| 2218 | } |
| 2219 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2220 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2221 | fmode_t fmode, |
| 2222 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2223 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2224 | { |
| 2225 | struct nfs4_state_owner *sp = opendata->owner; |
| 2226 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2227 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2228 | struct nfs4_state *state; |
| 2229 | unsigned int seq; |
| 2230 | int ret; |
| 2231 | |
| 2232 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2233 | |
| 2234 | ret = _nfs4_proc_open(opendata); |
NeilBrown | 4fa2c54 | 2014-07-21 13:28:28 +1000 | [diff] [blame] | 2235 | if (ret != 0) { |
| 2236 | if (ret == -ENOENT) { |
| 2237 | d_drop(opendata->dentry); |
| 2238 | d_add(opendata->dentry, NULL); |
| 2239 | nfs_set_verifier(opendata->dentry, |
| 2240 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2241 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2242 | goto out; |
NeilBrown | 4fa2c54 | 2014-07-21 13:28:28 +1000 | [diff] [blame] | 2243 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2244 | |
| 2245 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2246 | ret = PTR_ERR(state); |
| 2247 | if (IS_ERR(state)) |
| 2248 | goto out; |
| 2249 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2250 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2251 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2252 | dentry = opendata->dentry; |
| 2253 | if (dentry->d_inode == NULL) { |
| 2254 | /* FIXME: Is this d_drop() ever needed? */ |
| 2255 | d_drop(dentry); |
| 2256 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2257 | if (dentry == NULL) { |
| 2258 | dentry = opendata->dentry; |
| 2259 | } else if (dentry != ctx->dentry) { |
| 2260 | dput(ctx->dentry); |
| 2261 | ctx->dentry = dget(dentry); |
| 2262 | } |
| 2263 | nfs_set_verifier(dentry, |
| 2264 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2265 | } |
| 2266 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2267 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2268 | if (ret != 0) |
| 2269 | goto out; |
| 2270 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2271 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2272 | if (dentry->d_inode == state->inode) { |
| 2273 | nfs_inode_attach_open_context(ctx); |
| 2274 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2275 | nfs4_schedule_stateid_recovery(server, state); |
| 2276 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2277 | out: |
| 2278 | return ret; |
| 2279 | } |
| 2280 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2281 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2282 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2284 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2285 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2286 | int flags, |
| 2287 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2288 | struct nfs4_label *label, |
| 2289 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | { |
| 2291 | struct nfs4_state_owner *sp; |
| 2292 | struct nfs4_state *state = NULL; |
| 2293 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2294 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2295 | struct dentry *dentry = ctx->dentry; |
| 2296 | struct rpc_cred *cred = ctx->cred; |
| 2297 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2298 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2299 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2300 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2301 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | |
| 2303 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2305 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2306 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2308 | goto out_err; |
| 2309 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2310 | status = nfs4_recover_expired_lease(server); |
| 2311 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2312 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2313 | if (dentry->d_inode != NULL) |
| 2314 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2315 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2316 | if (dentry->d_inode) |
| 2317 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2318 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2319 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2320 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2321 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2323 | if (label) { |
| 2324 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2325 | if (IS_ERR(olabel)) { |
| 2326 | status = PTR_ERR(olabel); |
| 2327 | goto err_opendata_put; |
| 2328 | } |
| 2329 | } |
| 2330 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2331 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2332 | if (!opendata->f_attr.mdsthreshold) { |
| 2333 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2334 | if (!opendata->f_attr.mdsthreshold) |
| 2335 | goto err_free_label; |
| 2336 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2337 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2338 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2339 | if (dentry->d_inode != NULL) |
| 2340 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2341 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2342 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2343 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2344 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2345 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2346 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2347 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2348 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2349 | nfs4_exclusive_attrset(opendata, sattr); |
| 2350 | |
| 2351 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2352 | status = nfs4_do_setattr(state->inode, cred, |
| 2353 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2354 | state, label, olabel); |
| 2355 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2356 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2357 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2358 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2359 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2360 | } |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2361 | if (opendata->file_created) |
| 2362 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2363 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2364 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2365 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2366 | opendata->f_attr.mdsthreshold = NULL; |
| 2367 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2368 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2369 | nfs4_label_free(olabel); |
| 2370 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2371 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2374 | err_free_label: |
| 2375 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2376 | err_opendata_put: |
| 2377 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2378 | err_put_state_owner: |
| 2379 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | return status; |
| 2382 | } |
| 2383 | |
| 2384 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2385 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2386 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2387 | int flags, |
| 2388 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2389 | struct nfs4_label *label, |
| 2390 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2392 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | struct nfs4_exception exception = { }; |
| 2394 | struct nfs4_state *res; |
| 2395 | int status; |
| 2396 | |
| 2397 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2398 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2399 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2400 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | if (status == 0) |
| 2402 | break; |
| 2403 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2404 | * book-keeping w.r.t. state-changing operations |
| 2405 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2406 | * It is actually a sign of a bug on the client or on the server. |
| 2407 | * |
| 2408 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2409 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | * have unhashed the old state_owner for us, and that we can |
| 2411 | * therefore safely retry using a new one. We should still warn |
| 2412 | * the user though... |
| 2413 | */ |
| 2414 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2415 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2416 | " returned a bad sequence-id error!\n", |
| 2417 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | exception.retry = 1; |
| 2419 | continue; |
| 2420 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2421 | /* |
| 2422 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2423 | * state before it received the OPEN_CONFIRM. |
| 2424 | * Recover by retrying the request as per the discussion |
| 2425 | * on Page 181 of RFC3530. |
| 2426 | */ |
| 2427 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2428 | exception.retry = 1; |
| 2429 | continue; |
| 2430 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2431 | if (status == -EAGAIN) { |
| 2432 | /* We must have found a delegation */ |
| 2433 | exception.retry = 1; |
| 2434 | continue; |
| 2435 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2436 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2437 | continue; |
| 2438 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | status, &exception)); |
| 2440 | } while (exception.retry); |
| 2441 | return res; |
| 2442 | } |
| 2443 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2444 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2445 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2446 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2447 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2449 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2451 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | .iap = sattr, |
| 2453 | .server = server, |
| 2454 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2455 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | }; |
| 2457 | struct nfs_setattrres res = { |
| 2458 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2459 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | .server = server, |
| 2461 | }; |
| 2462 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2463 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2464 | .rpc_argp = &arg, |
| 2465 | .rpc_resp = &res, |
| 2466 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2468 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2469 | fmode_t fmode; |
| 2470 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2471 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2473 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2474 | if (ilabel) |
| 2475 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2476 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2477 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2479 | /* Servers should only apply open mode checks for file size changes */ |
| 2480 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2481 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2482 | |
| 2483 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2484 | /* Use that stateid */ |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2485 | } else if (truncate && state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2486 | struct nfs_lockowner lockowner = { |
| 2487 | .l_owner = current->files, |
| 2488 | .l_pid = current->tgid, |
| 2489 | }; |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2490 | if (!nfs4_valid_open_stateid(state)) |
| 2491 | return -EBADF; |
| 2492 | if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2493 | &lockowner) == -EIO) |
| 2494 | return -EBADF; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2495 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2496 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2498 | 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] | 2499 | if (status == 0 && state != NULL) |
| 2500 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2501 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2504 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2505 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2506 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2507 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2509 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2510 | struct nfs4_exception exception = { |
| 2511 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2512 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2513 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | int err; |
| 2515 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2516 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2517 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2518 | switch (err) { |
| 2519 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2520 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2521 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2522 | "applying open mode checks to " |
| 2523 | "a SETATTR that is not " |
| 2524 | "changing file size.\n", |
| 2525 | server->nfs_client->cl_hostname); |
| 2526 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2527 | if (state && !(state->state & FMODE_WRITE)) { |
| 2528 | err = -EBADF; |
| 2529 | if (sattr->ia_valid & ATTR_OPEN) |
| 2530 | err = -EACCES; |
| 2531 | goto out; |
| 2532 | } |
| 2533 | } |
| 2534 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2536 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | return err; |
| 2538 | } |
| 2539 | |
| 2540 | struct nfs4_closedata { |
| 2541 | struct inode *inode; |
| 2542 | struct nfs4_state *state; |
| 2543 | struct nfs_closeargs arg; |
| 2544 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2545 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2546 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2547 | bool roc; |
| 2548 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | }; |
| 2550 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2551 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2552 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2553 | struct nfs4_closedata *calldata = data; |
| 2554 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2555 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2556 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2557 | if (calldata->roc) |
| 2558 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2559 | nfs4_put_open_state(calldata->state); |
| 2560 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2561 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2562 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2563 | kfree(calldata); |
| 2564 | } |
| 2565 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2566 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2568 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2571 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2573 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2574 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2575 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2576 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | /* hmm. we are done with the inode, and in the process of freeing |
| 2578 | * the state_owner. we keep this around to process errors |
| 2579 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | switch (task->tk_status) { |
| 2581 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2582 | res_stateid = &calldata->res.stateid; |
| 2583 | if (calldata->arg.fmode == 0 && calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2584 | pnfs_roc_set_barrier(state->inode, |
| 2585 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2586 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2587 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2588 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2590 | case -NFS4ERR_OLD_STATEID: |
| 2591 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2593 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2594 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 2596 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2597 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2598 | goto out_release; |
| 2599 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | } |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2601 | nfs_clear_open_stateid(state, res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2602 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2603 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2604 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2605 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2608 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2610 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2611 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2612 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2613 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2614 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2615 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2616 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2617 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2618 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2619 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2620 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2621 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2622 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2623 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2624 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2625 | /* Calculate the current open share mode */ |
| 2626 | calldata->arg.fmode = 0; |
| 2627 | if (is_rdonly || is_rdwr) |
| 2628 | calldata->arg.fmode |= FMODE_READ; |
| 2629 | if (is_wronly || is_rdwr) |
| 2630 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2631 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2632 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2633 | if (state->n_rdonly == 0) { |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2634 | call_close |= is_rdonly || is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2635 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2636 | } |
| 2637 | if (state->n_wronly == 0) { |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2638 | call_close |= is_wronly || is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2639 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2640 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2641 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2642 | if (!nfs4_valid_open_stateid(state)) |
| 2643 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2644 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2645 | |
| 2646 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2647 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2648 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2649 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2650 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2651 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2652 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2653 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2654 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2655 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2656 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2657 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2658 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2659 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2660 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2661 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2662 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2663 | &calldata->arg.seq_args, |
| 2664 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2665 | task) != 0) |
| 2666 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2667 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2668 | return; |
| 2669 | out_no_action: |
| 2670 | task->tk_action = NULL; |
| 2671 | out_wait: |
| 2672 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2675 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2676 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2677 | .rpc_call_done = nfs4_close_done, |
| 2678 | .rpc_release = nfs4_free_closedata, |
| 2679 | }; |
| 2680 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2681 | static bool nfs4_state_has_opener(struct nfs4_state *state) |
| 2682 | { |
| 2683 | /* first check existing openers */ |
| 2684 | if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 && |
| 2685 | state->n_rdonly != 0) |
| 2686 | return true; |
| 2687 | |
| 2688 | if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 && |
| 2689 | state->n_wronly != 0) |
| 2690 | return true; |
| 2691 | |
| 2692 | if (test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 && |
| 2693 | state->n_rdwr != 0) |
| 2694 | return true; |
| 2695 | |
| 2696 | return false; |
| 2697 | } |
| 2698 | |
| 2699 | static bool nfs4_roc(struct inode *inode) |
| 2700 | { |
| 2701 | struct nfs_inode *nfsi = NFS_I(inode); |
| 2702 | struct nfs_open_context *ctx; |
| 2703 | struct nfs4_state *state; |
| 2704 | |
| 2705 | spin_lock(&inode->i_lock); |
| 2706 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 2707 | state = ctx->state; |
| 2708 | if (state == NULL) |
| 2709 | continue; |
| 2710 | if (nfs4_state_has_opener(state)) { |
| 2711 | spin_unlock(&inode->i_lock); |
| 2712 | return false; |
| 2713 | } |
| 2714 | } |
| 2715 | spin_unlock(&inode->i_lock); |
| 2716 | |
| 2717 | if (nfs4_check_delegation(inode, FMODE_READ)) |
| 2718 | return false; |
| 2719 | |
| 2720 | return pnfs_roc(inode); |
| 2721 | } |
| 2722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | /* |
| 2724 | * It is possible for data to be read/written from a mem-mapped file |
| 2725 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2726 | * This means that we can't safely call nfsv4 close on a file until |
| 2727 | * the inode is cleared. This in turn means that we are not good |
| 2728 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2729 | * share state even when we are done with one of the three share |
| 2730 | * stateid's in the inode. |
| 2731 | * |
| 2732 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2733 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2734 | 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] | 2735 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2736 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2738 | struct nfs4_state_owner *sp = state->owner; |
| 2739 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2740 | struct rpc_message msg = { |
| 2741 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2742 | .rpc_cred = state->owner->so_cred, |
| 2743 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2744 | struct rpc_task_setup task_setup_data = { |
| 2745 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2746 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2747 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2748 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2749 | .flags = RPC_TASK_ASYNC, |
| 2750 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2751 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2753 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2754 | &task_setup_data.rpc_client, &msg); |
| 2755 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2756 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2758 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2759 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2760 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2762 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2763 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2765 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2766 | if (calldata->arg.seqid == NULL) |
| 2767 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2768 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2769 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2770 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2771 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2772 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2773 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2774 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2775 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2776 | msg.rpc_argp = &calldata->arg; |
| 2777 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2778 | task_setup_data.callback_data = calldata; |
| 2779 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2780 | if (IS_ERR(task)) |
| 2781 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2782 | status = 0; |
| 2783 | if (wait) |
| 2784 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2785 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2786 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2787 | out_free_calldata: |
| 2788 | kfree(calldata); |
| 2789 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2790 | nfs4_put_open_state(state); |
| 2791 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2792 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2795 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2796 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 2797 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2800 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2801 | |
| 2802 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2804 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2805 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2806 | |
| 2807 | nfs4_label_release_security(label); |
| 2808 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2809 | if (IS_ERR(state)) |
| 2810 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2811 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2814 | 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] | 2815 | { |
| 2816 | if (ctx->state == NULL) |
| 2817 | return; |
| 2818 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2819 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2820 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2821 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2822 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2824 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 2825 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 2826 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2829 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2830 | struct nfs4_server_caps_arg args = { |
| 2831 | .fhandle = fhandle, |
| 2832 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | struct nfs4_server_caps_res res = {}; |
| 2834 | struct rpc_message msg = { |
| 2835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2836 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | .rpc_resp = &res, |
| 2838 | }; |
| 2839 | int status; |
| 2840 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2841 | 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] | 2842 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2843 | /* Sanity check the server answers */ |
| 2844 | switch (server->nfs_client->cl_minorversion) { |
| 2845 | case 0: |
| 2846 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 2847 | res.attr_bitmask[2] = 0; |
| 2848 | break; |
| 2849 | case 1: |
| 2850 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 2851 | break; |
| 2852 | case 2: |
| 2853 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 2854 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2856 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2857 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2858 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2859 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2860 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 2861 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 2862 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 2863 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | server->caps |= NFS_CAP_ACLS; |
| 2865 | if (res.has_links != 0) |
| 2866 | server->caps |= NFS_CAP_HARDLINKS; |
| 2867 | if (res.has_symlinks != 0) |
| 2868 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2869 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2870 | server->caps |= NFS_CAP_FILEID; |
| 2871 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2872 | server->caps |= NFS_CAP_MODE; |
| 2873 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2874 | server->caps |= NFS_CAP_NLINK; |
| 2875 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2876 | server->caps |= NFS_CAP_OWNER; |
| 2877 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2878 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2879 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2880 | server->caps |= NFS_CAP_ATIME; |
| 2881 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2882 | server->caps |= NFS_CAP_CTIME; |
| 2883 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2884 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2885 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2886 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2887 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2888 | #endif |
| 2889 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2890 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2891 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2892 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2893 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2894 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2895 | 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] | 2896 | server->cache_consistency_bitmask[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2898 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | return status; |
| 2902 | } |
| 2903 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2904 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | { |
| 2906 | struct nfs4_exception exception = { }; |
| 2907 | int err; |
| 2908 | do { |
| 2909 | err = nfs4_handle_exception(server, |
| 2910 | _nfs4_server_capabilities(server, fhandle), |
| 2911 | &exception); |
| 2912 | } while (exception.retry); |
| 2913 | return err; |
| 2914 | } |
| 2915 | |
| 2916 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2917 | struct nfs_fsinfo *info) |
| 2918 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2919 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2921 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | }; |
| 2923 | struct nfs4_lookup_res res = { |
| 2924 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2925 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | .fh = fhandle, |
| 2927 | }; |
| 2928 | struct rpc_message msg = { |
| 2929 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2930 | .rpc_argp = &args, |
| 2931 | .rpc_resp = &res, |
| 2932 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2933 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2934 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2935 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2936 | /* |
| 2937 | * Process the label in the upcoming getfattr |
| 2938 | */ |
| 2939 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2940 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2941 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2942 | 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] | 2943 | } |
| 2944 | |
| 2945 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2946 | struct nfs_fsinfo *info) |
| 2947 | { |
| 2948 | struct nfs4_exception exception = { }; |
| 2949 | int err; |
| 2950 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2951 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2952 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2953 | switch (err) { |
| 2954 | case 0: |
| 2955 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2956 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2957 | default: |
| 2958 | err = nfs4_handle_exception(server, err, &exception); |
| 2959 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2961 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | return err; |
| 2963 | } |
| 2964 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2965 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2966 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2967 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2968 | struct rpc_auth_create_args auth_args = { |
| 2969 | .pseudoflavor = flavor, |
| 2970 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2971 | struct rpc_auth *auth; |
| 2972 | int ret; |
| 2973 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2974 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2975 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2976 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2977 | goto out; |
| 2978 | } |
| 2979 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2980 | out: |
| 2981 | return ret; |
| 2982 | } |
| 2983 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2984 | /* |
| 2985 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2986 | * |
| 2987 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2988 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2989 | * |
| 2990 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2991 | * negative errno value. |
| 2992 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2993 | 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] | 2994 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2996 | /* Per 3530bis 15.33.5 */ |
| 2997 | static const rpc_authflavor_t flav_array[] = { |
| 2998 | RPC_AUTH_GSS_KRB5P, |
| 2999 | RPC_AUTH_GSS_KRB5I, |
| 3000 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3001 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3002 | RPC_AUTH_NULL, |
| 3003 | }; |
| 3004 | int status = -EPERM; |
| 3005 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3007 | if (server->auth_info.flavor_len > 0) { |
| 3008 | /* try each flavor specified by user */ |
| 3009 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3010 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3011 | server->auth_info.flavors[i]); |
| 3012 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3013 | continue; |
| 3014 | break; |
| 3015 | } |
| 3016 | } else { |
| 3017 | /* no flavors specified by user, try default list */ |
| 3018 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3019 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3020 | flav_array[i]); |
| 3021 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3022 | continue; |
| 3023 | break; |
| 3024 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3025 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3026 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3027 | /* |
| 3028 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3029 | * to access the mount. It could also mean that we tried to mount |
| 3030 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3031 | * existing mount programs don't handle -EACCES very well so it should |
| 3032 | * be mapped to -EPERM instead. |
| 3033 | */ |
| 3034 | if (status == -EACCES) |
| 3035 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3036 | return status; |
| 3037 | } |
| 3038 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3039 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 3040 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 3041 | { |
| 3042 | int mv = server->nfs_client->cl_minorversion; |
| 3043 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3048 | * @server: initialized nfs_server handle |
| 3049 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3050 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3051 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3052 | * |
| 3053 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3054 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3055 | 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] | 3056 | struct nfs_fsinfo *info, |
| 3057 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3058 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3059 | int status; |
| 3060 | |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3061 | switch (auth_probe) { |
| 3062 | case false: |
| 3063 | status = nfs4_lookup_root(server, fhandle, info); |
| 3064 | if (status != -NFS4ERR_WRONGSEC) |
| 3065 | break; |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3066 | default: |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3067 | status = nfs4_do_find_root_sec(server, fhandle, info); |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3068 | } |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | if (status == 0) |
| 3071 | status = nfs4_server_capabilities(server, fhandle); |
| 3072 | if (status == 0) |
| 3073 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3074 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3075 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3078 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3079 | struct nfs_fsinfo *info) |
| 3080 | { |
| 3081 | int error; |
| 3082 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3083 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3084 | |
| 3085 | error = nfs4_server_capabilities(server, mntfh); |
| 3086 | if (error < 0) { |
| 3087 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3088 | return error; |
| 3089 | } |
| 3090 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3091 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3092 | if (IS_ERR(label)) |
| 3093 | return PTR_ERR(label); |
| 3094 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3095 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3096 | if (error < 0) { |
| 3097 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3098 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3102 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3103 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3104 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3105 | err_free_label: |
| 3106 | nfs4_label_free(label); |
| 3107 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3108 | return error; |
| 3109 | } |
| 3110 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3111 | /* |
| 3112 | * Get locations and (maybe) other attributes of a referral. |
| 3113 | * Note that we'll actually follow the referral later when |
| 3114 | * we detect fsid mismatch in inode revalidation |
| 3115 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3116 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3117 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3118 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3119 | { |
| 3120 | int status = -ENOMEM; |
| 3121 | struct page *page = NULL; |
| 3122 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3123 | |
| 3124 | page = alloc_page(GFP_KERNEL); |
| 3125 | if (page == NULL) |
| 3126 | goto out; |
| 3127 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3128 | if (locations == NULL) |
| 3129 | goto out; |
| 3130 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3131 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3132 | if (status != 0) |
| 3133 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3134 | |
| 3135 | /* |
| 3136 | * If the fsid didn't change, this is a migration event, not a |
| 3137 | * referral. Cause us to drop into the exception handler, which |
| 3138 | * will kick off migration recovery. |
| 3139 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3140 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3141 | dprintk("%s: server did not return a different fsid for" |
| 3142 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3143 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3144 | goto out; |
| 3145 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3146 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3147 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3148 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3149 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3150 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3151 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3152 | out: |
| 3153 | if (page) |
| 3154 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3155 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3156 | return status; |
| 3157 | } |
| 3158 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3159 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3160 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | { |
| 3162 | struct nfs4_getattr_arg args = { |
| 3163 | .fh = fhandle, |
| 3164 | .bitmask = server->attr_bitmask, |
| 3165 | }; |
| 3166 | struct nfs4_getattr_res res = { |
| 3167 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3168 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | .server = server, |
| 3170 | }; |
| 3171 | struct rpc_message msg = { |
| 3172 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3173 | .rpc_argp = &args, |
| 3174 | .rpc_resp = &res, |
| 3175 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3176 | |
| 3177 | args.bitmask = nfs4_bitmask(server, label); |
| 3178 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3179 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3180 | 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] | 3181 | } |
| 3182 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3183 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3184 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | { |
| 3186 | struct nfs4_exception exception = { }; |
| 3187 | int err; |
| 3188 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3189 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3190 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3191 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | &exception); |
| 3193 | } while (exception.retry); |
| 3194 | return err; |
| 3195 | } |
| 3196 | |
| 3197 | /* |
| 3198 | * The file is not closed if it is opened due to the a request to change |
| 3199 | * the size of the file. The open call will not be needed once the |
| 3200 | * VFS layer lookup-intents are implemented. |
| 3201 | * |
| 3202 | * Close is called when the inode is destroyed. |
| 3203 | * If we haven't opened the file for O_WRONLY, we |
| 3204 | * need to in the size_change case to obtain a stateid. |
| 3205 | * |
| 3206 | * Got race? |
| 3207 | * Because OPEN is always done by name in nfsv4, it is |
| 3208 | * possible that we opened a different file by the same |
| 3209 | * name. We can recognize this race condition, but we |
| 3210 | * can't do anything about it besides returning an error. |
| 3211 | * |
| 3212 | * This will be fixed with VFS changes (lookup-intent). |
| 3213 | */ |
| 3214 | static int |
| 3215 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3216 | struct iattr *sattr) |
| 3217 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3218 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3219 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3220 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3221 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | int status; |
| 3223 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3224 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3225 | sattr->ia_valid & ATTR_SIZE && |
| 3226 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3227 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3228 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3229 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3231 | /* Deal with open(O_TRUNC) */ |
| 3232 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3233 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3234 | |
| 3235 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3236 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3237 | return 0; |
| 3238 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3239 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3240 | if (sattr->ia_valid & ATTR_FILE) { |
| 3241 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3242 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3243 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3244 | if (ctx) { |
| 3245 | cred = ctx->cred; |
| 3246 | state = ctx->state; |
| 3247 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3248 | } |
| 3249 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3250 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3251 | if (IS_ERR(label)) |
| 3252 | return PTR_ERR(label); |
| 3253 | |
| 3254 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3255 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 3256 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3257 | nfs_setsecurity(inode, fattr, label); |
| 3258 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3259 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return status; |
| 3261 | } |
| 3262 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3263 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3264 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3265 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3266 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3267 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3268 | int status; |
| 3269 | struct nfs4_lookup_arg args = { |
| 3270 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3271 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3272 | .name = name, |
| 3273 | }; |
| 3274 | struct nfs4_lookup_res res = { |
| 3275 | .server = server, |
| 3276 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3277 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3278 | .fh = fhandle, |
| 3279 | }; |
| 3280 | struct rpc_message msg = { |
| 3281 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3282 | .rpc_argp = &args, |
| 3283 | .rpc_resp = &res, |
| 3284 | }; |
| 3285 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3286 | args.bitmask = nfs4_bitmask(server, label); |
| 3287 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3288 | nfs_fattr_init(fattr); |
| 3289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3291 | 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] | 3292 | dprintk("NFS reply lookup: %d\n", status); |
| 3293 | return status; |
| 3294 | } |
| 3295 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3296 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3297 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3298 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3299 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3300 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3301 | fattr->nlink = 2; |
| 3302 | } |
| 3303 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3304 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3305 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3306 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3307 | { |
| 3308 | struct nfs4_exception exception = { }; |
| 3309 | struct rpc_clnt *client = *clnt; |
| 3310 | int err; |
| 3311 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3312 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3313 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3314 | switch (err) { |
| 3315 | case -NFS4ERR_BADNAME: |
| 3316 | err = -ENOENT; |
| 3317 | goto out; |
| 3318 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3319 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3320 | goto out; |
| 3321 | case -NFS4ERR_WRONGSEC: |
| 3322 | err = -EPERM; |
| 3323 | if (client != *clnt) |
| 3324 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3325 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3326 | if (IS_ERR(client)) |
| 3327 | return PTR_ERR(client); |
| 3328 | |
| 3329 | exception.retry = 1; |
| 3330 | break; |
| 3331 | default: |
| 3332 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3333 | } |
| 3334 | } while (exception.retry); |
| 3335 | |
| 3336 | out: |
| 3337 | if (err == 0) |
| 3338 | *clnt = client; |
| 3339 | else if (client != *clnt) |
| 3340 | rpc_shutdown_client(client); |
| 3341 | |
| 3342 | return err; |
| 3343 | } |
| 3344 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3345 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3346 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3347 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3349 | int status; |
| 3350 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3351 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3352 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3353 | if (client != NFS_CLIENT(dir)) { |
| 3354 | rpc_shutdown_client(client); |
| 3355 | nfs_fixup_secinfo_attributes(fattr); |
| 3356 | } |
| 3357 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3360 | struct rpc_clnt * |
| 3361 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3362 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3363 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3364 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3365 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3366 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3367 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3368 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3369 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3370 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3371 | } |
| 3372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3374 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3375 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | struct nfs4_accessargs args = { |
| 3377 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3378 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3380 | struct nfs4_accessres res = { |
| 3381 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3382 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | struct rpc_message msg = { |
| 3384 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3385 | .rpc_argp = &args, |
| 3386 | .rpc_resp = &res, |
| 3387 | .rpc_cred = entry->cred, |
| 3388 | }; |
| 3389 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3390 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | |
| 3392 | /* |
| 3393 | * Determine which access bits we want to ask for... |
| 3394 | */ |
| 3395 | if (mode & MAY_READ) |
| 3396 | args.access |= NFS4_ACCESS_READ; |
| 3397 | if (S_ISDIR(inode->i_mode)) { |
| 3398 | if (mode & MAY_WRITE) |
| 3399 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3400 | if (mode & MAY_EXEC) |
| 3401 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3402 | } else { |
| 3403 | if (mode & MAY_WRITE) |
| 3404 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3405 | if (mode & MAY_EXEC) |
| 3406 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3407 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3408 | |
| 3409 | res.fattr = nfs_alloc_fattr(); |
| 3410 | if (res.fattr == NULL) |
| 3411 | return -ENOMEM; |
| 3412 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3413 | 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] | 3414 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3415 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3416 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3418 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | return status; |
| 3420 | } |
| 3421 | |
| 3422 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3423 | { |
| 3424 | struct nfs4_exception exception = { }; |
| 3425 | int err; |
| 3426 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3427 | err = _nfs4_proc_access(inode, entry); |
| 3428 | trace_nfs4_access(inode, err); |
| 3429 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | &exception); |
| 3431 | } while (exception.retry); |
| 3432 | return err; |
| 3433 | } |
| 3434 | |
| 3435 | /* |
| 3436 | * TODO: For the time being, we don't try to get any attributes |
| 3437 | * along with any of the zero-copy operations READ, READDIR, |
| 3438 | * READLINK, WRITE. |
| 3439 | * |
| 3440 | * In the case of the first three, we want to put the GETATTR |
| 3441 | * after the read-type operation -- this is because it is hard |
| 3442 | * to predict the length of a GETATTR response in v4, and thus |
| 3443 | * align the READ data correctly. This means that the GETATTR |
| 3444 | * may end up partially falling into the page cache, and we should |
| 3445 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3446 | * To do this efficiently, we need to know the total length |
| 3447 | * of data received, which doesn't seem to be available outside |
| 3448 | * of the RPC layer. |
| 3449 | * |
| 3450 | * In the case of WRITE, we also want to put the GETATTR after |
| 3451 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3452 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | * |
| 3454 | * Both of these changes to the XDR layer would in fact be quite |
| 3455 | * minor, but I decided to leave them for a subsequent patch. |
| 3456 | */ |
| 3457 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3458 | unsigned int pgbase, unsigned int pglen) |
| 3459 | { |
| 3460 | struct nfs4_readlink args = { |
| 3461 | .fh = NFS_FH(inode), |
| 3462 | .pgbase = pgbase, |
| 3463 | .pglen = pglen, |
| 3464 | .pages = &page, |
| 3465 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3466 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | struct rpc_message msg = { |
| 3468 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3469 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3470 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | }; |
| 3472 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3473 | 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] | 3474 | } |
| 3475 | |
| 3476 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3477 | unsigned int pgbase, unsigned int pglen) |
| 3478 | { |
| 3479 | struct nfs4_exception exception = { }; |
| 3480 | int err; |
| 3481 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3482 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3483 | trace_nfs4_readlink(inode, err); |
| 3484 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | &exception); |
| 3486 | } while (exception.retry); |
| 3487 | return err; |
| 3488 | } |
| 3489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3491 | * 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] | 3492 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | static int |
| 3494 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3495 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3497 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3498 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | struct nfs4_state *state; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3500 | int opened = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | int status = 0; |
| 3502 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3503 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3504 | if (IS_ERR(ctx)) |
| 3505 | return PTR_ERR(ctx); |
| 3506 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3507 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3508 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3509 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3510 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, &opened); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | if (IS_ERR(state)) { |
| 3512 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3513 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3516 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3517 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | return status; |
| 3519 | } |
| 3520 | |
| 3521 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3522 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3523 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3524 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3526 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3528 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3529 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3530 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3532 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3533 | .rpc_argp = &args, |
| 3534 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3536 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3537 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3538 | 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] | 3539 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3540 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | return status; |
| 3542 | } |
| 3543 | |
| 3544 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3545 | { |
| 3546 | struct nfs4_exception exception = { }; |
| 3547 | int err; |
| 3548 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3549 | err = _nfs4_proc_remove(dir, name); |
| 3550 | trace_nfs4_remove(dir, name, err); |
| 3551 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | &exception); |
| 3553 | } while (exception.retry); |
| 3554 | return err; |
| 3555 | } |
| 3556 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3557 | 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] | 3558 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3559 | struct nfs_server *server = NFS_SERVER(dir); |
| 3560 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3561 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3563 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3565 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3566 | |
| 3567 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3570 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3571 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3572 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3573 | &data->args.seq_args, |
| 3574 | &data->res.seq_res, |
| 3575 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3578 | 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] | 3579 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3580 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3581 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3582 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3583 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3584 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 3585 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3586 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3587 | return 0; |
| 3588 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3589 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3592 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3593 | { |
| 3594 | struct nfs_server *server = NFS_SERVER(dir); |
| 3595 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3596 | struct nfs_renameres *res = msg->rpc_resp; |
| 3597 | |
| 3598 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3599 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3600 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3601 | } |
| 3602 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3603 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3604 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3605 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3606 | &data->args.seq_args, |
| 3607 | &data->res.seq_res, |
| 3608 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3612 | struct inode *new_dir) |
| 3613 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3614 | struct nfs_renamedata *data = task->tk_calldata; |
| 3615 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3616 | |
| 3617 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3618 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 3619 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3620 | return 0; |
| 3621 | |
| 3622 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3623 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3624 | return 1; |
| 3625 | } |
| 3626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3628 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3629 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | struct nfs4_link_arg arg = { |
| 3631 | .fh = NFS_FH(inode), |
| 3632 | .dir_fh = NFS_FH(dir), |
| 3633 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3634 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3636 | struct nfs4_link_res res = { |
| 3637 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3638 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3639 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | struct rpc_message msg = { |
| 3641 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3642 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3643 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3645 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3647 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3648 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3649 | goto out; |
| 3650 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3651 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3652 | if (IS_ERR(res.label)) { |
| 3653 | status = PTR_ERR(res.label); |
| 3654 | goto out; |
| 3655 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3656 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3657 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3658 | 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] | 3659 | if (!status) { |
| 3660 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3661 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3662 | if (!status) |
| 3663 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3664 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3665 | |
| 3666 | |
| 3667 | nfs4_label_free(res.label); |
| 3668 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3669 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3670 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | return status; |
| 3672 | } |
| 3673 | |
| 3674 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3675 | { |
| 3676 | struct nfs4_exception exception = { }; |
| 3677 | int err; |
| 3678 | do { |
| 3679 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3680 | _nfs4_proc_link(inode, dir, name), |
| 3681 | &exception); |
| 3682 | } while (exception.retry); |
| 3683 | return err; |
| 3684 | } |
| 3685 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3686 | struct nfs4_createdata { |
| 3687 | struct rpc_message msg; |
| 3688 | struct nfs4_create_arg arg; |
| 3689 | struct nfs4_create_res res; |
| 3690 | struct nfs_fh fh; |
| 3691 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3692 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3693 | }; |
| 3694 | |
| 3695 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3696 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3697 | { |
| 3698 | struct nfs4_createdata *data; |
| 3699 | |
| 3700 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3701 | if (data != NULL) { |
| 3702 | struct nfs_server *server = NFS_SERVER(dir); |
| 3703 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3704 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3705 | if (IS_ERR(data->label)) |
| 3706 | goto out_free; |
| 3707 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3708 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3709 | data->msg.rpc_argp = &data->arg; |
| 3710 | data->msg.rpc_resp = &data->res; |
| 3711 | data->arg.dir_fh = NFS_FH(dir); |
| 3712 | data->arg.server = server; |
| 3713 | data->arg.name = name; |
| 3714 | data->arg.attrs = sattr; |
| 3715 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3716 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3717 | data->res.server = server; |
| 3718 | data->res.fh = &data->fh; |
| 3719 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3720 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3721 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3722 | } |
| 3723 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3724 | out_free: |
| 3725 | kfree(data); |
| 3726 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3730 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3731 | 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] | 3732 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3733 | if (status == 0) { |
| 3734 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3735 | 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] | 3736 | } |
| 3737 | return status; |
| 3738 | } |
| 3739 | |
| 3740 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3741 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3742 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3743 | kfree(data); |
| 3744 | } |
| 3745 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3746 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3747 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3748 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3750 | struct nfs4_createdata *data; |
| 3751 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3753 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3754 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3755 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3756 | status = -ENOMEM; |
| 3757 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3758 | if (data == NULL) |
| 3759 | goto out; |
| 3760 | |
| 3761 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3762 | data->arg.u.symlink.pages = &page; |
| 3763 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3764 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3766 | status = nfs4_do_create(dir, dentry, data); |
| 3767 | |
| 3768 | nfs4_free_createdata(data); |
| 3769 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | return status; |
| 3771 | } |
| 3772 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3773 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3774 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | { |
| 3776 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3777 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3779 | |
| 3780 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3783 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3784 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3785 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | &exception); |
| 3787 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3788 | |
| 3789 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | return err; |
| 3791 | } |
| 3792 | |
| 3793 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3794 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3796 | struct nfs4_createdata *data; |
| 3797 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3799 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3800 | if (data == NULL) |
| 3801 | goto out; |
| 3802 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3803 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3804 | status = nfs4_do_create(dir, dentry, data); |
| 3805 | |
| 3806 | nfs4_free_createdata(data); |
| 3807 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | return status; |
| 3809 | } |
| 3810 | |
| 3811 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3812 | struct iattr *sattr) |
| 3813 | { |
| 3814 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3815 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3817 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3818 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3819 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3820 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3822 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3823 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3824 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | &exception); |
| 3826 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3827 | nfs4_label_release_security(label); |
| 3828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | return err; |
| 3830 | } |
| 3831 | |
| 3832 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3833 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | { |
| 3835 | struct inode *dir = dentry->d_inode; |
| 3836 | struct nfs4_readdir_arg args = { |
| 3837 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3838 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | .pgbase = 0, |
| 3840 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3841 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3842 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | }; |
| 3844 | struct nfs4_readdir_res res; |
| 3845 | struct rpc_message msg = { |
| 3846 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3847 | .rpc_argp = &args, |
| 3848 | .rpc_resp = &res, |
| 3849 | .rpc_cred = cred, |
| 3850 | }; |
| 3851 | int status; |
| 3852 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 3853 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 3854 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3855 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3856 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3858 | 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] | 3859 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3860 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3861 | status += args.pgbase; |
| 3862 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3863 | |
| 3864 | nfs_invalidate_atime(dir); |
| 3865 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3866 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | return status; |
| 3868 | } |
| 3869 | |
| 3870 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3871 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | { |
| 3873 | struct nfs4_exception exception = { }; |
| 3874 | int err; |
| 3875 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3876 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3877 | pages, count, plus); |
| 3878 | trace_nfs4_readdir(dentry->d_inode, err); |
| 3879 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | &exception); |
| 3881 | } while (exception.retry); |
| 3882 | return err; |
| 3883 | } |
| 3884 | |
| 3885 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3886 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3888 | struct nfs4_createdata *data; |
| 3889 | int mode = sattr->ia_mode; |
| 3890 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3892 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3893 | if (data == NULL) |
| 3894 | goto out; |
| 3895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3897 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3899 | data->arg.ftype = NF4BLK; |
| 3900 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3901 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | } |
| 3903 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3904 | data->arg.ftype = NF4CHR; |
| 3905 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3906 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3907 | } else if (!S_ISSOCK(mode)) { |
| 3908 | status = -EINVAL; |
| 3909 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3911 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3912 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3913 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3914 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3915 | nfs4_free_createdata(data); |
| 3916 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | return status; |
| 3918 | } |
| 3919 | |
| 3920 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3921 | struct iattr *sattr, dev_t rdev) |
| 3922 | { |
| 3923 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3924 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3926 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3927 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3928 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3929 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3931 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3932 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3933 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | &exception); |
| 3935 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3936 | |
| 3937 | nfs4_label_release_security(label); |
| 3938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | return err; |
| 3940 | } |
| 3941 | |
| 3942 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3943 | struct nfs_fsstat *fsstat) |
| 3944 | { |
| 3945 | struct nfs4_statfs_arg args = { |
| 3946 | .fh = fhandle, |
| 3947 | .bitmask = server->attr_bitmask, |
| 3948 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3949 | struct nfs4_statfs_res res = { |
| 3950 | .fsstat = fsstat, |
| 3951 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | struct rpc_message msg = { |
| 3953 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3954 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3955 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | }; |
| 3957 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3958 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3959 | 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] | 3960 | } |
| 3961 | |
| 3962 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3963 | { |
| 3964 | struct nfs4_exception exception = { }; |
| 3965 | int err; |
| 3966 | do { |
| 3967 | err = nfs4_handle_exception(server, |
| 3968 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3969 | &exception); |
| 3970 | } while (exception.retry); |
| 3971 | return err; |
| 3972 | } |
| 3973 | |
| 3974 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3975 | struct nfs_fsinfo *fsinfo) |
| 3976 | { |
| 3977 | struct nfs4_fsinfo_arg args = { |
| 3978 | .fh = fhandle, |
| 3979 | .bitmask = server->attr_bitmask, |
| 3980 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3981 | struct nfs4_fsinfo_res res = { |
| 3982 | .fsinfo = fsinfo, |
| 3983 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | struct rpc_message msg = { |
| 3985 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3986 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3987 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | }; |
| 3989 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3990 | 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] | 3991 | } |
| 3992 | |
| 3993 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3994 | { |
| 3995 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3996 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | int err; |
| 3998 | |
| 3999 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4000 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4001 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4002 | if (err == 0) { |
| 4003 | struct nfs_client *clp = server->nfs_client; |
| 4004 | |
| 4005 | spin_lock(&clp->cl_lock); |
| 4006 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 4007 | clp->cl_last_renewal = now; |
| 4008 | spin_unlock(&clp->cl_lock); |
| 4009 | break; |
| 4010 | } |
| 4011 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | } while (exception.retry); |
| 4013 | return err; |
| 4014 | } |
| 4015 | |
| 4016 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4017 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4018 | int error; |
| 4019 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4020 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4021 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4022 | if (error == 0) { |
| 4023 | /* block layout checks this! */ |
| 4024 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4025 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4026 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4027 | |
| 4028 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4032 | struct nfs_pathconf *pathconf) |
| 4033 | { |
| 4034 | struct nfs4_pathconf_arg args = { |
| 4035 | .fh = fhandle, |
| 4036 | .bitmask = server->attr_bitmask, |
| 4037 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4038 | struct nfs4_pathconf_res res = { |
| 4039 | .pathconf = pathconf, |
| 4040 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | struct rpc_message msg = { |
| 4042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4043 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4044 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | }; |
| 4046 | |
| 4047 | /* None of the pathconf attributes are mandatory to implement */ |
| 4048 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4049 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4050 | return 0; |
| 4051 | } |
| 4052 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4053 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4054 | 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] | 4055 | } |
| 4056 | |
| 4057 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4058 | struct nfs_pathconf *pathconf) |
| 4059 | { |
| 4060 | struct nfs4_exception exception = { }; |
| 4061 | int err; |
| 4062 | |
| 4063 | do { |
| 4064 | err = nfs4_handle_exception(server, |
| 4065 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4066 | &exception); |
| 4067 | } while (exception.retry); |
| 4068 | return err; |
| 4069 | } |
| 4070 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4071 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4072 | const struct nfs_open_context *ctx, |
| 4073 | const struct nfs_lock_context *l_ctx, |
| 4074 | fmode_t fmode) |
| 4075 | { |
| 4076 | const struct nfs_lockowner *lockowner = NULL; |
| 4077 | |
| 4078 | if (l_ctx != NULL) |
| 4079 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4080 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4081 | } |
| 4082 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4083 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4084 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4085 | const struct nfs_open_context *ctx, |
| 4086 | const struct nfs_lock_context *l_ctx, |
| 4087 | fmode_t fmode) |
| 4088 | { |
| 4089 | nfs4_stateid current_stateid; |
| 4090 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4091 | /* If the current stateid represents a lost lock, then exit */ |
| 4092 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4093 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4094 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4095 | } |
| 4096 | |
| 4097 | static bool nfs4_error_stateid_expired(int err) |
| 4098 | { |
| 4099 | switch (err) { |
| 4100 | case -NFS4ERR_DELEG_REVOKED: |
| 4101 | case -NFS4ERR_ADMIN_REVOKED: |
| 4102 | case -NFS4ERR_BAD_STATEID: |
| 4103 | case -NFS4ERR_STALE_STATEID: |
| 4104 | case -NFS4ERR_OLD_STATEID: |
| 4105 | case -NFS4ERR_OPENMODE: |
| 4106 | case -NFS4ERR_EXPIRED: |
| 4107 | return true; |
| 4108 | } |
| 4109 | return false; |
| 4110 | } |
| 4111 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4112 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4113 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4114 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4115 | } |
| 4116 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4117 | 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] | 4118 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4119 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4121 | trace_nfs4_read(hdr, task->tk_status); |
| 4122 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 4123 | hdr->args.context->state, |
| 4124 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4125 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4126 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4128 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4129 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4131 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4132 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4135 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4136 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4137 | { |
| 4138 | |
| 4139 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4140 | nfs4_stateid_is_current(&args->stateid, |
| 4141 | args->context, |
| 4142 | args->lock_context, |
| 4143 | FMODE_READ)) |
| 4144 | return false; |
| 4145 | rpc_restart_call_prepare(task); |
| 4146 | return true; |
| 4147 | } |
| 4148 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4149 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4150 | { |
| 4151 | |
| 4152 | dprintk("--> %s\n", __func__); |
| 4153 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4154 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4155 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4156 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4157 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4158 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4159 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4162 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4163 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4165 | hdr->timestamp = jiffies; |
| 4166 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4167 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4168 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | } |
| 4170 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4171 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4172 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4173 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4174 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4175 | &hdr->args.seq_args, |
| 4176 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4177 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4178 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4179 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4180 | hdr->args.lock_context, |
| 4181 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4182 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4183 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4184 | return -EIO; |
| 4185 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4188 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4189 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4191 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 4192 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4193 | trace_nfs4_write(hdr, task->tk_status); |
| 4194 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 4195 | hdr->args.context->state, |
| 4196 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4197 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4198 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4200 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4201 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
| 4202 | nfs_post_op_update_inode_force_wcc(inode, &hdr->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4203 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4204 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | } |
| 4206 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4207 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4208 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4209 | { |
| 4210 | |
| 4211 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4212 | nfs4_stateid_is_current(&args->stateid, |
| 4213 | args->context, |
| 4214 | args->lock_context, |
| 4215 | FMODE_WRITE)) |
| 4216 | return false; |
| 4217 | rpc_restart_call_prepare(task); |
| 4218 | return true; |
| 4219 | } |
| 4220 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4221 | 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] | 4222 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4223 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4224 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4225 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4226 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4227 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4228 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4229 | } |
| 4230 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4231 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4232 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4233 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4234 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4235 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4236 | return false; |
| 4237 | /* Otherwise, request attributes if and only if we don't hold |
| 4238 | * a delegation |
| 4239 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4240 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4241 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4242 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4243 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4244 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4246 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4247 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4248 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4249 | hdr->args.bitmask = NULL; |
| 4250 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4251 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4252 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4253 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4254 | if (!hdr->pgio_done_cb) |
| 4255 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4256 | hdr->res.server = server; |
| 4257 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4259 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4260 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | } |
| 4262 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4263 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4264 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4265 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4266 | &data->args.seq_args, |
| 4267 | &data->res.seq_res, |
| 4268 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | } |
| 4270 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4271 | 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] | 4272 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4274 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4275 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 4276 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4277 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4278 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4279 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4281 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4284 | 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] | 4285 | { |
| 4286 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4287 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4288 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4291 | 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] | 4292 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4293 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4294 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4295 | if (data->commit_done_cb == NULL) |
| 4296 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4297 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4298 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4299 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4302 | struct nfs4_renewdata { |
| 4303 | struct nfs_client *client; |
| 4304 | unsigned long timestamp; |
| 4305 | }; |
| 4306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | /* |
| 4308 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4309 | * standalone procedure for queueing an asynchronous RENEW. |
| 4310 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4311 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4312 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4313 | struct nfs4_renewdata *data = calldata; |
| 4314 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4315 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4316 | if (atomic_read(&clp->cl_count) > 1) |
| 4317 | nfs4_schedule_state_renewal(clp); |
| 4318 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4319 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4320 | } |
| 4321 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4322 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4324 | struct nfs4_renewdata *data = calldata; |
| 4325 | struct nfs_client *clp = data->client; |
| 4326 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4328 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4329 | switch (task->tk_status) { |
| 4330 | case 0: |
| 4331 | break; |
| 4332 | case -NFS4ERR_LEASE_MOVED: |
| 4333 | nfs4_schedule_lease_moved_recovery(clp); |
| 4334 | break; |
| 4335 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4336 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4337 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4338 | return; |
| 4339 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4340 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4341 | return; |
| 4342 | } |
| 4343 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4345 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4348 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4349 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4350 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4351 | }; |
| 4352 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4353 | 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] | 4354 | { |
| 4355 | struct rpc_message msg = { |
| 4356 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4357 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4358 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4360 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4362 | if (renew_flags == 0) |
| 4363 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4364 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4365 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4366 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4367 | if (data == NULL) |
| 4368 | return -ENOMEM; |
| 4369 | data->client = clp; |
| 4370 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4371 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4372 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | } |
| 4374 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4375 | 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] | 4376 | { |
| 4377 | struct rpc_message msg = { |
| 4378 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4379 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4380 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | }; |
| 4382 | unsigned long now = jiffies; |
| 4383 | int status; |
| 4384 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4385 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | if (status < 0) |
| 4387 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4388 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | return 0; |
| 4390 | } |
| 4391 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4392 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4393 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4394 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4395 | } |
| 4396 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4397 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4398 | * 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] | 4399 | * the stack. |
| 4400 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4401 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4402 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4403 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4404 | struct page **pages, unsigned int *pgbase) |
| 4405 | { |
| 4406 | struct page *newpage, **spages; |
| 4407 | int rc = 0; |
| 4408 | size_t len; |
| 4409 | spages = pages; |
| 4410 | |
| 4411 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4412 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4413 | newpage = alloc_page(GFP_KERNEL); |
| 4414 | |
| 4415 | if (newpage == NULL) |
| 4416 | goto unwind; |
| 4417 | memcpy(page_address(newpage), buf, len); |
| 4418 | buf += len; |
| 4419 | buflen -= len; |
| 4420 | *pages++ = newpage; |
| 4421 | rc++; |
| 4422 | } while (buflen != 0); |
| 4423 | |
| 4424 | return rc; |
| 4425 | |
| 4426 | unwind: |
| 4427 | for(; rc > 0; rc--) |
| 4428 | __free_page(spages[rc-1]); |
| 4429 | return -ENOMEM; |
| 4430 | } |
| 4431 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4432 | struct nfs4_cached_acl { |
| 4433 | int cached; |
| 4434 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4435 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4436 | }; |
| 4437 | |
| 4438 | 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] | 4439 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4440 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4441 | |
| 4442 | spin_lock(&inode->i_lock); |
| 4443 | kfree(nfsi->nfs4_acl); |
| 4444 | nfsi->nfs4_acl = acl; |
| 4445 | spin_unlock(&inode->i_lock); |
| 4446 | } |
| 4447 | |
| 4448 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4449 | { |
| 4450 | nfs4_set_cached_acl(inode, NULL); |
| 4451 | } |
| 4452 | |
| 4453 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4454 | { |
| 4455 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4456 | struct nfs4_cached_acl *acl; |
| 4457 | int ret = -ENOENT; |
| 4458 | |
| 4459 | spin_lock(&inode->i_lock); |
| 4460 | acl = nfsi->nfs4_acl; |
| 4461 | if (acl == NULL) |
| 4462 | goto out; |
| 4463 | if (buf == NULL) /* user is just asking for length */ |
| 4464 | goto out_len; |
| 4465 | if (acl->cached == 0) |
| 4466 | goto out; |
| 4467 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4468 | if (acl->len > buflen) |
| 4469 | goto out; |
| 4470 | memcpy(buf, acl->data, acl->len); |
| 4471 | out_len: |
| 4472 | ret = acl->len; |
| 4473 | out: |
| 4474 | spin_unlock(&inode->i_lock); |
| 4475 | return ret; |
| 4476 | } |
| 4477 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4478 | 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] | 4479 | { |
| 4480 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4481 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4482 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4483 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4484 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4485 | if (acl == NULL) |
| 4486 | goto out; |
| 4487 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4488 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4489 | } else { |
| 4490 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4491 | if (acl == NULL) |
| 4492 | goto out; |
| 4493 | acl->cached = 0; |
| 4494 | } |
| 4495 | acl->len = acl_len; |
| 4496 | out: |
| 4497 | nfs4_set_cached_acl(inode, acl); |
| 4498 | } |
| 4499 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4500 | /* |
| 4501 | * The getxattr API returns the required buffer length when called with a |
| 4502 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4503 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4504 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4505 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4506 | * the cache. If not so, we throw away the page, and cache the required |
| 4507 | * length. The next getxattr call will then produce another round trip to |
| 4508 | * the server, this time with the input buf of the required size. |
| 4509 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4510 | 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] | 4511 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4512 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4513 | struct nfs_getaclargs args = { |
| 4514 | .fh = NFS_FH(inode), |
| 4515 | .acl_pages = pages, |
| 4516 | .acl_len = buflen, |
| 4517 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4518 | struct nfs_getaclres res = { |
| 4519 | .acl_len = buflen, |
| 4520 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4521 | struct rpc_message msg = { |
| 4522 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4523 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4524 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4525 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4526 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4527 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4528 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4529 | /* As long as we're doing a round trip to the server anyway, |
| 4530 | * let's be prepared for a page of acl data. */ |
| 4531 | if (npages == 0) |
| 4532 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4533 | if (npages > ARRAY_SIZE(pages)) |
| 4534 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4535 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4536 | for (i = 0; i < npages; i++) { |
| 4537 | pages[i] = alloc_page(GFP_KERNEL); |
| 4538 | if (!pages[i]) |
| 4539 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4540 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4541 | |
| 4542 | /* for decoding across pages */ |
| 4543 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4544 | if (!res.acl_scratch) |
| 4545 | goto out_free; |
| 4546 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4547 | args.acl_len = npages * PAGE_SIZE; |
| 4548 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4549 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4550 | 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] | 4551 | __func__, buf, buflen, npages, args.acl_len); |
| 4552 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4553 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4554 | if (ret) |
| 4555 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4556 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4557 | /* Handle the case where the passed-in buffer is too short */ |
| 4558 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4559 | /* Did the user only issue a request for the acl length? */ |
| 4560 | if (buf == NULL) |
| 4561 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4562 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4563 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4564 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4565 | 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] | 4566 | if (buf) { |
| 4567 | if (res.acl_len > buflen) { |
| 4568 | ret = -ERANGE; |
| 4569 | goto out_free; |
| 4570 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4571 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4572 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4573 | out_ok: |
| 4574 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4575 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4576 | for (i = 0; i < npages; i++) |
| 4577 | if (pages[i]) |
| 4578 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4579 | if (res.acl_scratch) |
| 4580 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4581 | return ret; |
| 4582 | } |
| 4583 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4584 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4585 | { |
| 4586 | struct nfs4_exception exception = { }; |
| 4587 | ssize_t ret; |
| 4588 | do { |
| 4589 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4590 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4591 | if (ret >= 0) |
| 4592 | break; |
| 4593 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4594 | } while (exception.retry); |
| 4595 | return ret; |
| 4596 | } |
| 4597 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4598 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4599 | { |
| 4600 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4601 | int ret; |
| 4602 | |
| 4603 | if (!nfs4_server_supports_acls(server)) |
| 4604 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4605 | ret = nfs_revalidate_inode(server, inode); |
| 4606 | if (ret < 0) |
| 4607 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4608 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4609 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4610 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4611 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4612 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4613 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4614 | return ret; |
| 4615 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4616 | } |
| 4617 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4618 | 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] | 4619 | { |
| 4620 | struct nfs_server *server = NFS_SERVER(inode); |
| 4621 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4622 | struct nfs_setaclargs arg = { |
| 4623 | .fh = NFS_FH(inode), |
| 4624 | .acl_pages = pages, |
| 4625 | .acl_len = buflen, |
| 4626 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4627 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4628 | struct rpc_message msg = { |
| 4629 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4630 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4631 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4632 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4633 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4634 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4635 | |
| 4636 | if (!nfs4_server_supports_acls(server)) |
| 4637 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4638 | if (npages > ARRAY_SIZE(pages)) |
| 4639 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4640 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4641 | if (i < 0) |
| 4642 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4643 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4644 | 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] | 4645 | |
| 4646 | /* |
| 4647 | * Free each page after tx, so the only ref left is |
| 4648 | * held by the network stack |
| 4649 | */ |
| 4650 | for (; i > 0; i--) |
| 4651 | put_page(pages[i-1]); |
| 4652 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4653 | /* |
| 4654 | * Acl update can result in inode attribute update. |
| 4655 | * so mark the attribute cache invalid. |
| 4656 | */ |
| 4657 | spin_lock(&inode->i_lock); |
| 4658 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4659 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4660 | nfs_access_zap_cache(inode); |
| 4661 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4662 | return ret; |
| 4663 | } |
| 4664 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4665 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4666 | { |
| 4667 | struct nfs4_exception exception = { }; |
| 4668 | int err; |
| 4669 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4670 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4671 | trace_nfs4_set_acl(inode, err); |
| 4672 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4673 | &exception); |
| 4674 | } while (exception.retry); |
| 4675 | return err; |
| 4676 | } |
| 4677 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4678 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4679 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4680 | size_t buflen) |
| 4681 | { |
| 4682 | struct nfs_server *server = NFS_SERVER(inode); |
| 4683 | struct nfs_fattr fattr; |
| 4684 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4685 | |
| 4686 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4687 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4688 | .fh = NFS_FH(inode), |
| 4689 | .bitmask = bitmask, |
| 4690 | }; |
| 4691 | struct nfs4_getattr_res res = { |
| 4692 | .fattr = &fattr, |
| 4693 | .label = &label, |
| 4694 | .server = server, |
| 4695 | }; |
| 4696 | struct rpc_message msg = { |
| 4697 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4698 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4699 | .rpc_resp = &res, |
| 4700 | }; |
| 4701 | int ret; |
| 4702 | |
| 4703 | nfs_fattr_init(&fattr); |
| 4704 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4705 | 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] | 4706 | if (ret) |
| 4707 | return ret; |
| 4708 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4709 | return -ENOENT; |
| 4710 | if (buflen < label.len) |
| 4711 | return -ERANGE; |
| 4712 | return 0; |
| 4713 | } |
| 4714 | |
| 4715 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4716 | size_t buflen) |
| 4717 | { |
| 4718 | struct nfs4_exception exception = { }; |
| 4719 | int err; |
| 4720 | |
| 4721 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4722 | return -EOPNOTSUPP; |
| 4723 | |
| 4724 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4725 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4726 | trace_nfs4_get_security_label(inode, err); |
| 4727 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4728 | &exception); |
| 4729 | } while (exception.retry); |
| 4730 | return err; |
| 4731 | } |
| 4732 | |
| 4733 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4734 | struct nfs4_label *ilabel, |
| 4735 | struct nfs_fattr *fattr, |
| 4736 | struct nfs4_label *olabel) |
| 4737 | { |
| 4738 | |
| 4739 | struct iattr sattr = {0}; |
| 4740 | struct nfs_server *server = NFS_SERVER(inode); |
| 4741 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4742 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4743 | .fh = NFS_FH(inode), |
| 4744 | .iap = &sattr, |
| 4745 | .server = server, |
| 4746 | .bitmask = bitmask, |
| 4747 | .label = ilabel, |
| 4748 | }; |
| 4749 | struct nfs_setattrres res = { |
| 4750 | .fattr = fattr, |
| 4751 | .label = olabel, |
| 4752 | .server = server, |
| 4753 | }; |
| 4754 | struct rpc_message msg = { |
| 4755 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4756 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4757 | .rpc_resp = &res, |
| 4758 | }; |
| 4759 | int status; |
| 4760 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4761 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4762 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4763 | 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] | 4764 | if (status) |
| 4765 | dprintk("%s failed: %d\n", __func__, status); |
| 4766 | |
| 4767 | return status; |
| 4768 | } |
| 4769 | |
| 4770 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4771 | struct nfs4_label *ilabel, |
| 4772 | struct nfs_fattr *fattr, |
| 4773 | struct nfs4_label *olabel) |
| 4774 | { |
| 4775 | struct nfs4_exception exception = { }; |
| 4776 | int err; |
| 4777 | |
| 4778 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4779 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4780 | fattr, olabel); |
| 4781 | trace_nfs4_set_security_label(inode, err); |
| 4782 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4783 | &exception); |
| 4784 | } while (exception.retry); |
| 4785 | return err; |
| 4786 | } |
| 4787 | |
| 4788 | static int |
| 4789 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4790 | { |
| 4791 | struct nfs4_label ilabel, *olabel = NULL; |
| 4792 | struct nfs_fattr fattr; |
| 4793 | struct rpc_cred *cred; |
| 4794 | struct inode *inode = dentry->d_inode; |
| 4795 | int status; |
| 4796 | |
| 4797 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4798 | return -EOPNOTSUPP; |
| 4799 | |
| 4800 | nfs_fattr_init(&fattr); |
| 4801 | |
| 4802 | ilabel.pi = 0; |
| 4803 | ilabel.lfs = 0; |
| 4804 | ilabel.label = (char *)buf; |
| 4805 | ilabel.len = buflen; |
| 4806 | |
| 4807 | cred = rpc_lookup_cred(); |
| 4808 | if (IS_ERR(cred)) |
| 4809 | return PTR_ERR(cred); |
| 4810 | |
| 4811 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4812 | if (IS_ERR(olabel)) { |
| 4813 | status = -PTR_ERR(olabel); |
| 4814 | goto out; |
| 4815 | } |
| 4816 | |
| 4817 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4818 | if (status == 0) |
| 4819 | nfs_setsecurity(inode, &fattr, olabel); |
| 4820 | |
| 4821 | nfs4_label_free(olabel); |
| 4822 | out: |
| 4823 | put_rpccred(cred); |
| 4824 | return status; |
| 4825 | } |
| 4826 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4827 | |
| 4828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | static int |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 4830 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, |
| 4831 | struct nfs4_state *state, long *timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4833 | struct nfs_client *clp = server->nfs_client; |
| 4834 | |
| 4835 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | return 0; |
| 4837 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4838 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4839 | case -NFS4ERR_ADMIN_REVOKED: |
| 4840 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4841 | if (state == NULL) |
| 4842 | break; |
| 4843 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4844 | case -NFS4ERR_OPENMODE: |
| 4845 | if (state == NULL) |
| 4846 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4847 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4848 | goto recovery_failed; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4849 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4850 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4851 | if (state != NULL) { |
| 4852 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4853 | goto recovery_failed; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4854 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4856 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4857 | nfs4_schedule_lease_recovery(clp); |
| 4858 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4859 | case -NFS4ERR_MOVED: |
| 4860 | if (nfs4_schedule_migration_recovery(server) < 0) |
| 4861 | goto recovery_failed; |
| 4862 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 4863 | case -NFS4ERR_LEASE_MOVED: |
| 4864 | nfs4_schedule_lease_moved_recovery(clp); |
| 4865 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4866 | #if defined(CONFIG_NFS_V4_1) |
| 4867 | case -NFS4ERR_BADSESSION: |
| 4868 | case -NFS4ERR_BADSLOT: |
| 4869 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4870 | case -NFS4ERR_DEADSESSION: |
| 4871 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4872 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4873 | case -NFS4ERR_SEQ_MISORDERED: |
| 4874 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4875 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4876 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4a82fd7 | 2013-11-15 16:36:16 -0500 | [diff] [blame] | 4877 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4878 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4880 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 4881 | rpc_delay(task, nfs4_update_delay(timeout)); |
| 4882 | goto restart_call; |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4883 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4885 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | case -NFS4ERR_OLD_STATEID: |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4887 | goto restart_call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | } |
| 4889 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4890 | return 0; |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4891 | recovery_failed: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4892 | task->tk_status = -EIO; |
| 4893 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4894 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4895 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4896 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4897 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4898 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 4899 | goto recovery_failed; |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4900 | restart_call: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4901 | task->tk_status = 0; |
| 4902 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4905 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4906 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4907 | { |
| 4908 | __be32 verf[2]; |
| 4909 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4910 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4911 | /* An impossible timestamp guarantees this value |
| 4912 | * will never match a generated boot time. */ |
| 4913 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4914 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4915 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4916 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4917 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4918 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4919 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4920 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4921 | } |
| 4922 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4923 | static unsigned int |
| 4924 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4925 | char *buf, size_t len) |
| 4926 | { |
| 4927 | unsigned int result; |
| 4928 | |
| 4929 | rcu_read_lock(); |
| 4930 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4931 | clp->cl_ipaddr, |
| 4932 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4933 | RPC_DISPLAY_ADDR), |
| 4934 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4935 | RPC_DISPLAY_PROTO)); |
| 4936 | rcu_read_unlock(); |
| 4937 | return result; |
| 4938 | } |
| 4939 | |
| 4940 | static unsigned int |
| 4941 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 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; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4945 | |
| 4946 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4947 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4948 | clp->rpc_ops->version, |
| 4949 | clp->cl_minorversion, |
| 4950 | nfs4_client_id_uniquifier, |
| 4951 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4952 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4953 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4954 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4955 | } |
| 4956 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 4957 | /* |
| 4958 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 4959 | * services. Advertise one based on the address family of the |
| 4960 | * clientaddr. |
| 4961 | */ |
| 4962 | static unsigned int |
| 4963 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 4964 | { |
| 4965 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 4966 | return scnprintf(buf, len, "tcp6"); |
| 4967 | else |
| 4968 | return scnprintf(buf, len, "tcp"); |
| 4969 | } |
| 4970 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 4971 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 4972 | { |
| 4973 | struct nfs4_setclientid *sc = calldata; |
| 4974 | |
| 4975 | if (task->tk_status == 0) |
| 4976 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 4977 | } |
| 4978 | |
| 4979 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 4980 | .rpc_call_done = nfs4_setclientid_done, |
| 4981 | }; |
| 4982 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4983 | /** |
| 4984 | * nfs4_proc_setclientid - Negotiate client ID |
| 4985 | * @clp: state data structure |
| 4986 | * @program: RPC program for NFSv4 callback service |
| 4987 | * @port: IP port number for NFS4 callback service |
| 4988 | * @cred: RPC credential to use for this call |
| 4989 | * @res: where to place the result |
| 4990 | * |
| 4991 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4992 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4993 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4994 | unsigned short port, struct rpc_cred *cred, |
| 4995 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | { |
| 4997 | nfs4_verifier sc_verifier; |
| 4998 | struct nfs4_setclientid setclientid = { |
| 4999 | .sc_verifier = &sc_verifier, |
| 5000 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 5001 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | }; |
| 5003 | struct rpc_message msg = { |
| 5004 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5005 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5006 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5007 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5009 | struct rpc_task *task; |
| 5010 | struct rpc_task_setup task_setup_data = { |
| 5011 | .rpc_client = clp->cl_rpcclient, |
| 5012 | .rpc_message = &msg, |
| 5013 | .callback_ops = &nfs4_setclientid_ops, |
| 5014 | .callback_data = &setclientid, |
| 5015 | .flags = RPC_TASK_TIMEOUT, |
| 5016 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5017 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5018 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5019 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5020 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5021 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5022 | setclientid.sc_name_len = |
| 5023 | nfs4_init_uniform_client_string(clp, |
| 5024 | setclientid.sc_name, |
| 5025 | sizeof(setclientid.sc_name)); |
| 5026 | else |
| 5027 | setclientid.sc_name_len = |
| 5028 | nfs4_init_nonuniform_client_string(clp, |
| 5029 | setclientid.sc_name, |
| 5030 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5031 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5032 | setclientid.sc_netid_len = |
| 5033 | nfs4_init_callback_netid(clp, |
| 5034 | setclientid.sc_netid, |
| 5035 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5036 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5037 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5039 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5040 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 5041 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5042 | setclientid.sc_name_len, setclientid.sc_name); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5043 | task = rpc_run_task(&task_setup_data); |
| 5044 | if (IS_ERR(task)) { |
| 5045 | status = PTR_ERR(task); |
| 5046 | goto out; |
| 5047 | } |
| 5048 | status = task->tk_status; |
| 5049 | if (setclientid.sc_cred) { |
| 5050 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5051 | put_rpccred(setclientid.sc_cred); |
| 5052 | } |
| 5053 | rpc_put_task(task); |
| 5054 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5055 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5056 | dprintk("NFS reply setclientid: %d\n", status); |
| 5057 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | } |
| 5059 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5060 | /** |
| 5061 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5062 | * @clp: state data structure |
| 5063 | * @res: result of a previous SETCLIENTID |
| 5064 | * @cred: RPC credential to use for this call |
| 5065 | * |
| 5066 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5067 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5068 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5069 | struct nfs4_setclientid_res *arg, |
| 5070 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | struct rpc_message msg = { |
| 5073 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5074 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5075 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5076 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | int status; |
| 5078 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5079 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5080 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5081 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5082 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5083 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5084 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | return status; |
| 5086 | } |
| 5087 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5088 | struct nfs4_delegreturndata { |
| 5089 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5090 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5091 | struct nfs_fh fh; |
| 5092 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5093 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5094 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5095 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5096 | struct inode *inode; |
| 5097 | bool roc; |
| 5098 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5099 | }; |
| 5100 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5101 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5102 | { |
| 5103 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5104 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5105 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5106 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5107 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5108 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5109 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5110 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5111 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5112 | case -NFS4ERR_ADMIN_REVOKED: |
| 5113 | case -NFS4ERR_DELEG_REVOKED: |
| 5114 | case -NFS4ERR_BAD_STATEID: |
| 5115 | case -NFS4ERR_OLD_STATEID: |
| 5116 | case -NFS4ERR_STALE_STATEID: |
| 5117 | case -NFS4ERR_EXPIRED: |
| 5118 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5119 | if (data->roc) |
| 5120 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5121 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5122 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 5123 | if (nfs4_async_handle_error(task, data->res.server, |
| 5124 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5125 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5126 | return; |
| 5127 | } |
| 5128 | } |
| 5129 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | static void nfs4_delegreturn_release(void *calldata) |
| 5133 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5134 | struct nfs4_delegreturndata *data = calldata; |
| 5135 | |
| 5136 | if (data->roc) |
| 5137 | pnfs_roc_release(data->inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5138 | kfree(calldata); |
| 5139 | } |
| 5140 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5141 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5142 | { |
| 5143 | struct nfs4_delegreturndata *d_data; |
| 5144 | |
| 5145 | d_data = (struct nfs4_delegreturndata *)data; |
| 5146 | |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5147 | if (d_data->roc && |
| 5148 | pnfs_roc_drain(d_data->inode, &d_data->roc_barrier, task)) |
| 5149 | return; |
| 5150 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5151 | nfs4_setup_sequence(d_data->res.server, |
| 5152 | &d_data->args.seq_args, |
| 5153 | &d_data->res.seq_res, |
| 5154 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5155 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5156 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5157 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5158 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5159 | .rpc_call_done = nfs4_delegreturn_done, |
| 5160 | .rpc_release = nfs4_delegreturn_release, |
| 5161 | }; |
| 5162 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5163 | 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] | 5164 | { |
| 5165 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5166 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5167 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5168 | struct rpc_message msg = { |
| 5169 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5170 | .rpc_cred = cred, |
| 5171 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5172 | struct rpc_task_setup task_setup_data = { |
| 5173 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5174 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5175 | .callback_ops = &nfs4_delegreturn_ops, |
| 5176 | .flags = RPC_TASK_ASYNC, |
| 5177 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5178 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5179 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5180 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5181 | if (data == NULL) |
| 5182 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5183 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5184 | data->args.fhandle = &data->fh; |
| 5185 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5186 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5187 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5188 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5189 | data->res.fattr = &data->fattr; |
| 5190 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5191 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5192 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5193 | data->rpc_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5194 | data->inode = inode; |
| 5195 | data->roc = list_empty(&NFS_I(inode)->open_files) ? |
| 5196 | pnfs_roc(inode) : false; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5197 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5198 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5199 | msg.rpc_argp = &data->args; |
| 5200 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5201 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5202 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5203 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5204 | if (!issync) |
| 5205 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5206 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5207 | if (status != 0) |
| 5208 | goto out; |
| 5209 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5210 | if (status == 0) |
| 5211 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5212 | else |
| 5213 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5214 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5215 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5216 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | } |
| 5218 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5219 | 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] | 5220 | { |
| 5221 | struct nfs_server *server = NFS_SERVER(inode); |
| 5222 | struct nfs4_exception exception = { }; |
| 5223 | int err; |
| 5224 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5225 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5226 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5227 | switch (err) { |
| 5228 | case -NFS4ERR_STALE_STATEID: |
| 5229 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | case 0: |
| 5231 | return 0; |
| 5232 | } |
| 5233 | err = nfs4_handle_exception(server, err, &exception); |
| 5234 | } while (exception.retry); |
| 5235 | return err; |
| 5236 | } |
| 5237 | |
| 5238 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5239 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5240 | |
| 5241 | /* |
| 5242 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5243 | */ |
| 5244 | static unsigned long |
| 5245 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5246 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5247 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | timeout <<= 1; |
| 5249 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5250 | return NFS4_LOCK_MAXTIMEOUT; |
| 5251 | return timeout; |
| 5252 | } |
| 5253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5255 | { |
| 5256 | struct inode *inode = state->inode; |
| 5257 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5258 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5259 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5260 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5261 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5263 | struct nfs_lockt_res res = { |
| 5264 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5265 | }; |
| 5266 | struct rpc_message msg = { |
| 5267 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5268 | .rpc_argp = &arg, |
| 5269 | .rpc_resp = &res, |
| 5270 | .rpc_cred = state->owner->so_cred, |
| 5271 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | struct nfs4_lock_state *lsp; |
| 5273 | int status; |
| 5274 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5275 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5276 | status = nfs4_set_lock_state(state, request); |
| 5277 | if (status != 0) |
| 5278 | goto out; |
| 5279 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5280 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5281 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5282 | 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] | 5283 | switch (status) { |
| 5284 | case 0: |
| 5285 | request->fl_type = F_UNLCK; |
| 5286 | break; |
| 5287 | case -NFS4ERR_DENIED: |
| 5288 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5290 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5291 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5292 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | return status; |
| 5294 | } |
| 5295 | |
| 5296 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5297 | { |
| 5298 | struct nfs4_exception exception = { }; |
| 5299 | int err; |
| 5300 | |
| 5301 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5302 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5303 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5304 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | &exception); |
| 5306 | } while (exception.retry); |
| 5307 | return err; |
| 5308 | } |
| 5309 | |
| 5310 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5311 | { |
| 5312 | int res = 0; |
| 5313 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5314 | case FL_POSIX: |
| 5315 | res = posix_lock_file_wait(file, fl); |
| 5316 | break; |
| 5317 | case FL_FLOCK: |
| 5318 | res = flock_lock_file_wait(file, fl); |
| 5319 | break; |
| 5320 | default: |
| 5321 | BUG(); |
| 5322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5323 | return res; |
| 5324 | } |
| 5325 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5326 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5327 | struct nfs_locku_args arg; |
| 5328 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5329 | struct nfs4_lock_state *lsp; |
| 5330 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5331 | struct file_lock fl; |
| 5332 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5333 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5334 | }; |
| 5335 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5336 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5337 | struct nfs_open_context *ctx, |
| 5338 | struct nfs4_lock_state *lsp, |
| 5339 | struct nfs_seqid *seqid) |
| 5340 | { |
| 5341 | struct nfs4_unlockdata *p; |
| 5342 | struct inode *inode = lsp->ls_state->inode; |
| 5343 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5344 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5345 | if (p == NULL) |
| 5346 | return NULL; |
| 5347 | p->arg.fh = NFS_FH(inode); |
| 5348 | p->arg.fl = &p->fl; |
| 5349 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5350 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5351 | p->arg.stateid = &lsp->ls_stateid; |
| 5352 | p->lsp = lsp; |
| 5353 | atomic_inc(&lsp->ls_count); |
| 5354 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5355 | p->ctx = get_nfs_open_context(ctx); |
| 5356 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5357 | p->server = NFS_SERVER(inode); |
| 5358 | return p; |
| 5359 | } |
| 5360 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5361 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5362 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5363 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5364 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5365 | nfs4_put_lock_state(calldata->lsp); |
| 5366 | put_nfs_open_context(calldata->ctx); |
| 5367 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5368 | } |
| 5369 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5370 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5371 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5372 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5373 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5374 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5375 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5376 | switch (task->tk_status) { |
| 5377 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5378 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5379 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5380 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5381 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5382 | case -NFS4ERR_BAD_STATEID: |
| 5383 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5384 | case -NFS4ERR_STALE_STATEID: |
| 5385 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5386 | break; |
| 5387 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 5388 | if (nfs4_async_handle_error(task, calldata->server, |
| 5389 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5390 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5391 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5392 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5395 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5396 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5397 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5399 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5400 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5401 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5402 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5403 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5404 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5405 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5406 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5407 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5408 | &calldata->res.seq_res, |
| 5409 | task) != 0) |
| 5410 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5411 | return; |
| 5412 | out_no_action: |
| 5413 | task->tk_action = NULL; |
| 5414 | out_wait: |
| 5415 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | } |
| 5417 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5418 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5419 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5420 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5421 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5422 | }; |
| 5423 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5424 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5425 | struct nfs_open_context *ctx, |
| 5426 | struct nfs4_lock_state *lsp, |
| 5427 | struct nfs_seqid *seqid) |
| 5428 | { |
| 5429 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5430 | struct rpc_message msg = { |
| 5431 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5432 | .rpc_cred = ctx->cred, |
| 5433 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5434 | struct rpc_task_setup task_setup_data = { |
| 5435 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5436 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5437 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5438 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5439 | .flags = RPC_TASK_ASYNC, |
| 5440 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5441 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5442 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5443 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5444 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5445 | /* Ensure this is an unlock - when canceling a lock, the |
| 5446 | * canceled lock is passed in, and it won't be an unlock. |
| 5447 | */ |
| 5448 | fl->fl_type = F_UNLCK; |
| 5449 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5450 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5451 | if (data == NULL) { |
| 5452 | nfs_free_seqid(seqid); |
| 5453 | return ERR_PTR(-ENOMEM); |
| 5454 | } |
| 5455 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5456 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5457 | msg.rpc_argp = &data->arg; |
| 5458 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5459 | task_setup_data.callback_data = data; |
| 5460 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5461 | } |
| 5462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5463 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5464 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5465 | struct inode *inode = state->inode; |
| 5466 | struct nfs4_state_owner *sp = state->owner; |
| 5467 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5468 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5469 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5470 | struct rpc_task *task; |
| 5471 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5472 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5474 | status = nfs4_set_lock_state(state, request); |
| 5475 | /* Unlock _before_ we do the RPC call */ |
| 5476 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5477 | /* Exclude nfs_delegation_claim_locks() */ |
| 5478 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5479 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5480 | down_read(&nfsi->rwsem); |
| 5481 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5482 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5483 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5484 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5485 | } |
| 5486 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5487 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5488 | if (status != 0) |
| 5489 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5490 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5491 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5492 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5493 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5494 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5495 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5496 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5497 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5498 | 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] | 5499 | status = PTR_ERR(task); |
| 5500 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5501 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5502 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5503 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5504 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5505 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5506 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5507 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | } |
| 5509 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5510 | struct nfs4_lockdata { |
| 5511 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5512 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5513 | struct nfs4_lock_state *lsp; |
| 5514 | struct nfs_open_context *ctx; |
| 5515 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5516 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5517 | int rpc_status; |
| 5518 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5519 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5520 | }; |
| 5521 | |
| 5522 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5523 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5524 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5525 | { |
| 5526 | struct nfs4_lockdata *p; |
| 5527 | struct inode *inode = lsp->ls_state->inode; |
| 5528 | struct nfs_server *server = NFS_SERVER(inode); |
| 5529 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5530 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5531 | if (p == NULL) |
| 5532 | return NULL; |
| 5533 | |
| 5534 | p->arg.fh = NFS_FH(inode); |
| 5535 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5536 | 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] | 5537 | if (p->arg.open_seqid == NULL) |
| 5538 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5539 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5540 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5541 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5542 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5543 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5544 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5545 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5546 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5547 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5548 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5549 | atomic_inc(&lsp->ls_count); |
| 5550 | p->ctx = get_nfs_open_context(ctx); |
| 5551 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5552 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5553 | out_free_seqid: |
| 5554 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5555 | out_free: |
| 5556 | kfree(p); |
| 5557 | return NULL; |
| 5558 | } |
| 5559 | |
| 5560 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5561 | { |
| 5562 | struct nfs4_lockdata *data = calldata; |
| 5563 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5565 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5566 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5567 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5568 | /* Do we need to do an open_to_lock_owner? */ |
| 5569 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5570 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5571 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5572 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5573 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5574 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5575 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5576 | } else |
| 5577 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5578 | if (!nfs4_valid_open_stateid(state)) { |
| 5579 | data->rpc_status = -EBADF; |
| 5580 | task->tk_action = NULL; |
| 5581 | goto out_release_open_seqid; |
| 5582 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5583 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5584 | if (nfs4_setup_sequence(data->server, |
| 5585 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5586 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5587 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5588 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5589 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5590 | nfs_release_seqid(data->arg.open_seqid); |
| 5591 | out_release_lock_seqid: |
| 5592 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5593 | out_wait: |
| 5594 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5595 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5596 | } |
| 5597 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5598 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5599 | { |
| 5600 | struct nfs4_lockdata *data = calldata; |
| 5601 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5602 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5603 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5604 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5605 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5606 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5607 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5608 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5609 | if (data->rpc_status == 0) |
| 5610 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5611 | else |
| 5612 | goto out; |
| 5613 | } |
| 5614 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5615 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5616 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5617 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5618 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5619 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5620 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | static void nfs4_lock_release(void *calldata) |
| 5624 | { |
| 5625 | struct nfs4_lockdata *data = calldata; |
| 5626 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5627 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5628 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5629 | if (data->cancelled != 0) { |
| 5630 | struct rpc_task *task; |
| 5631 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5632 | data->arg.lock_seqid); |
| 5633 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5634 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5635 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5636 | } else |
| 5637 | nfs_free_seqid(data->arg.lock_seqid); |
| 5638 | nfs4_put_lock_state(data->lsp); |
| 5639 | put_nfs_open_context(data->ctx); |
| 5640 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5641 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5645 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5646 | .rpc_call_done = nfs4_lock_done, |
| 5647 | .rpc_release = nfs4_lock_release, |
| 5648 | }; |
| 5649 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5650 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5651 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5652 | switch (error) { |
| 5653 | case -NFS4ERR_ADMIN_REVOKED: |
| 5654 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5655 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5656 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5657 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5658 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5659 | break; |
| 5660 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5661 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5662 | case -NFS4ERR_EXPIRED: |
| 5663 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5664 | }; |
| 5665 | } |
| 5666 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5667 | 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] | 5668 | { |
| 5669 | struct nfs4_lockdata *data; |
| 5670 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5671 | struct rpc_message msg = { |
| 5672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5673 | .rpc_cred = state->owner->so_cred, |
| 5674 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5675 | struct rpc_task_setup task_setup_data = { |
| 5676 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5677 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5678 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5679 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5680 | .flags = RPC_TASK_ASYNC, |
| 5681 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5682 | int ret; |
| 5683 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5684 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5685 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5686 | fl->fl_u.nfs4_fl.owner, |
| 5687 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5688 | if (data == NULL) |
| 5689 | return -ENOMEM; |
| 5690 | if (IS_SETLKW(cmd)) |
| 5691 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5692 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5693 | msg.rpc_argp = &data->arg; |
| 5694 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5695 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5696 | if (recovery_type > NFS_LOCK_NEW) { |
| 5697 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5698 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5699 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5700 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5701 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5702 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5703 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5704 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5705 | if (ret == 0) { |
| 5706 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5707 | if (ret) |
| 5708 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5709 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5710 | } else |
| 5711 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5712 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5713 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5714 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5718 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5719 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5720 | struct nfs4_exception exception = { |
| 5721 | .inode = state->inode, |
| 5722 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5723 | int err; |
| 5724 | |
| 5725 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5726 | /* Cache the lock if possible... */ |
| 5727 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5728 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5729 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5730 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5731 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5732 | break; |
| 5733 | nfs4_handle_exception(server, err, &exception); |
| 5734 | } while (exception.retry); |
| 5735 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5739 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5740 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5741 | struct nfs4_exception exception = { |
| 5742 | .inode = state->inode, |
| 5743 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5744 | int err; |
| 5745 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5746 | err = nfs4_set_lock_state(state, request); |
| 5747 | if (err != 0) |
| 5748 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 5749 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5750 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 5751 | return 0; |
| 5752 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5753 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5754 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5755 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5756 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5757 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5758 | switch (err) { |
| 5759 | default: |
| 5760 | goto out; |
| 5761 | case -NFS4ERR_GRACE: |
| 5762 | case -NFS4ERR_DELAY: |
| 5763 | nfs4_handle_exception(server, err, &exception); |
| 5764 | err = 0; |
| 5765 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5766 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5767 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5768 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5771 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5772 | /** |
| 5773 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5774 | * |
| 5775 | * @state: NFSv4 state for an inode |
| 5776 | * |
| 5777 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5778 | * Otherwise a negative NFS4ERR value is returned. |
| 5779 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5780 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5781 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5782 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5783 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5784 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5785 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5786 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5787 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5788 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5789 | |
| 5790 | status = nfs41_test_stateid(server, |
| 5791 | &lsp->ls_stateid, |
| 5792 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5793 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5794 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5795 | /* Free the stateid unless the server |
| 5796 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5797 | if (status != -NFS4ERR_BAD_STATEID) |
| 5798 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5799 | &lsp->ls_stateid, |
| 5800 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5801 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5802 | ret = status; |
| 5803 | } |
| 5804 | } |
| 5805 | }; |
| 5806 | |
| 5807 | return ret; |
| 5808 | } |
| 5809 | |
| 5810 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5811 | { |
| 5812 | int status = NFS_OK; |
| 5813 | |
| 5814 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5815 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5816 | if (status != NFS_OK) |
| 5817 | status = nfs4_lock_expired(state, request); |
| 5818 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5819 | } |
| 5820 | #endif |
| 5821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5823 | { |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5824 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5825 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5826 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5827 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5828 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5830 | if ((fl_flags & FL_POSIX) && |
| 5831 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5832 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5833 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5834 | status = nfs4_set_lock_state(state, request); |
| 5835 | if (status != 0) |
| 5836 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5837 | request->fl_flags |= FL_ACCESS; |
| 5838 | status = do_vfs_lock(request->fl_file, request); |
| 5839 | if (status < 0) |
| 5840 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5841 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5842 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5843 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5844 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5845 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5846 | status = do_vfs_lock(request->fl_file, request); |
| 5847 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5848 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5849 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5850 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5851 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5852 | if (status != 0) |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5853 | goto out; |
| 5854 | down_read(&nfsi->rwsem); |
| 5855 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5856 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5857 | goto out_unlock; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5858 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5859 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5860 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5861 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5862 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5863 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5864 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5865 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5866 | out: |
| 5867 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | return status; |
| 5869 | } |
| 5870 | |
| 5871 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5872 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5873 | struct nfs4_exception exception = { |
| 5874 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5875 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5876 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | int err; |
| 5878 | |
| 5879 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5880 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5881 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5882 | if (err == -NFS4ERR_DENIED) |
| 5883 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5884 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5885 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5886 | } while (exception.retry); |
| 5887 | return err; |
| 5888 | } |
| 5889 | |
| 5890 | static int |
| 5891 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5892 | { |
| 5893 | struct nfs_open_context *ctx; |
| 5894 | struct nfs4_state *state; |
| 5895 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5896 | int status; |
| 5897 | |
| 5898 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5899 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5900 | state = ctx->state; |
| 5901 | |
| 5902 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5903 | return -EINVAL; |
| 5904 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5905 | if (IS_GETLK(cmd)) { |
| 5906 | if (state != NULL) |
| 5907 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5908 | return 0; |
| 5909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5910 | |
| 5911 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5912 | return -EINVAL; |
| 5913 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5914 | if (request->fl_type == F_UNLCK) { |
| 5915 | if (state != NULL) |
| 5916 | return nfs4_proc_unlck(state, cmd, request); |
| 5917 | return 0; |
| 5918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5919 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5920 | if (state == NULL) |
| 5921 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5922 | /* |
| 5923 | * Don't rely on the VFS having checked the file open mode, |
| 5924 | * since it won't do this for flock() locks. |
| 5925 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5926 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5927 | case F_RDLCK: |
| 5928 | if (!(filp->f_mode & FMODE_READ)) |
| 5929 | return -EBADF; |
| 5930 | break; |
| 5931 | case F_WRLCK: |
| 5932 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5933 | return -EBADF; |
| 5934 | } |
| 5935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | do { |
| 5937 | status = nfs4_proc_setlk(state, cmd, request); |
| 5938 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5939 | break; |
| 5940 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5941 | status = -ERESTARTSYS; |
| 5942 | if (signalled()) |
| 5943 | break; |
| 5944 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5945 | return status; |
| 5946 | } |
| 5947 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5948 | 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] | 5949 | { |
| 5950 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5951 | int err; |
| 5952 | |
| 5953 | err = nfs4_set_lock_state(state, fl); |
| 5954 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5955 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5956 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5957 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5958 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5959 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5960 | struct nfs_release_lockowner_data { |
| 5961 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5962 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5963 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 5964 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5965 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5966 | }; |
| 5967 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5968 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 5969 | { |
| 5970 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 5971 | struct nfs_server *server = data->server; |
| 5972 | nfs40_setup_sequence(server, &data->args.seq_args, |
| 5973 | &data->res.seq_res, task); |
| 5974 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5975 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 5979 | { |
| 5980 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5981 | struct nfs_server *server = data->server; |
| 5982 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 5983 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5984 | |
| 5985 | switch (task->tk_status) { |
| 5986 | case 0: |
| 5987 | renew_lease(server, data->timestamp); |
| 5988 | break; |
| 5989 | case -NFS4ERR_STALE_CLIENTID: |
| 5990 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 5991 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5992 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5993 | case -NFS4ERR_LEASE_MOVED: |
| 5994 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 5995 | if (nfs4_async_handle_error(task, server, |
| 5996 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5997 | rpc_restart_call_prepare(task); |
| 5998 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5999 | } |
| 6000 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6001 | static void nfs4_release_lockowner_release(void *calldata) |
| 6002 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6003 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6004 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6005 | kfree(calldata); |
| 6006 | } |
| 6007 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6008 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6009 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6010 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6011 | .rpc_release = nfs4_release_lockowner_release, |
| 6012 | }; |
| 6013 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6014 | static void |
| 6015 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6016 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6017 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6018 | struct rpc_message msg = { |
| 6019 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6020 | }; |
| 6021 | |
| 6022 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6023 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6024 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6025 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6026 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6027 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6028 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6029 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6030 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6031 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6032 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6033 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6034 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6035 | msg.rpc_resp = &data->res; |
| 6036 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6037 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6038 | } |
| 6039 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6040 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6041 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6042 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 6043 | const void *buf, size_t buflen, |
| 6044 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6045 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6046 | if (strcmp(key, "") != 0) |
| 6047 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6048 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6049 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6050 | } |
| 6051 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6052 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 6053 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6054 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6055 | if (strcmp(key, "") != 0) |
| 6056 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6057 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6058 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6059 | } |
| 6060 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6061 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 6062 | size_t list_len, const char *name, |
| 6063 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 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 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6066 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 6067 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 6068 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6069 | |
| 6070 | if (list && len <= list_len) |
| 6071 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6072 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6073 | } |
| 6074 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6075 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 6076 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 6077 | { |
| 6078 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 6079 | } |
| 6080 | |
| 6081 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 6082 | const void *buf, size_t buflen, |
| 6083 | int flags, int type) |
| 6084 | { |
| 6085 | if (security_ismaclabel(key)) |
| 6086 | return nfs4_set_security_label(dentry, buf, buflen); |
| 6087 | |
| 6088 | return -EOPNOTSUPP; |
| 6089 | } |
| 6090 | |
| 6091 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 6092 | void *buf, size_t buflen, int type) |
| 6093 | { |
| 6094 | if (security_ismaclabel(key)) |
| 6095 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 6096 | return -EOPNOTSUPP; |
| 6097 | } |
| 6098 | |
| 6099 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 6100 | size_t list_len, const char *name, |
| 6101 | size_t name_len, int type) |
| 6102 | { |
| 6103 | size_t len = 0; |
| 6104 | |
| 6105 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 6106 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 6107 | if (list && len <= list_len) |
| 6108 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 6109 | } |
| 6110 | return len; |
| 6111 | } |
| 6112 | |
| 6113 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6114 | .prefix = XATTR_SECURITY_PREFIX, |
| 6115 | .list = nfs4_xattr_list_nfs4_label, |
| 6116 | .get = nfs4_xattr_get_nfs4_label, |
| 6117 | .set = nfs4_xattr_set_nfs4_label, |
| 6118 | }; |
| 6119 | #endif |
| 6120 | |
| 6121 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6122 | /* |
| 6123 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6124 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6125 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6126 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6127 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6128 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6129 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6130 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6131 | return; |
| 6132 | |
| 6133 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6134 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6135 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6136 | fattr->nlink = 2; |
| 6137 | } |
| 6138 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6139 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6140 | const struct qstr *name, |
| 6141 | struct nfs4_fs_locations *fs_locations, |
| 6142 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6143 | { |
| 6144 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6145 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6146 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6147 | }; |
| 6148 | struct nfs4_fs_locations_arg args = { |
| 6149 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6150 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6151 | .page = page, |
| 6152 | .bitmask = bitmask, |
| 6153 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6154 | struct nfs4_fs_locations_res res = { |
| 6155 | .fs_locations = fs_locations, |
| 6156 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6157 | struct rpc_message msg = { |
| 6158 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6159 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6160 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6161 | }; |
| 6162 | int status; |
| 6163 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6164 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6165 | |
| 6166 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6167 | * is not supported */ |
| 6168 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6169 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6170 | else |
| 6171 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6172 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6173 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6174 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6175 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6176 | 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] | 6177 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6178 | return status; |
| 6179 | } |
| 6180 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6181 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6182 | const struct qstr *name, |
| 6183 | struct nfs4_fs_locations *fs_locations, |
| 6184 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6185 | { |
| 6186 | struct nfs4_exception exception = { }; |
| 6187 | int err; |
| 6188 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6189 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6190 | fs_locations, page); |
| 6191 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6192 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6193 | &exception); |
| 6194 | } while (exception.retry); |
| 6195 | return err; |
| 6196 | } |
| 6197 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6198 | /* |
| 6199 | * This operation also signals the server that this client is |
| 6200 | * performing migration recovery. The server can stop returning |
| 6201 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6202 | * appended to this compound to identify the client ID which is |
| 6203 | * performing recovery. |
| 6204 | */ |
| 6205 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6206 | struct nfs4_fs_locations *locations, |
| 6207 | struct page *page, struct rpc_cred *cred) |
| 6208 | { |
| 6209 | struct nfs_server *server = NFS_SERVER(inode); |
| 6210 | struct rpc_clnt *clnt = server->client; |
| 6211 | u32 bitmask[2] = { |
| 6212 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6213 | }; |
| 6214 | struct nfs4_fs_locations_arg args = { |
| 6215 | .clientid = server->nfs_client->cl_clientid, |
| 6216 | .fh = NFS_FH(inode), |
| 6217 | .page = page, |
| 6218 | .bitmask = bitmask, |
| 6219 | .migration = 1, /* skip LOOKUP */ |
| 6220 | .renew = 1, /* append RENEW */ |
| 6221 | }; |
| 6222 | struct nfs4_fs_locations_res res = { |
| 6223 | .fs_locations = locations, |
| 6224 | .migration = 1, |
| 6225 | .renew = 1, |
| 6226 | }; |
| 6227 | struct rpc_message msg = { |
| 6228 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6229 | .rpc_argp = &args, |
| 6230 | .rpc_resp = &res, |
| 6231 | .rpc_cred = cred, |
| 6232 | }; |
| 6233 | unsigned long now = jiffies; |
| 6234 | int status; |
| 6235 | |
| 6236 | nfs_fattr_init(&locations->fattr); |
| 6237 | locations->server = server; |
| 6238 | locations->nlocations = 0; |
| 6239 | |
| 6240 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6241 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6242 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6243 | &args.seq_args, &res.seq_res); |
| 6244 | if (status) |
| 6245 | return status; |
| 6246 | |
| 6247 | renew_lease(server, now); |
| 6248 | return 0; |
| 6249 | } |
| 6250 | |
| 6251 | #ifdef CONFIG_NFS_V4_1 |
| 6252 | |
| 6253 | /* |
| 6254 | * This operation also signals the server that this client is |
| 6255 | * performing migration recovery. The server can stop asserting |
| 6256 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6257 | * performing this operation is identified in the SEQUENCE |
| 6258 | * operation in this compound. |
| 6259 | * |
| 6260 | * When the client supports GETATTR(fs_locations_info), it can |
| 6261 | * be plumbed in here. |
| 6262 | */ |
| 6263 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6264 | struct nfs4_fs_locations *locations, |
| 6265 | struct page *page, struct rpc_cred *cred) |
| 6266 | { |
| 6267 | struct nfs_server *server = NFS_SERVER(inode); |
| 6268 | struct rpc_clnt *clnt = server->client; |
| 6269 | u32 bitmask[2] = { |
| 6270 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6271 | }; |
| 6272 | struct nfs4_fs_locations_arg args = { |
| 6273 | .fh = NFS_FH(inode), |
| 6274 | .page = page, |
| 6275 | .bitmask = bitmask, |
| 6276 | .migration = 1, /* skip LOOKUP */ |
| 6277 | }; |
| 6278 | struct nfs4_fs_locations_res res = { |
| 6279 | .fs_locations = locations, |
| 6280 | .migration = 1, |
| 6281 | }; |
| 6282 | struct rpc_message msg = { |
| 6283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6284 | .rpc_argp = &args, |
| 6285 | .rpc_resp = &res, |
| 6286 | .rpc_cred = cred, |
| 6287 | }; |
| 6288 | int status; |
| 6289 | |
| 6290 | nfs_fattr_init(&locations->fattr); |
| 6291 | locations->server = server; |
| 6292 | locations->nlocations = 0; |
| 6293 | |
| 6294 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6295 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6296 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6297 | &args.seq_args, &res.seq_res); |
| 6298 | if (status == NFS4_OK && |
| 6299 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6300 | status = -NFS4ERR_LEASE_MOVED; |
| 6301 | return status; |
| 6302 | } |
| 6303 | |
| 6304 | #endif /* CONFIG_NFS_V4_1 */ |
| 6305 | |
| 6306 | /** |
| 6307 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6308 | * @inode: inode on FSID that is migrating |
| 6309 | * @locations: result of query |
| 6310 | * @page: buffer |
| 6311 | * @cred: credential to use for this operation |
| 6312 | * |
| 6313 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6314 | * operation failed, or a negative errno if a local error occurred. |
| 6315 | * |
| 6316 | * On success, "locations" is filled in, but if the server has |
| 6317 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6318 | * asserted. |
| 6319 | * |
| 6320 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6321 | * from this client that require migration recovery. |
| 6322 | */ |
| 6323 | int nfs4_proc_get_locations(struct inode *inode, |
| 6324 | struct nfs4_fs_locations *locations, |
| 6325 | struct page *page, struct rpc_cred *cred) |
| 6326 | { |
| 6327 | struct nfs_server *server = NFS_SERVER(inode); |
| 6328 | struct nfs_client *clp = server->nfs_client; |
| 6329 | const struct nfs4_mig_recovery_ops *ops = |
| 6330 | clp->cl_mvops->mig_recovery_ops; |
| 6331 | struct nfs4_exception exception = { }; |
| 6332 | int status; |
| 6333 | |
| 6334 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6335 | (unsigned long long)server->fsid.major, |
| 6336 | (unsigned long long)server->fsid.minor, |
| 6337 | clp->cl_hostname); |
| 6338 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6339 | |
| 6340 | do { |
| 6341 | status = ops->get_locations(inode, locations, page, cred); |
| 6342 | if (status != -NFS4ERR_DELAY) |
| 6343 | break; |
| 6344 | nfs4_handle_exception(server, status, &exception); |
| 6345 | } while (exception.retry); |
| 6346 | return status; |
| 6347 | } |
| 6348 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6349 | /* |
| 6350 | * This operation also signals the server that this client is |
| 6351 | * performing "lease moved" recovery. The server can stop |
| 6352 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6353 | * is appended to this compound to identify the client ID which is |
| 6354 | * performing recovery. |
| 6355 | */ |
| 6356 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6357 | { |
| 6358 | struct nfs_server *server = NFS_SERVER(inode); |
| 6359 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6360 | struct rpc_clnt *clnt = server->client; |
| 6361 | struct nfs4_fsid_present_arg args = { |
| 6362 | .fh = NFS_FH(inode), |
| 6363 | .clientid = clp->cl_clientid, |
| 6364 | .renew = 1, /* append RENEW */ |
| 6365 | }; |
| 6366 | struct nfs4_fsid_present_res res = { |
| 6367 | .renew = 1, |
| 6368 | }; |
| 6369 | struct rpc_message msg = { |
| 6370 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6371 | .rpc_argp = &args, |
| 6372 | .rpc_resp = &res, |
| 6373 | .rpc_cred = cred, |
| 6374 | }; |
| 6375 | unsigned long now = jiffies; |
| 6376 | int status; |
| 6377 | |
| 6378 | res.fh = nfs_alloc_fhandle(); |
| 6379 | if (res.fh == NULL) |
| 6380 | return -ENOMEM; |
| 6381 | |
| 6382 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6383 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6384 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6385 | &args.seq_args, &res.seq_res); |
| 6386 | nfs_free_fhandle(res.fh); |
| 6387 | if (status) |
| 6388 | return status; |
| 6389 | |
| 6390 | do_renew_lease(clp, now); |
| 6391 | return 0; |
| 6392 | } |
| 6393 | |
| 6394 | #ifdef CONFIG_NFS_V4_1 |
| 6395 | |
| 6396 | /* |
| 6397 | * This operation also signals the server that this client is |
| 6398 | * performing "lease moved" recovery. The server can stop asserting |
| 6399 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6400 | * this operation is identified in the SEQUENCE operation in this |
| 6401 | * compound. |
| 6402 | */ |
| 6403 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6404 | { |
| 6405 | struct nfs_server *server = NFS_SERVER(inode); |
| 6406 | struct rpc_clnt *clnt = server->client; |
| 6407 | struct nfs4_fsid_present_arg args = { |
| 6408 | .fh = NFS_FH(inode), |
| 6409 | }; |
| 6410 | struct nfs4_fsid_present_res res = { |
| 6411 | }; |
| 6412 | struct rpc_message msg = { |
| 6413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6414 | .rpc_argp = &args, |
| 6415 | .rpc_resp = &res, |
| 6416 | .rpc_cred = cred, |
| 6417 | }; |
| 6418 | int status; |
| 6419 | |
| 6420 | res.fh = nfs_alloc_fhandle(); |
| 6421 | if (res.fh == NULL) |
| 6422 | return -ENOMEM; |
| 6423 | |
| 6424 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6425 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6426 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6427 | &args.seq_args, &res.seq_res); |
| 6428 | nfs_free_fhandle(res.fh); |
| 6429 | if (status == NFS4_OK && |
| 6430 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6431 | status = -NFS4ERR_LEASE_MOVED; |
| 6432 | return status; |
| 6433 | } |
| 6434 | |
| 6435 | #endif /* CONFIG_NFS_V4_1 */ |
| 6436 | |
| 6437 | /** |
| 6438 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6439 | * @inode: inode on FSID to check |
| 6440 | * @cred: credential to use for this operation |
| 6441 | * |
| 6442 | * Server indicates whether the FSID is present, moved, or not |
| 6443 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6444 | * condition for this client ID. |
| 6445 | * |
| 6446 | * Returns NFS4_OK if the FSID is present on this server, |
| 6447 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6448 | * NFS4ERR code if some error occurred on the server, or a |
| 6449 | * negative errno if a local failure occurred. |
| 6450 | */ |
| 6451 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6452 | { |
| 6453 | struct nfs_server *server = NFS_SERVER(inode); |
| 6454 | struct nfs_client *clp = server->nfs_client; |
| 6455 | const struct nfs4_mig_recovery_ops *ops = |
| 6456 | clp->cl_mvops->mig_recovery_ops; |
| 6457 | struct nfs4_exception exception = { }; |
| 6458 | int status; |
| 6459 | |
| 6460 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6461 | (unsigned long long)server->fsid.major, |
| 6462 | (unsigned long long)server->fsid.minor, |
| 6463 | clp->cl_hostname); |
| 6464 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6465 | |
| 6466 | do { |
| 6467 | status = ops->fsid_present(inode, cred); |
| 6468 | if (status != -NFS4ERR_DELAY) |
| 6469 | break; |
| 6470 | nfs4_handle_exception(server, status, &exception); |
| 6471 | } while (exception.retry); |
| 6472 | return status; |
| 6473 | } |
| 6474 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6475 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6476 | * If 'use_integrity' is true and the state managment nfs_client |
| 6477 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6478 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6479 | * Considerations sections. Otherwise, just use the user cred with the |
| 6480 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6481 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6482 | 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] | 6483 | { |
| 6484 | int status; |
| 6485 | struct nfs4_secinfo_arg args = { |
| 6486 | .dir_fh = NFS_FH(dir), |
| 6487 | .name = name, |
| 6488 | }; |
| 6489 | struct nfs4_secinfo_res res = { |
| 6490 | .flavors = flavors, |
| 6491 | }; |
| 6492 | struct rpc_message msg = { |
| 6493 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6494 | .rpc_argp = &args, |
| 6495 | .rpc_resp = &res, |
| 6496 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6497 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6498 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6499 | |
| 6500 | if (use_integrity) { |
| 6501 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6502 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6503 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6504 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6505 | |
| 6506 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6507 | |
| 6508 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6509 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6510 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6511 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6512 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6513 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6514 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6515 | if (cred) |
| 6516 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6517 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6518 | return status; |
| 6519 | } |
| 6520 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6521 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6522 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6523 | { |
| 6524 | struct nfs4_exception exception = { }; |
| 6525 | int err; |
| 6526 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6527 | err = -NFS4ERR_WRONGSEC; |
| 6528 | |
| 6529 | /* try to use integrity protection with machine cred */ |
| 6530 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6531 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6532 | |
| 6533 | /* |
| 6534 | * if unable to use integrity protection, or SECINFO with |
| 6535 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6536 | * disallowed by spec, but exists in deployed servers) use |
| 6537 | * the current filesystem's rpc_client and the user cred. |
| 6538 | */ |
| 6539 | if (err == -NFS4ERR_WRONGSEC) |
| 6540 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6541 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6542 | trace_nfs4_secinfo(dir, name, err); |
| 6543 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6544 | &exception); |
| 6545 | } while (exception.retry); |
| 6546 | return err; |
| 6547 | } |
| 6548 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6549 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6550 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6551 | * Check the exchange flags returned by the server for invalid flags, having |
| 6552 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6553 | * DS flags set. |
| 6554 | */ |
| 6555 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6556 | { |
| 6557 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6558 | goto out_inval; |
| 6559 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6560 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6561 | goto out_inval; |
| 6562 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6563 | goto out_inval; |
| 6564 | return NFS_OK; |
| 6565 | out_inval: |
| 6566 | return -NFS4ERR_INVAL; |
| 6567 | } |
| 6568 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6569 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6570 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6571 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6572 | { |
| 6573 | if (a->server_scope_sz == b->server_scope_sz && |
| 6574 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6575 | return true; |
| 6576 | |
| 6577 | return false; |
| 6578 | } |
| 6579 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6580 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6581 | * nfs4_proc_bind_conn_to_session() |
| 6582 | * |
| 6583 | * The 4.1 client currently uses the same TCP connection for the |
| 6584 | * fore and backchannel. |
| 6585 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6586 | 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] | 6587 | { |
| 6588 | int status; |
| 6589 | struct nfs41_bind_conn_to_session_res res; |
| 6590 | struct rpc_message msg = { |
| 6591 | .rpc_proc = |
| 6592 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 6593 | .rpc_argp = clp, |
| 6594 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6595 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6596 | }; |
| 6597 | |
| 6598 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6599 | |
| 6600 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 6601 | if (unlikely(res.session == NULL)) { |
| 6602 | status = -ENOMEM; |
| 6603 | goto out; |
| 6604 | } |
| 6605 | |
| 6606 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6607 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6608 | if (status == 0) { |
| 6609 | if (memcmp(res.session->sess_id.data, |
| 6610 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6611 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6612 | status = -EIO; |
| 6613 | goto out_session; |
| 6614 | } |
| 6615 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 6616 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6617 | __func__); |
| 6618 | status = -EIO; |
| 6619 | goto out_session; |
| 6620 | } |
| 6621 | if (res.use_conn_in_rdma_mode) { |
| 6622 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6623 | __func__); |
| 6624 | status = -EIO; |
| 6625 | goto out_session; |
| 6626 | } |
| 6627 | } |
| 6628 | out_session: |
| 6629 | kfree(res.session); |
| 6630 | out: |
| 6631 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6632 | return status; |
| 6633 | } |
| 6634 | |
| 6635 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6636 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6637 | * 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] | 6638 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6639 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6640 | .how = SP4_MACH_CRED, |
| 6641 | .enforce.u.words = { |
| 6642 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6643 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6644 | 1 << (OP_CREATE_SESSION - 32) | |
| 6645 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6646 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6647 | }, |
| 6648 | .allow.u.words = { |
| 6649 | [0] = 1 << (OP_CLOSE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6650 | 1 << (OP_LOCKU) | |
| 6651 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6652 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6653 | 1 << (OP_SECINFO_NO_NAME - 32) | |
| 6654 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6655 | 1 << (OP_FREE_STATEID - 32) | |
| 6656 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6657 | } |
| 6658 | }; |
| 6659 | |
| 6660 | /* |
| 6661 | * Select the state protection mode for client `clp' given the server results |
| 6662 | * from exchange_id in `sp'. |
| 6663 | * |
| 6664 | * Returns 0 on success, negative errno otherwise. |
| 6665 | */ |
| 6666 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6667 | struct nfs41_state_protection *sp) |
| 6668 | { |
| 6669 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6670 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6671 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6672 | 1 << (OP_CREATE_SESSION - 32) | |
| 6673 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6674 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6675 | }; |
| 6676 | unsigned int i; |
| 6677 | |
| 6678 | if (sp->how == SP4_MACH_CRED) { |
| 6679 | /* Print state protect result */ |
| 6680 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6681 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6682 | if (test_bit(i, sp->enforce.u.longs)) |
| 6683 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6684 | if (test_bit(i, sp->allow.u.longs)) |
| 6685 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6686 | } |
| 6687 | |
| 6688 | /* make sure nothing is on enforce list that isn't supported */ |
| 6689 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6690 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6691 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6692 | return -EINVAL; |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | /* |
| 6697 | * Minimal mode - state operations are allowed to use machine |
| 6698 | * credential. Note this already happens by default, so the |
| 6699 | * client doesn't have to do anything more than the negotiation. |
| 6700 | * |
| 6701 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6702 | * we're already using the machine cred for exchange_id |
| 6703 | * and will never use a different cred. |
| 6704 | */ |
| 6705 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6706 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6707 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6708 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6709 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6710 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6711 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 6712 | } else { |
| 6713 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6714 | return -EINVAL; |
| 6715 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6716 | |
| 6717 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
| 6718 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 6719 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 6720 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 6721 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6722 | |
| 6723 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 6724 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 6725 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 6726 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 6727 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6728 | |
| 6729 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 6730 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 6731 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 6732 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 6733 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6734 | |
| 6735 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 6736 | dfprintk(MOUNT, " write mode enabled\n"); |
| 6737 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 6738 | } |
| 6739 | |
| 6740 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 6741 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 6742 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 6743 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | return 0; |
| 6747 | } |
| 6748 | |
| 6749 | /* |
| 6750 | * _nfs4_proc_exchange_id() |
| 6751 | * |
| 6752 | * Wrapper for EXCHANGE_ID operation. |
| 6753 | */ |
| 6754 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 6755 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6756 | { |
| 6757 | nfs4_verifier verifier; |
| 6758 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6759 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6760 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6761 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6762 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6763 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 6764 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 6765 | #else |
| 6766 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 6767 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 6768 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6769 | }; |
| 6770 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6771 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6772 | }; |
| 6773 | int status; |
| 6774 | struct rpc_message msg = { |
| 6775 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 6776 | .rpc_argp = &args, |
| 6777 | .rpc_resp = &res, |
| 6778 | .rpc_cred = cred, |
| 6779 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6780 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6781 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6782 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 6783 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6784 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 6785 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6786 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6787 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6788 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6789 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6790 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6791 | status = -ENOMEM; |
| 6792 | goto out; |
| 6793 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6794 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6795 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6796 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6797 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6798 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6799 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6800 | } |
| 6801 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6802 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6803 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6804 | status = -ENOMEM; |
| 6805 | goto out_server_scope; |
| 6806 | } |
| 6807 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6808 | switch (sp4_how) { |
| 6809 | case SP4_NONE: |
| 6810 | args.state_protect.how = SP4_NONE; |
| 6811 | break; |
| 6812 | |
| 6813 | case SP4_MACH_CRED: |
| 6814 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 6815 | break; |
| 6816 | |
| 6817 | default: |
| 6818 | /* unsupported! */ |
| 6819 | WARN_ON_ONCE(1); |
| 6820 | status = -EINVAL; |
| 6821 | goto out_server_scope; |
| 6822 | } |
| 6823 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6824 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6825 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6826 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6827 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6828 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6829 | if (status == 0) |
| 6830 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 6831 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6832 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6833 | clp->cl_clientid = res.clientid; |
| 6834 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 6835 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 6836 | clp->cl_seqid = res.seqid; |
| 6837 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6838 | kfree(clp->cl_serverowner); |
| 6839 | clp->cl_serverowner = res.server_owner; |
| 6840 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6841 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6842 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6843 | kfree(clp->cl_implid); |
| 6844 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6845 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6846 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6847 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6848 | res.server_scope)) { |
| 6849 | dprintk("%s: server_scope mismatch detected\n", |
| 6850 | __func__); |
| 6851 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6852 | kfree(clp->cl_serverscope); |
| 6853 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6854 | } |
| 6855 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6856 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6857 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6858 | goto out; |
| 6859 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6860 | } else |
| 6861 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6862 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6863 | out_server_owner: |
| 6864 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6865 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6866 | kfree(res.server_scope); |
| 6867 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6868 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6869 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6870 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6871 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6872 | clp->cl_implid->date.seconds, |
| 6873 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6874 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6875 | return status; |
| 6876 | } |
| 6877 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6878 | /* |
| 6879 | * nfs4_proc_exchange_id() |
| 6880 | * |
| 6881 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6882 | * |
| 6883 | * Since the clientid has expired, all compounds using sessions |
| 6884 | * associated with the stale clientid will be returning |
| 6885 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 6886 | * be in some phase of session reset. |
| 6887 | * |
| 6888 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 6889 | */ |
| 6890 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 6891 | { |
| 6892 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 6893 | int status; |
| 6894 | |
| 6895 | /* try SP4_MACH_CRED if krb5i/p */ |
| 6896 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 6897 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 6898 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 6899 | if (!status) |
| 6900 | return 0; |
| 6901 | } |
| 6902 | |
| 6903 | /* try SP4_NONE */ |
| 6904 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 6905 | } |
| 6906 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6907 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6908 | struct rpc_cred *cred) |
| 6909 | { |
| 6910 | struct rpc_message msg = { |
| 6911 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6912 | .rpc_argp = clp, |
| 6913 | .rpc_cred = cred, |
| 6914 | }; |
| 6915 | int status; |
| 6916 | |
| 6917 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6918 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6919 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6920 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6921 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6922 | return status; |
| 6923 | } |
| 6924 | |
| 6925 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6926 | struct rpc_cred *cred) |
| 6927 | { |
| 6928 | unsigned int loop; |
| 6929 | int ret; |
| 6930 | |
| 6931 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6932 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6933 | switch (ret) { |
| 6934 | case -NFS4ERR_DELAY: |
| 6935 | case -NFS4ERR_CLIENTID_BUSY: |
| 6936 | ssleep(1); |
| 6937 | break; |
| 6938 | default: |
| 6939 | return ret; |
| 6940 | } |
| 6941 | } |
| 6942 | return 0; |
| 6943 | } |
| 6944 | |
| 6945 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6946 | { |
| 6947 | struct rpc_cred *cred; |
| 6948 | int ret = 0; |
| 6949 | |
| 6950 | if (clp->cl_mvops->minor_version < 1) |
| 6951 | goto out; |
| 6952 | if (clp->cl_exchange_flags == 0) |
| 6953 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6954 | if (clp->cl_preserve_clid) |
| 6955 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6956 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6957 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6958 | if (cred) |
| 6959 | put_rpccred(cred); |
| 6960 | switch (ret) { |
| 6961 | case 0: |
| 6962 | case -NFS4ERR_STALE_CLIENTID: |
| 6963 | clp->cl_exchange_flags = 0; |
| 6964 | } |
| 6965 | out: |
| 6966 | return ret; |
| 6967 | } |
| 6968 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6969 | struct nfs4_get_lease_time_data { |
| 6970 | struct nfs4_get_lease_time_args *args; |
| 6971 | struct nfs4_get_lease_time_res *res; |
| 6972 | struct nfs_client *clp; |
| 6973 | }; |
| 6974 | |
| 6975 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6976 | void *calldata) |
| 6977 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6978 | struct nfs4_get_lease_time_data *data = |
| 6979 | (struct nfs4_get_lease_time_data *)calldata; |
| 6980 | |
| 6981 | dprintk("--> %s\n", __func__); |
| 6982 | /* just setup sequence, do not trigger session recovery |
| 6983 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6984 | nfs41_setup_sequence(data->clp->cl_session, |
| 6985 | &data->args->la_seq_args, |
| 6986 | &data->res->lr_seq_res, |
| 6987 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6988 | dprintk("<-- %s\n", __func__); |
| 6989 | } |
| 6990 | |
| 6991 | /* |
| 6992 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6993 | * from sequence operation or clientid errors. |
| 6994 | */ |
| 6995 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6996 | { |
| 6997 | struct nfs4_get_lease_time_data *data = |
| 6998 | (struct nfs4_get_lease_time_data *)calldata; |
| 6999 | |
| 7000 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7001 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7002 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7003 | switch (task->tk_status) { |
| 7004 | case -NFS4ERR_DELAY: |
| 7005 | case -NFS4ERR_GRACE: |
| 7006 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7007 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7008 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7009 | /* fall through */ |
| 7010 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7011 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7012 | return; |
| 7013 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7014 | dprintk("<-- %s\n", __func__); |
| 7015 | } |
| 7016 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7017 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7018 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7019 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7020 | }; |
| 7021 | |
| 7022 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7023 | { |
| 7024 | struct rpc_task *task; |
| 7025 | struct nfs4_get_lease_time_args args; |
| 7026 | struct nfs4_get_lease_time_res res = { |
| 7027 | .lr_fsinfo = fsinfo, |
| 7028 | }; |
| 7029 | struct nfs4_get_lease_time_data data = { |
| 7030 | .args = &args, |
| 7031 | .res = &res, |
| 7032 | .clp = clp, |
| 7033 | }; |
| 7034 | struct rpc_message msg = { |
| 7035 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7036 | .rpc_argp = &args, |
| 7037 | .rpc_resp = &res, |
| 7038 | }; |
| 7039 | struct rpc_task_setup task_setup = { |
| 7040 | .rpc_client = clp->cl_rpcclient, |
| 7041 | .rpc_message = &msg, |
| 7042 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7043 | .callback_data = &data, |
| 7044 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7045 | }; |
| 7046 | int status; |
| 7047 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7048 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7049 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7050 | dprintk("--> %s\n", __func__); |
| 7051 | task = rpc_run_task(&task_setup); |
| 7052 | |
| 7053 | if (IS_ERR(task)) |
| 7054 | status = PTR_ERR(task); |
| 7055 | else { |
| 7056 | status = task->tk_status; |
| 7057 | rpc_put_task(task); |
| 7058 | } |
| 7059 | dprintk("<-- %s return %d\n", __func__, status); |
| 7060 | |
| 7061 | return status; |
| 7062 | } |
| 7063 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7064 | /* |
| 7065 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7066 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7067 | * use them. |
| 7068 | * |
| 7069 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7070 | * always set csa_cachethis to FALSE because the current implementation |
| 7071 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7072 | */ |
| 7073 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 7074 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7075 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7076 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7077 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7078 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7079 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7080 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7081 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7082 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7083 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7084 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7085 | |
| 7086 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7087 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7088 | __func__, |
| 7089 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7090 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7091 | |
| 7092 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7093 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 7094 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 7095 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7096 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 7097 | args->bc_attrs.max_reqs = 1; |
| 7098 | |
| 7099 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7100 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7101 | __func__, |
| 7102 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7103 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7104 | args->bc_attrs.max_reqs); |
| 7105 | } |
| 7106 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7107 | 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] | 7108 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7109 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 7110 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 7111 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7112 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7113 | return -EINVAL; |
| 7114 | /* |
| 7115 | * Our requested max_ops is the minimum we need; we're not |
| 7116 | * prepared to break up compounds into smaller pieces than that. |
| 7117 | * So, no point even trying to continue if the server won't |
| 7118 | * cooperate: |
| 7119 | */ |
| 7120 | if (rcvd->max_ops < sent->max_ops) |
| 7121 | return -EINVAL; |
| 7122 | if (rcvd->max_reqs == 0) |
| 7123 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7124 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7125 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7126 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7127 | } |
| 7128 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7129 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 7130 | { |
| 7131 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 7132 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7133 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7134 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7135 | return -EINVAL; |
| 7136 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7137 | return -EINVAL; |
| 7138 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7139 | return -EINVAL; |
| 7140 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7141 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7142 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7143 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7144 | return -EINVAL; |
| 7145 | return 0; |
| 7146 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7147 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7148 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 7149 | struct nfs4_session *session) |
| 7150 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7151 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7152 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7153 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 7154 | if (ret) |
| 7155 | return ret; |
| 7156 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7157 | } |
| 7158 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7159 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7160 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7161 | { |
| 7162 | struct nfs4_session *session = clp->cl_session; |
| 7163 | struct nfs41_create_session_args args = { |
| 7164 | .client = clp, |
| 7165 | .cb_program = NFS4_CALLBACK, |
| 7166 | }; |
| 7167 | struct nfs41_create_session_res res = { |
| 7168 | .client = clp, |
| 7169 | }; |
| 7170 | struct rpc_message msg = { |
| 7171 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7172 | .rpc_argp = &args, |
| 7173 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7174 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7175 | }; |
| 7176 | int status; |
| 7177 | |
| 7178 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7179 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7180 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7181 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7182 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7183 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7184 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7185 | /* Verify the session's negotiated channel_attrs values */ |
| 7186 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7187 | /* Increment the clientid slot sequence id */ |
| 7188 | clp->cl_seqid++; |
| 7189 | } |
| 7190 | |
| 7191 | return status; |
| 7192 | } |
| 7193 | |
| 7194 | /* |
| 7195 | * Issues a CREATE_SESSION operation to the server. |
| 7196 | * It is the responsibility of the caller to verify the session is |
| 7197 | * expired before calling this routine. |
| 7198 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7199 | 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] | 7200 | { |
| 7201 | int status; |
| 7202 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7203 | struct nfs4_session *session = clp->cl_session; |
| 7204 | |
| 7205 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7206 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7207 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7208 | if (status) |
| 7209 | goto out; |
| 7210 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7211 | /* Init or reset the session slot tables */ |
| 7212 | status = nfs4_setup_session_slot_tables(session); |
| 7213 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7214 | if (status) |
| 7215 | goto out; |
| 7216 | |
| 7217 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7218 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7219 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7220 | out: |
| 7221 | dprintk("<-- %s\n", __func__); |
| 7222 | return status; |
| 7223 | } |
| 7224 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7225 | /* |
| 7226 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7227 | * The caller must serialize access to this routine. |
| 7228 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7229 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7230 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7231 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7232 | struct rpc_message msg = { |
| 7233 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7234 | .rpc_argp = session, |
| 7235 | .rpc_cred = cred, |
| 7236 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7237 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7238 | |
| 7239 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7240 | |
| 7241 | /* session is still being setup */ |
| 7242 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 7243 | return status; |
| 7244 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7245 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7246 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7247 | |
| 7248 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7249 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7250 | "Session has been destroyed regardless...\n", status); |
| 7251 | |
| 7252 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7253 | return status; |
| 7254 | } |
| 7255 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7256 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7257 | * Renew the cl_session lease. |
| 7258 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7259 | struct nfs4_sequence_data { |
| 7260 | struct nfs_client *clp; |
| 7261 | struct nfs4_sequence_args args; |
| 7262 | struct nfs4_sequence_res res; |
| 7263 | }; |
| 7264 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7265 | static void nfs41_sequence_release(void *data) |
| 7266 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7267 | struct nfs4_sequence_data *calldata = data; |
| 7268 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7269 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7270 | if (atomic_read(&clp->cl_count) > 1) |
| 7271 | nfs4_schedule_state_renewal(clp); |
| 7272 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7273 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7274 | } |
| 7275 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7276 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7277 | { |
| 7278 | switch(task->tk_status) { |
| 7279 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7280 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7281 | return -EAGAIN; |
| 7282 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7283 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7284 | } |
| 7285 | return 0; |
| 7286 | } |
| 7287 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7288 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7289 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7290 | struct nfs4_sequence_data *calldata = data; |
| 7291 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7292 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7293 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7294 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7295 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7296 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7297 | if (task->tk_status < 0) { |
| 7298 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7299 | if (atomic_read(&clp->cl_count) == 1) |
| 7300 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7301 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7302 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7303 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7304 | return; |
| 7305 | } |
| 7306 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7307 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7308 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7309 | dprintk("<-- %s\n", __func__); |
| 7310 | } |
| 7311 | |
| 7312 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7313 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7314 | struct nfs4_sequence_data *calldata = data; |
| 7315 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7316 | struct nfs4_sequence_args *args; |
| 7317 | struct nfs4_sequence_res *res; |
| 7318 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7319 | args = task->tk_msg.rpc_argp; |
| 7320 | res = task->tk_msg.rpc_resp; |
| 7321 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7322 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7323 | } |
| 7324 | |
| 7325 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7326 | .rpc_call_done = nfs41_sequence_call_done, |
| 7327 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7328 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7329 | }; |
| 7330 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7331 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7332 | struct rpc_cred *cred, |
| 7333 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7334 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7335 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7336 | struct rpc_message msg = { |
| 7337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7338 | .rpc_cred = cred, |
| 7339 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7340 | struct rpc_task_setup task_setup_data = { |
| 7341 | .rpc_client = clp->cl_rpcclient, |
| 7342 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7343 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7344 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7345 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7346 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7347 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7348 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7349 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7350 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7351 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7352 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7353 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7354 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7355 | if (is_privileged) |
| 7356 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7357 | msg.rpc_argp = &calldata->args; |
| 7358 | msg.rpc_resp = &calldata->res; |
| 7359 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7360 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7361 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7362 | return rpc_run_task(&task_setup_data); |
| 7363 | } |
| 7364 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7365 | 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] | 7366 | { |
| 7367 | struct rpc_task *task; |
| 7368 | int ret = 0; |
| 7369 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7370 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 7371 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7372 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7373 | if (IS_ERR(task)) |
| 7374 | ret = PTR_ERR(task); |
| 7375 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7376 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7377 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7378 | return ret; |
| 7379 | } |
| 7380 | |
| 7381 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7382 | { |
| 7383 | struct rpc_task *task; |
| 7384 | int ret; |
| 7385 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7386 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7387 | if (IS_ERR(task)) { |
| 7388 | ret = PTR_ERR(task); |
| 7389 | goto out; |
| 7390 | } |
| 7391 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7392 | if (!ret) { |
| 7393 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 7394 | |
| 7395 | if (task->tk_status == 0) |
| 7396 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7397 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7398 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7399 | rpc_put_task(task); |
| 7400 | out: |
| 7401 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7402 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7403 | } |
| 7404 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7405 | struct nfs4_reclaim_complete_data { |
| 7406 | struct nfs_client *clp; |
| 7407 | struct nfs41_reclaim_complete_args arg; |
| 7408 | struct nfs41_reclaim_complete_res res; |
| 7409 | }; |
| 7410 | |
| 7411 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7412 | { |
| 7413 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7414 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7415 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7416 | &calldata->arg.seq_args, |
| 7417 | &calldata->res.seq_res, |
| 7418 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7419 | } |
| 7420 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7421 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7422 | { |
| 7423 | switch(task->tk_status) { |
| 7424 | case 0: |
| 7425 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7426 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7427 | break; |
| 7428 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7429 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7430 | /* fall through */ |
| 7431 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7432 | return -EAGAIN; |
| 7433 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7434 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7435 | } |
| 7436 | return 0; |
| 7437 | } |
| 7438 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7439 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7440 | { |
| 7441 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7442 | struct nfs_client *clp = calldata->clp; |
| 7443 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7444 | |
| 7445 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7446 | if (!nfs41_sequence_done(task, res)) |
| 7447 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7448 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7449 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7450 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7451 | rpc_restart_call_prepare(task); |
| 7452 | return; |
| 7453 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7454 | dprintk("<-- %s\n", __func__); |
| 7455 | } |
| 7456 | |
| 7457 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7458 | { |
| 7459 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7460 | |
| 7461 | kfree(calldata); |
| 7462 | } |
| 7463 | |
| 7464 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7465 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7466 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7467 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7468 | }; |
| 7469 | |
| 7470 | /* |
| 7471 | * Issue a global reclaim complete. |
| 7472 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7473 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7474 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7475 | { |
| 7476 | struct nfs4_reclaim_complete_data *calldata; |
| 7477 | struct rpc_task *task; |
| 7478 | struct rpc_message msg = { |
| 7479 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7480 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7481 | }; |
| 7482 | struct rpc_task_setup task_setup_data = { |
| 7483 | .rpc_client = clp->cl_rpcclient, |
| 7484 | .rpc_message = &msg, |
| 7485 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7486 | .flags = RPC_TASK_ASYNC, |
| 7487 | }; |
| 7488 | int status = -ENOMEM; |
| 7489 | |
| 7490 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7491 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7492 | if (calldata == NULL) |
| 7493 | goto out; |
| 7494 | calldata->clp = clp; |
| 7495 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7496 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7497 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7498 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7499 | msg.rpc_argp = &calldata->arg; |
| 7500 | msg.rpc_resp = &calldata->res; |
| 7501 | task_setup_data.callback_data = calldata; |
| 7502 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7503 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7504 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7505 | goto out; |
| 7506 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7507 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7508 | if (status == 0) |
| 7509 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7510 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7511 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7512 | out: |
| 7513 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7514 | return status; |
| 7515 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7516 | |
| 7517 | static void |
| 7518 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7519 | { |
| 7520 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7521 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7522 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7523 | |
| 7524 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7525 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 7526 | * right now covering the LAYOUTGET we are about to send. |
| 7527 | * However, that is not so catastrophic, and there seems |
| 7528 | * to be no way to prevent it completely. |
| 7529 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7530 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7531 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7532 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7533 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7534 | NFS_I(lgp->args.inode)->layout, |
| 7535 | lgp->args.ctx->state)) { |
| 7536 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7537 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7541 | { |
| 7542 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7543 | struct inode *inode = lgp->args.inode; |
| 7544 | struct nfs_server *server = NFS_SERVER(inode); |
| 7545 | struct pnfs_layout_hdr *lo; |
| 7546 | struct nfs4_state *state = NULL; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7547 | unsigned long timeo, now, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7548 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7549 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7550 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7551 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7552 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7553 | |
| 7554 | switch (task->tk_status) { |
| 7555 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7556 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7557 | /* |
| 7558 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
| 7559 | * (or clients) writing to the same RAID stripe |
| 7560 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7561 | case -NFS4ERR_LAYOUTTRYLATER: |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7562 | /* |
| 7563 | * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall |
| 7564 | * existing layout before getting a new one). |
| 7565 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7566 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7567 | timeo = rpc_get_timeout(task->tk_client); |
| 7568 | giveup = lgp->args.timestamp + timeo; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7569 | now = jiffies; |
| 7570 | if (time_after(giveup, now)) { |
| 7571 | unsigned long delay; |
| 7572 | |
| 7573 | /* Delay for: |
| 7574 | * - Not less then NFS4_POLL_RETRY_MIN. |
| 7575 | * - One last time a jiffie before we give up |
| 7576 | * - exponential backoff (time_now minus start_attempt) |
| 7577 | */ |
| 7578 | delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN, |
| 7579 | min((giveup - now - 1), |
| 7580 | now - lgp->args.timestamp)); |
| 7581 | |
| 7582 | dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n", |
| 7583 | __func__, delay); |
| 7584 | rpc_delay(task, delay); |
| 7585 | task->tk_status = 0; |
| 7586 | rpc_restart_call_prepare(task); |
| 7587 | goto out; /* Do not call nfs4_async_handle_error() */ |
| 7588 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7589 | break; |
| 7590 | case -NFS4ERR_EXPIRED: |
| 7591 | case -NFS4ERR_BAD_STATEID: |
| 7592 | spin_lock(&inode->i_lock); |
| 7593 | lo = NFS_I(inode)->layout; |
| 7594 | if (!lo || list_empty(&lo->plh_segs)) { |
| 7595 | spin_unlock(&inode->i_lock); |
| 7596 | /* If the open stateid was bad, then recover it. */ |
| 7597 | state = lgp->args.ctx->state; |
| 7598 | } else { |
| 7599 | LIST_HEAD(head); |
| 7600 | |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7601 | /* |
| 7602 | * Mark the bad layout state as invalid, then retry |
| 7603 | * with the current stateid. |
| 7604 | */ |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7605 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 7606 | spin_unlock(&inode->i_lock); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7607 | pnfs_free_lseg_list(&head); |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7608 | |
| 7609 | task->tk_status = 0; |
| 7610 | rpc_restart_call_prepare(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7611 | } |
| 7612 | } |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 7613 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7614 | rpc_restart_call_prepare(task); |
| 7615 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7616 | dprintk("<-- %s\n", __func__); |
| 7617 | } |
| 7618 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7619 | static size_t max_response_pages(struct nfs_server *server) |
| 7620 | { |
| 7621 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7622 | return nfs_page_array_len(0, max_resp_sz); |
| 7623 | } |
| 7624 | |
| 7625 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7626 | { |
| 7627 | int i; |
| 7628 | |
| 7629 | if (!pages) |
| 7630 | return; |
| 7631 | |
| 7632 | for (i = 0; i < size; i++) { |
| 7633 | if (!pages[i]) |
| 7634 | break; |
| 7635 | __free_page(pages[i]); |
| 7636 | } |
| 7637 | kfree(pages); |
| 7638 | } |
| 7639 | |
| 7640 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7641 | { |
| 7642 | struct page **pages; |
| 7643 | int i; |
| 7644 | |
| 7645 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7646 | if (!pages) { |
| 7647 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7648 | return NULL; |
| 7649 | } |
| 7650 | |
| 7651 | for (i = 0; i < size; i++) { |
| 7652 | pages[i] = alloc_page(gfp_flags); |
| 7653 | if (!pages[i]) { |
| 7654 | dprintk("%s: failed to allocate page\n", __func__); |
| 7655 | nfs4_free_pages(pages, size); |
| 7656 | return NULL; |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | return pages; |
| 7661 | } |
| 7662 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7663 | static void nfs4_layoutget_release(void *calldata) |
| 7664 | { |
| 7665 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7666 | struct inode *inode = lgp->args.inode; |
| 7667 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7668 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7669 | |
| 7670 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7671 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7672 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7673 | put_nfs_open_context(lgp->args.ctx); |
| 7674 | kfree(calldata); |
| 7675 | dprintk("<-- %s\n", __func__); |
| 7676 | } |
| 7677 | |
| 7678 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 7679 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 7680 | .rpc_call_done = nfs4_layoutget_done, |
| 7681 | .rpc_release = nfs4_layoutget_release, |
| 7682 | }; |
| 7683 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7684 | struct pnfs_layout_segment * |
| 7685 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7686 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7687 | struct inode *inode = lgp->args.inode; |
| 7688 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7689 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7690 | struct rpc_task *task; |
| 7691 | struct rpc_message msg = { |
| 7692 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 7693 | .rpc_argp = &lgp->args, |
| 7694 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7695 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7696 | }; |
| 7697 | struct rpc_task_setup task_setup_data = { |
| 7698 | .rpc_client = server->client, |
| 7699 | .rpc_message = &msg, |
| 7700 | .callback_ops = &nfs4_layoutget_call_ops, |
| 7701 | .callback_data = lgp, |
| 7702 | .flags = RPC_TASK_ASYNC, |
| 7703 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7704 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7705 | int status = 0; |
| 7706 | |
| 7707 | dprintk("--> %s\n", __func__); |
| 7708 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7709 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 7710 | if (!lgp->args.layout.pages) { |
| 7711 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7712 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7713 | } |
| 7714 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7715 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7716 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 7717 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7718 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7719 | 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] | 7720 | |
| 7721 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 7722 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 7723 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7724 | task = rpc_run_task(&task_setup_data); |
| 7725 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7726 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7727 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7728 | if (status == 0) |
| 7729 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7730 | trace_nfs4_layoutget(lgp->args.ctx, |
| 7731 | &lgp->args.range, |
| 7732 | &lgp->res.range, |
| 7733 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 7734 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 7735 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7736 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7737 | rpc_put_task(task); |
| 7738 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7739 | if (status) |
| 7740 | return ERR_PTR(status); |
| 7741 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7742 | } |
| 7743 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7744 | static void |
| 7745 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 7746 | { |
| 7747 | struct nfs4_layoutreturn *lrp = calldata; |
| 7748 | |
| 7749 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7750 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 7751 | &lrp->args.seq_args, |
| 7752 | &lrp->res.seq_res, |
| 7753 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7754 | } |
| 7755 | |
| 7756 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 7757 | { |
| 7758 | struct nfs4_layoutreturn *lrp = calldata; |
| 7759 | struct nfs_server *server; |
| 7760 | |
| 7761 | dprintk("--> %s\n", __func__); |
| 7762 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7763 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7764 | return; |
| 7765 | |
| 7766 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7767 | switch (task->tk_status) { |
| 7768 | default: |
| 7769 | task->tk_status = 0; |
| 7770 | case 0: |
| 7771 | break; |
| 7772 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 7773 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7774 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7775 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7776 | return; |
| 7777 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7778 | dprintk("<-- %s\n", __func__); |
| 7779 | } |
| 7780 | |
| 7781 | static void nfs4_layoutreturn_release(void *calldata) |
| 7782 | { |
| 7783 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7784 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7785 | |
| 7786 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7787 | spin_lock(&lo->plh_inode->i_lock); |
| 7788 | if (lrp->res.lrs_present) |
| 7789 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 7790 | lo->plh_block_lgets--; |
| 7791 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 7792 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7793 | kfree(calldata); |
| 7794 | dprintk("<-- %s\n", __func__); |
| 7795 | } |
| 7796 | |
| 7797 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 7798 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 7799 | .rpc_call_done = nfs4_layoutreturn_done, |
| 7800 | .rpc_release = nfs4_layoutreturn_release, |
| 7801 | }; |
| 7802 | |
| 7803 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 7804 | { |
| 7805 | struct rpc_task *task; |
| 7806 | struct rpc_message msg = { |
| 7807 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 7808 | .rpc_argp = &lrp->args, |
| 7809 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 7810 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7811 | }; |
| 7812 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 7813 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7814 | .rpc_message = &msg, |
| 7815 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 7816 | .callback_data = lrp, |
| 7817 | }; |
| 7818 | int status; |
| 7819 | |
| 7820 | dprintk("--> %s\n", __func__); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7821 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7822 | task = rpc_run_task(&task_setup_data); |
| 7823 | if (IS_ERR(task)) |
| 7824 | return PTR_ERR(task); |
| 7825 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7826 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7827 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7828 | rpc_put_task(task); |
| 7829 | return status; |
| 7830 | } |
| 7831 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7832 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7833 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7834 | struct pnfs_device *pdev, |
| 7835 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7836 | { |
| 7837 | struct nfs4_getdeviceinfo_args args = { |
| 7838 | .pdev = pdev, |
| 7839 | }; |
| 7840 | struct nfs4_getdeviceinfo_res res = { |
| 7841 | .pdev = pdev, |
| 7842 | }; |
| 7843 | struct rpc_message msg = { |
| 7844 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7845 | .rpc_argp = &args, |
| 7846 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7847 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7848 | }; |
| 7849 | int status; |
| 7850 | |
| 7851 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7852 | 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] | 7853 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7854 | |
| 7855 | return status; |
| 7856 | } |
| 7857 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7858 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7859 | struct pnfs_device *pdev, |
| 7860 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7861 | { |
| 7862 | struct nfs4_exception exception = { }; |
| 7863 | int err; |
| 7864 | |
| 7865 | do { |
| 7866 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7867 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7868 | &exception); |
| 7869 | } while (exception.retry); |
| 7870 | return err; |
| 7871 | } |
| 7872 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7873 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7874 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7875 | { |
| 7876 | struct nfs4_layoutcommit_data *data = calldata; |
| 7877 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7878 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7879 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7880 | nfs41_setup_sequence(session, |
| 7881 | &data->args.seq_args, |
| 7882 | &data->res.seq_res, |
| 7883 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7884 | } |
| 7885 | |
| 7886 | static void |
| 7887 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7888 | { |
| 7889 | struct nfs4_layoutcommit_data *data = calldata; |
| 7890 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7891 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7892 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7893 | return; |
| 7894 | |
| 7895 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7896 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7897 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7898 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7899 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7900 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7901 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7902 | break; |
| 7903 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 7904 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7905 | rpc_restart_call_prepare(task); |
| 7906 | return; |
| 7907 | } |
| 7908 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7909 | } |
| 7910 | |
| 7911 | static void nfs4_layoutcommit_release(void *calldata) |
| 7912 | { |
| 7913 | struct nfs4_layoutcommit_data *data = calldata; |
| 7914 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7915 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 7916 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7917 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7918 | put_rpccred(data->cred); |
| 7919 | kfree(data); |
| 7920 | } |
| 7921 | |
| 7922 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7923 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7924 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7925 | .rpc_release = nfs4_layoutcommit_release, |
| 7926 | }; |
| 7927 | |
| 7928 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7929 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7930 | { |
| 7931 | struct rpc_message msg = { |
| 7932 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7933 | .rpc_argp = &data->args, |
| 7934 | .rpc_resp = &data->res, |
| 7935 | .rpc_cred = data->cred, |
| 7936 | }; |
| 7937 | struct rpc_task_setup task_setup_data = { |
| 7938 | .task = &data->task, |
| 7939 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7940 | .rpc_message = &msg, |
| 7941 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7942 | .callback_data = data, |
| 7943 | .flags = RPC_TASK_ASYNC, |
| 7944 | }; |
| 7945 | struct rpc_task *task; |
| 7946 | int status = 0; |
| 7947 | |
| 7948 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7949 | "lbw: %llu inode %lu\n", |
| 7950 | data->task.tk_pid, sync, |
| 7951 | data->args.lastbytewritten, |
| 7952 | data->args.inode->i_ino); |
| 7953 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7954 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7955 | task = rpc_run_task(&task_setup_data); |
| 7956 | if (IS_ERR(task)) |
| 7957 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7958 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7959 | goto out; |
| 7960 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7961 | if (status != 0) |
| 7962 | goto out; |
| 7963 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7964 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7965 | out: |
| 7966 | dprintk("%s: status %d\n", __func__, status); |
| 7967 | rpc_put_task(task); |
| 7968 | return status; |
| 7969 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7970 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7971 | /** |
| 7972 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7973 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7974 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7975 | static int |
| 7976 | _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] | 7977 | struct nfs_fsinfo *info, |
| 7978 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7979 | { |
| 7980 | struct nfs41_secinfo_no_name_args args = { |
| 7981 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7982 | }; |
| 7983 | struct nfs4_secinfo_res res = { |
| 7984 | .flavors = flavors, |
| 7985 | }; |
| 7986 | struct rpc_message msg = { |
| 7987 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7988 | .rpc_argp = &args, |
| 7989 | .rpc_resp = &res, |
| 7990 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7991 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7992 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7993 | int status; |
| 7994 | |
| 7995 | if (use_integrity) { |
| 7996 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7997 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 7998 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7999 | } |
| 8000 | |
| 8001 | dprintk("--> %s\n", __func__); |
| 8002 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8003 | &res.seq_res, 0); |
| 8004 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8005 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8006 | if (cred) |
| 8007 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8008 | |
| 8009 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8010 | } |
| 8011 | |
| 8012 | static int |
| 8013 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8014 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8015 | { |
| 8016 | struct nfs4_exception exception = { }; |
| 8017 | int err; |
| 8018 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8019 | /* first try using integrity protection */ |
| 8020 | err = -NFS4ERR_WRONGSEC; |
| 8021 | |
| 8022 | /* try to use integrity protection with machine cred */ |
| 8023 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8024 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8025 | flavors, true); |
| 8026 | |
| 8027 | /* |
| 8028 | * if unable to use integrity protection, or SECINFO with |
| 8029 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8030 | * disallowed by spec, but exists in deployed servers) use |
| 8031 | * the current filesystem's rpc_client and the user cred. |
| 8032 | */ |
| 8033 | if (err == -NFS4ERR_WRONGSEC) |
| 8034 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8035 | flavors, false); |
| 8036 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8037 | switch (err) { |
| 8038 | case 0: |
| 8039 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8040 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8041 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8042 | default: |
| 8043 | err = nfs4_handle_exception(server, err, &exception); |
| 8044 | } |
| 8045 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8046 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8047 | return err; |
| 8048 | } |
| 8049 | |
| 8050 | static int |
| 8051 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8052 | struct nfs_fsinfo *info) |
| 8053 | { |
| 8054 | int err; |
| 8055 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8056 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8057 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8058 | struct nfs4_secinfo4 *secinfo; |
| 8059 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8060 | |
| 8061 | page = alloc_page(GFP_KERNEL); |
| 8062 | if (!page) { |
| 8063 | err = -ENOMEM; |
| 8064 | goto out; |
| 8065 | } |
| 8066 | |
| 8067 | flavors = page_address(page); |
| 8068 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8069 | |
| 8070 | /* |
| 8071 | * Fall back on "guess and check" method if |
| 8072 | * the server doesn't support SECINFO_NO_NAME |
| 8073 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8074 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8075 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8076 | goto out_freepage; |
| 8077 | } |
| 8078 | if (err) |
| 8079 | goto out_freepage; |
| 8080 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8081 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8082 | secinfo = &flavors->flavors[i]; |
| 8083 | |
| 8084 | switch (secinfo->flavor) { |
| 8085 | case RPC_AUTH_NULL: |
| 8086 | case RPC_AUTH_UNIX: |
| 8087 | case RPC_AUTH_GSS: |
| 8088 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8089 | &secinfo->flavor_info); |
| 8090 | break; |
| 8091 | default: |
| 8092 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8093 | break; |
| 8094 | } |
| 8095 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8096 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8097 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8098 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8099 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8100 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8101 | info, flavor); |
| 8102 | if (!err) |
| 8103 | break; |
| 8104 | } |
| 8105 | } |
| 8106 | |
| 8107 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8108 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8109 | |
| 8110 | out_freepage: |
| 8111 | put_page(page); |
| 8112 | if (err == -EACCES) |
| 8113 | return -EPERM; |
| 8114 | out: |
| 8115 | return err; |
| 8116 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8117 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8118 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8119 | nfs4_stateid *stateid, |
| 8120 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8121 | { |
| 8122 | int status; |
| 8123 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8124 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8125 | }; |
| 8126 | struct nfs41_test_stateid_res res; |
| 8127 | struct rpc_message msg = { |
| 8128 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8129 | .rpc_argp = &args, |
| 8130 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8131 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8132 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8133 | struct rpc_clnt *rpc_client = server->client; |
| 8134 | |
| 8135 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8136 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8137 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8138 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8139 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8140 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8141 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8142 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8143 | if (status != NFS_OK) { |
| 8144 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8145 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8146 | } |
| 8147 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8148 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8149 | } |
| 8150 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8151 | /** |
| 8152 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8153 | * |
| 8154 | * @server: server / transport on which to perform the operation |
| 8155 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8156 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8157 | * |
| 8158 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8159 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8160 | * failed or the state ID is not currently valid. |
| 8161 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8162 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8163 | nfs4_stateid *stateid, |
| 8164 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8165 | { |
| 8166 | struct nfs4_exception exception = { }; |
| 8167 | int err; |
| 8168 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8169 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8170 | if (err != -NFS4ERR_DELAY) |
| 8171 | break; |
| 8172 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8173 | } while (exception.retry); |
| 8174 | return err; |
| 8175 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8176 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8177 | struct nfs_free_stateid_data { |
| 8178 | struct nfs_server *server; |
| 8179 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8180 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8181 | }; |
| 8182 | |
| 8183 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8184 | { |
| 8185 | struct nfs_free_stateid_data *data = calldata; |
| 8186 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8187 | &data->args.seq_args, |
| 8188 | &data->res.seq_res, |
| 8189 | task); |
| 8190 | } |
| 8191 | |
| 8192 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8193 | { |
| 8194 | struct nfs_free_stateid_data *data = calldata; |
| 8195 | |
| 8196 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8197 | |
| 8198 | switch (task->tk_status) { |
| 8199 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame^] | 8200 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8201 | rpc_restart_call_prepare(task); |
| 8202 | } |
| 8203 | } |
| 8204 | |
| 8205 | static void nfs41_free_stateid_release(void *calldata) |
| 8206 | { |
| 8207 | kfree(calldata); |
| 8208 | } |
| 8209 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8210 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8211 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8212 | .rpc_call_done = nfs41_free_stateid_done, |
| 8213 | .rpc_release = nfs41_free_stateid_release, |
| 8214 | }; |
| 8215 | |
| 8216 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8217 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8218 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8219 | bool privileged) |
| 8220 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8221 | struct rpc_message msg = { |
| 8222 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8223 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8224 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8225 | struct rpc_task_setup task_setup = { |
| 8226 | .rpc_client = server->client, |
| 8227 | .rpc_message = &msg, |
| 8228 | .callback_ops = &nfs41_free_stateid_ops, |
| 8229 | .flags = RPC_TASK_ASYNC, |
| 8230 | }; |
| 8231 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8232 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8233 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8234 | &task_setup.rpc_client, &msg); |
| 8235 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8236 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8237 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8238 | if (!data) |
| 8239 | return ERR_PTR(-ENOMEM); |
| 8240 | data->server = server; |
| 8241 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8242 | |
| 8243 | task_setup.callback_data = data; |
| 8244 | |
| 8245 | msg.rpc_argp = &data->args; |
| 8246 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8247 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8248 | if (privileged) |
| 8249 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8250 | |
| 8251 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8252 | } |
| 8253 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8254 | /** |
| 8255 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8256 | * |
| 8257 | * @server: server / transport on which to perform the operation |
| 8258 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8259 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8260 | * |
| 8261 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8262 | * negative NFS4ERR value is returned. |
| 8263 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8264 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8265 | nfs4_stateid *stateid, |
| 8266 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8267 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8268 | struct rpc_task *task; |
| 8269 | int ret; |
| 8270 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8271 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8272 | if (IS_ERR(task)) |
| 8273 | return PTR_ERR(task); |
| 8274 | ret = rpc_wait_for_completion_task(task); |
| 8275 | if (!ret) |
| 8276 | ret = task->tk_status; |
| 8277 | rpc_put_task(task); |
| 8278 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8279 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8280 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8281 | static void |
| 8282 | 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] | 8283 | { |
| 8284 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8285 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8286 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8287 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8288 | nfs4_free_lock_state(server, lsp); |
| 8289 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8290 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8291 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8292 | } |
| 8293 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8294 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8295 | const nfs4_stateid *s2) |
| 8296 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8297 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8298 | return false; |
| 8299 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8300 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8301 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8302 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8303 | return true; |
| 8304 | |
| 8305 | return false; |
| 8306 | } |
| 8307 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8308 | #endif /* CONFIG_NFS_V4_1 */ |
| 8309 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8310 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8311 | const nfs4_stateid *s2) |
| 8312 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8313 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8314 | } |
| 8315 | |
| 8316 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8317 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8318 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8319 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8320 | .recover_open = nfs4_open_reclaim, |
| 8321 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8322 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8323 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8324 | }; |
| 8325 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8326 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8327 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8328 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8329 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8330 | .recover_open = nfs4_open_reclaim, |
| 8331 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8332 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8333 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8334 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8335 | }; |
| 8336 | #endif /* CONFIG_NFS_V4_1 */ |
| 8337 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8338 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8339 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8340 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8341 | .recover_open = nfs4_open_expired, |
| 8342 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8343 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8344 | }; |
| 8345 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8346 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8347 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8348 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8349 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8350 | .recover_open = nfs41_open_expired, |
| 8351 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8352 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8353 | }; |
| 8354 | #endif /* CONFIG_NFS_V4_1 */ |
| 8355 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8356 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8357 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8358 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8359 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8360 | }; |
| 8361 | |
| 8362 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8363 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8364 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8365 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8366 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8367 | }; |
| 8368 | #endif |
| 8369 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8370 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8371 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8372 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8373 | }; |
| 8374 | |
| 8375 | #if defined(CONFIG_NFS_V4_1) |
| 8376 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8377 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8378 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8379 | }; |
| 8380 | #endif /* CONFIG_NFS_V4_1 */ |
| 8381 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8382 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8383 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8384 | .init_caps = NFS_CAP_READDIRPLUS |
| 8385 | | NFS_CAP_ATOMIC_OPEN |
| 8386 | | NFS_CAP_CHANGE_ATTR |
| 8387 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8388 | .init_client = nfs40_init_client, |
| 8389 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8390 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8391 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8392 | .free_lock_state = nfs4_release_lockowner, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8393 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8394 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8395 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8396 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8397 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8398 | }; |
| 8399 | |
| 8400 | #if defined(CONFIG_NFS_V4_1) |
| 8401 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8402 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8403 | .init_caps = NFS_CAP_READDIRPLUS |
| 8404 | | NFS_CAP_ATOMIC_OPEN |
| 8405 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8406 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8407 | | NFS_CAP_STATEID_NFSV41 |
| 8408 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8409 | .init_client = nfs41_init_client, |
| 8410 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8411 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8412 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8413 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8414 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8415 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8416 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8417 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8418 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8419 | }; |
| 8420 | #endif |
| 8421 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8422 | #if defined(CONFIG_NFS_V4_2) |
| 8423 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8424 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8425 | .init_caps = NFS_CAP_READDIRPLUS |
| 8426 | | NFS_CAP_ATOMIC_OPEN |
| 8427 | | NFS_CAP_CHANGE_ATTR |
| 8428 | | NFS_CAP_POSIX_LOCK |
| 8429 | | NFS_CAP_STATEID_NFSV41 |
| 8430 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8431 | .init_client = nfs41_init_client, |
| 8432 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8433 | .match_stateid = nfs41_match_stateid, |
| 8434 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8435 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8436 | .call_sync_ops = &nfs41_call_sync_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8437 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8438 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8439 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 8440 | }; |
| 8441 | #endif |
| 8442 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8443 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8444 | [0] = &nfs_v4_0_minor_ops, |
| 8445 | #if defined(CONFIG_NFS_V4_1) |
| 8446 | [1] = &nfs_v4_1_minor_ops, |
| 8447 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8448 | #if defined(CONFIG_NFS_V4_2) |
| 8449 | [2] = &nfs_v4_2_minor_ops, |
| 8450 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8451 | }; |
| 8452 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8453 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8454 | .create = nfs_create, |
| 8455 | .lookup = nfs_lookup, |
| 8456 | .atomic_open = nfs_atomic_open, |
| 8457 | .link = nfs_link, |
| 8458 | .unlink = nfs_unlink, |
| 8459 | .symlink = nfs_symlink, |
| 8460 | .mkdir = nfs_mkdir, |
| 8461 | .rmdir = nfs_rmdir, |
| 8462 | .mknod = nfs_mknod, |
| 8463 | .rename = nfs_rename, |
| 8464 | .permission = nfs_permission, |
| 8465 | .getattr = nfs_getattr, |
| 8466 | .setattr = nfs_setattr, |
| 8467 | .getxattr = generic_getxattr, |
| 8468 | .setxattr = generic_setxattr, |
| 8469 | .listxattr = generic_listxattr, |
| 8470 | .removexattr = generic_removexattr, |
| 8471 | }; |
| 8472 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8473 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8474 | .permission = nfs_permission, |
| 8475 | .getattr = nfs_getattr, |
| 8476 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8477 | .getxattr = generic_getxattr, |
| 8478 | .setxattr = generic_setxattr, |
| 8479 | .listxattr = generic_listxattr, |
| 8480 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8481 | }; |
| 8482 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8483 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8484 | .version = 4, /* protocol version */ |
| 8485 | .dentry_ops = &nfs4_dentry_operations, |
| 8486 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8487 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8488 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8489 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8490 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8491 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8492 | .getattr = nfs4_proc_getattr, |
| 8493 | .setattr = nfs4_proc_setattr, |
| 8494 | .lookup = nfs4_proc_lookup, |
| 8495 | .access = nfs4_proc_access, |
| 8496 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8497 | .create = nfs4_proc_create, |
| 8498 | .remove = nfs4_proc_remove, |
| 8499 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8500 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8501 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8502 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8503 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8504 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8505 | .link = nfs4_proc_link, |
| 8506 | .symlink = nfs4_proc_symlink, |
| 8507 | .mkdir = nfs4_proc_mkdir, |
| 8508 | .rmdir = nfs4_proc_remove, |
| 8509 | .readdir = nfs4_proc_readdir, |
| 8510 | .mknod = nfs4_proc_mknod, |
| 8511 | .statfs = nfs4_proc_statfs, |
| 8512 | .fsinfo = nfs4_proc_fsinfo, |
| 8513 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8514 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8515 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8516 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8517 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8518 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8519 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8520 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8521 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8522 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8523 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8524 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8525 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8526 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8527 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8528 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8529 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8530 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8531 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8532 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8533 | .create_server = nfs4_create_server, |
| 8534 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8535 | }; |
| 8536 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8537 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 8538 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 8539 | .list = nfs4_xattr_list_nfs4_acl, |
| 8540 | .get = nfs4_xattr_get_nfs4_acl, |
| 8541 | .set = nfs4_xattr_set_nfs4_acl, |
| 8542 | }; |
| 8543 | |
| 8544 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8545 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8546 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8547 | &nfs4_xattr_nfs4_label_handler, |
| 8548 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8549 | NULL |
| 8550 | }; |
| 8551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8552 | /* |
| 8553 | * Local variables: |
| 8554 | * c-basic-offset: 8 |
| 8555 | * End: |
| 8556 | */ |