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 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 888 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 889 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 890 | struct rpc_message *msg, |
| 891 | struct nfs4_sequence_args *args, |
| 892 | struct nfs4_sequence_res *res, |
| 893 | int cache_reply) |
| 894 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 895 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 896 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
| 899 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 900 | { |
| 901 | struct nfs_inode *nfsi = NFS_I(dir); |
| 902 | |
| 903 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 904 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 905 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 907 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 908 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | spin_unlock(&dir->i_lock); |
| 910 | } |
| 911 | |
| 912 | struct nfs4_opendata { |
| 913 | struct kref kref; |
| 914 | struct nfs_openargs o_arg; |
| 915 | struct nfs_openres o_res; |
| 916 | struct nfs_open_confirmargs c_arg; |
| 917 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 918 | struct nfs4_string owner_name; |
| 919 | struct nfs4_string group_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 921 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 923 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | struct nfs4_state_owner *owner; |
| 925 | struct nfs4_state *state; |
| 926 | struct iattr attrs; |
| 927 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 928 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 929 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 930 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 931 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | int cancelled; |
| 933 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 934 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 935 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 936 | int err, struct nfs4_exception *exception) |
| 937 | { |
| 938 | if (err != -EINVAL) |
| 939 | return false; |
| 940 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 941 | return false; |
| 942 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 943 | exception->retry = 1; |
| 944 | return true; |
| 945 | } |
| 946 | |
| 947 | static enum open_claim_type4 |
| 948 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 949 | enum open_claim_type4 claim) |
| 950 | { |
| 951 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 952 | return claim; |
| 953 | switch (claim) { |
| 954 | default: |
| 955 | return claim; |
| 956 | case NFS4_OPEN_CLAIM_FH: |
| 957 | return NFS4_OPEN_CLAIM_NULL; |
| 958 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 959 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 960 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 961 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 962 | } |
| 963 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
| 965 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 966 | { |
| 967 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 968 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 969 | p->o_res.seqid = p->o_arg.seqid; |
| 970 | p->c_res.seqid = p->c_arg.seqid; |
| 971 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 972 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 973 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 974 | 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] | 975 | } |
| 976 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 977 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 978 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 979 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 980 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 981 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 982 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 983 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 984 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 985 | struct inode *dir = parent->d_inode; |
| 986 | struct nfs_server *server = NFS_SERVER(dir); |
| 987 | struct nfs4_opendata *p; |
| 988 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 989 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 990 | if (p == NULL) |
| 991 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 992 | |
| 993 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 994 | if (IS_ERR(p->f_label)) |
| 995 | goto err_free_p; |
| 996 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 997 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 998 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 999 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1000 | nfs_sb_active(dentry->d_sb); |
| 1001 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1002 | p->dir = parent; |
| 1003 | p->owner = sp; |
| 1004 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | p->o_arg.open_flags = flags; |
| 1006 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1007 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1008 | * will return permission denied for all bits until close */ |
| 1009 | if (!(flags & O_EXCL)) { |
| 1010 | /* ask server to check for all possible rights as results |
| 1011 | * are cached */ |
| 1012 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1013 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1014 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1015 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1016 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1017 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1018 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1019 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1020 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1021 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1022 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1023 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1024 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1025 | case NFS4_OPEN_CLAIM_NULL: |
| 1026 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1027 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1028 | p->o_arg.fh = NFS_FH(dir); |
| 1029 | break; |
| 1030 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1031 | case NFS4_OPEN_CLAIM_FH: |
| 1032 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1033 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1034 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 1035 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1036 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1037 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1038 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1039 | p->o_arg.u.attrs = &p->attrs; |
| 1040 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1041 | |
| 1042 | verf[0] = jiffies; |
| 1043 | verf[1] = current->pid; |
| 1044 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1045 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1046 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1047 | p->c_arg.fh = &p->o_res.fh; |
| 1048 | p->c_arg.stateid = &p->o_res.stateid; |
| 1049 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1050 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1051 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1052 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1053 | |
| 1054 | err_free_label: |
| 1055 | nfs4_label_free(p->f_label); |
| 1056 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1057 | kfree(p); |
| 1058 | err: |
| 1059 | dput(parent); |
| 1060 | return NULL; |
| 1061 | } |
| 1062 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1063 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1064 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1065 | struct nfs4_opendata *p = container_of(kref, |
| 1066 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1067 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1068 | |
| 1069 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1070 | if (p->state != NULL) |
| 1071 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1072 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1073 | |
| 1074 | nfs4_label_free(p->f_label); |
| 1075 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1076 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1077 | dput(p->dentry); |
| 1078 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1079 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1080 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1081 | kfree(p); |
| 1082 | } |
| 1083 | |
| 1084 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1085 | { |
| 1086 | if (p != NULL) |
| 1087 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1088 | } |
| 1089 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1090 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1091 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1092 | int ret; |
| 1093 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1094 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1095 | return ret; |
| 1096 | } |
| 1097 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1098 | 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] | 1099 | { |
| 1100 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1101 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1102 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1103 | goto out; |
| 1104 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1105 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1106 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1107 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1108 | break; |
| 1109 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1110 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1111 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1112 | break; |
| 1113 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1114 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1115 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1116 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1117 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1118 | return ret; |
| 1119 | } |
| 1120 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1121 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1122 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1123 | if (delegation == NULL) |
| 1124 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1125 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1126 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1127 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1128 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1129 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1130 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1131 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1132 | return 1; |
| 1133 | } |
| 1134 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1135 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1136 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1137 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1138 | case FMODE_WRITE: |
| 1139 | state->n_wronly++; |
| 1140 | break; |
| 1141 | case FMODE_READ: |
| 1142 | state->n_rdonly++; |
| 1143 | break; |
| 1144 | case FMODE_READ|FMODE_WRITE: |
| 1145 | state->n_rdwr++; |
| 1146 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1147 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1150 | 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] | 1151 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1152 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1153 | bool need_recover = false; |
| 1154 | |
| 1155 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1156 | need_recover = true; |
| 1157 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1158 | need_recover = true; |
| 1159 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1160 | need_recover = true; |
| 1161 | if (need_recover) |
| 1162 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1163 | } |
| 1164 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1165 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1166 | nfs4_stateid *stateid) |
| 1167 | { |
| 1168 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1169 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1170 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1171 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1172 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1173 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1174 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1175 | return true; |
| 1176 | return false; |
| 1177 | } |
| 1178 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1179 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1180 | nfs4_stateid *stateid, fmode_t fmode) |
| 1181 | { |
| 1182 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1183 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1184 | case FMODE_WRITE: |
| 1185 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1186 | break; |
| 1187 | case FMODE_READ: |
| 1188 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1189 | break; |
| 1190 | case 0: |
| 1191 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1192 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1193 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1194 | } |
| 1195 | if (stateid == NULL) |
| 1196 | return; |
| 1197 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1198 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1199 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1200 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1201 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | static void nfs_clear_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1205 | { |
| 1206 | write_seqlock(&state->seqlock); |
| 1207 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
| 1208 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1209 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1210 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1211 | } |
| 1212 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1213 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1214 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1215 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1216 | case FMODE_READ: |
| 1217 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1218 | break; |
| 1219 | case FMODE_WRITE: |
| 1220 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1221 | break; |
| 1222 | case FMODE_READ|FMODE_WRITE: |
| 1223 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1224 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1225 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1226 | return; |
| 1227 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1228 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1229 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1232 | 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] | 1233 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1234 | /* |
| 1235 | * Protect the call to nfs4_state_set_mode_locked and |
| 1236 | * serialise the stateid update |
| 1237 | */ |
| 1238 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1239 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1240 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1241 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1242 | } |
| 1243 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1244 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1245 | write_sequnlock(&state->seqlock); |
| 1246 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1247 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1248 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1251 | 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] | 1252 | { |
| 1253 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1254 | struct nfs_delegation *deleg_cur; |
| 1255 | int ret = 0; |
| 1256 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1257 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1258 | |
| 1259 | rcu_read_lock(); |
| 1260 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1261 | if (deleg_cur == NULL) |
| 1262 | goto no_delegation; |
| 1263 | |
| 1264 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1265 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1266 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1267 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1268 | goto no_delegation_unlock; |
| 1269 | |
| 1270 | if (delegation == NULL) |
| 1271 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1272 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1273 | goto no_delegation_unlock; |
| 1274 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1275 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1276 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1277 | ret = 1; |
| 1278 | no_delegation_unlock: |
| 1279 | spin_unlock(&deleg_cur->lock); |
| 1280 | no_delegation: |
| 1281 | rcu_read_unlock(); |
| 1282 | |
| 1283 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1284 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1285 | ret = 1; |
| 1286 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1287 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1288 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1289 | |
| 1290 | return ret; |
| 1291 | } |
| 1292 | |
| 1293 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1294 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1295 | { |
| 1296 | struct nfs_delegation *delegation; |
| 1297 | |
| 1298 | rcu_read_lock(); |
| 1299 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1300 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1301 | rcu_read_unlock(); |
| 1302 | return; |
| 1303 | } |
| 1304 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1305 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1306 | } |
| 1307 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1308 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1309 | { |
| 1310 | struct nfs4_state *state = opendata->state; |
| 1311 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1312 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1313 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1314 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1315 | nfs4_stateid stateid; |
| 1316 | int ret = -EAGAIN; |
| 1317 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1318 | for (;;) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1319 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1320 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1321 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1322 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1323 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1324 | } |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1325 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1326 | rcu_read_lock(); |
| 1327 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1328 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1329 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1330 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1331 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1332 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1333 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1334 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1335 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1336 | if (!opendata->is_recover) { |
| 1337 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1338 | if (ret != 0) |
| 1339 | goto out; |
| 1340 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1341 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1342 | |
| 1343 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1344 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1345 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1346 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1347 | out: |
| 1348 | return ERR_PTR(ret); |
| 1349 | out_return_state: |
| 1350 | atomic_inc(&state->count); |
| 1351 | return state; |
| 1352 | } |
| 1353 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1354 | static void |
| 1355 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1356 | { |
| 1357 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1358 | struct nfs_delegation *delegation; |
| 1359 | int delegation_flags = 0; |
| 1360 | |
| 1361 | rcu_read_lock(); |
| 1362 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1363 | if (delegation) |
| 1364 | delegation_flags = delegation->flags; |
| 1365 | rcu_read_unlock(); |
| 1366 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1367 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1368 | "returning a delegation for " |
| 1369 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1370 | clp->cl_hostname); |
| 1371 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1372 | nfs_inode_set_delegation(state->inode, |
| 1373 | data->owner->so_cred, |
| 1374 | &data->o_res); |
| 1375 | else |
| 1376 | nfs_inode_reclaim_delegation(state->inode, |
| 1377 | data->owner->so_cred, |
| 1378 | &data->o_res); |
| 1379 | } |
| 1380 | |
| 1381 | /* |
| 1382 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1383 | * and update the nfs4_state. |
| 1384 | */ |
| 1385 | static struct nfs4_state * |
| 1386 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1387 | { |
| 1388 | struct inode *inode = data->state->inode; |
| 1389 | struct nfs4_state *state = data->state; |
| 1390 | int ret; |
| 1391 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1392 | if (!data->rpc_done) { |
| 1393 | if (data->rpc_status) { |
| 1394 | ret = data->rpc_status; |
| 1395 | goto err; |
| 1396 | } |
| 1397 | /* cached opens have already been processed */ |
| 1398 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1399 | } |
| 1400 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1401 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1402 | if (ret) |
| 1403 | goto err; |
| 1404 | |
| 1405 | if (data->o_res.delegation_type != 0) |
| 1406 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1407 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1408 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1409 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1410 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1411 | |
| 1412 | return state; |
| 1413 | err: |
| 1414 | return ERR_PTR(ret); |
| 1415 | |
| 1416 | } |
| 1417 | |
| 1418 | static struct nfs4_state * |
| 1419 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1420 | { |
| 1421 | struct inode *inode; |
| 1422 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1423 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1424 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1425 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1426 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1427 | goto out; |
| 1428 | } |
| 1429 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1430 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1431 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1432 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1433 | 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] | 1434 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1435 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1436 | goto err; |
| 1437 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1438 | state = nfs4_get_open_state(inode, data->owner); |
| 1439 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1440 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1441 | if (data->o_res.delegation_type != 0) |
| 1442 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1443 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1444 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1445 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1446 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1447 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1448 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1449 | err_put_inode: |
| 1450 | iput(inode); |
| 1451 | err: |
| 1452 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1453 | } |
| 1454 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1455 | static struct nfs4_state * |
| 1456 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1457 | { |
| 1458 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1459 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1460 | return _nfs4_opendata_to_nfs4_state(data); |
| 1461 | } |
| 1462 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1463 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1464 | { |
| 1465 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1466 | struct nfs_open_context *ctx; |
| 1467 | |
| 1468 | spin_lock(&state->inode->i_lock); |
| 1469 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1470 | if (ctx->state != state) |
| 1471 | continue; |
| 1472 | get_nfs_open_context(ctx); |
| 1473 | spin_unlock(&state->inode->i_lock); |
| 1474 | return ctx; |
| 1475 | } |
| 1476 | spin_unlock(&state->inode->i_lock); |
| 1477 | return ERR_PTR(-ENOENT); |
| 1478 | } |
| 1479 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1480 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1481 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1482 | { |
| 1483 | struct nfs4_opendata *opendata; |
| 1484 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1485 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1486 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1487 | if (opendata == NULL) |
| 1488 | return ERR_PTR(-ENOMEM); |
| 1489 | opendata->state = state; |
| 1490 | atomic_inc(&state->count); |
| 1491 | return opendata; |
| 1492 | } |
| 1493 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1494 | 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] | 1495 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1496 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1497 | int ret; |
| 1498 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1499 | opendata->o_arg.open_flags = 0; |
| 1500 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1501 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1502 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1503 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1504 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1505 | if (ret != 0) |
| 1506 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1507 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1508 | if (IS_ERR(newstate)) |
| 1509 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1510 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1511 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1512 | return 0; |
| 1513 | } |
| 1514 | |
| 1515 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1516 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1517 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1518 | int ret; |
| 1519 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1520 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1521 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1522 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1523 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1524 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1525 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1526 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1527 | smp_rmb(); |
| 1528 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1529 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1530 | if (ret != 0) |
| 1531 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1532 | if (newstate != state) |
| 1533 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1534 | } |
| 1535 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1536 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1537 | if (ret != 0) |
| 1538 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1539 | if (newstate != state) |
| 1540 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1541 | } |
| 1542 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1543 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1544 | if (ret != 0) |
| 1545 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1546 | if (newstate != state) |
| 1547 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1548 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1549 | /* |
| 1550 | * We may have performed cached opens for all three recoveries. |
| 1551 | * Check if we need to update the current stateid. |
| 1552 | */ |
| 1553 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1554 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1555 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1556 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1557 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1558 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1559 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1560 | return 0; |
| 1561 | } |
| 1562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | /* |
| 1564 | * OPEN_RECLAIM: |
| 1565 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1567 | 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] | 1568 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1569 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1570 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1571 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | int status; |
| 1573 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1574 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1575 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1576 | if (IS_ERR(opendata)) |
| 1577 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1578 | rcu_read_lock(); |
| 1579 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1580 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1581 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1582 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1583 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1584 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1585 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | return status; |
| 1587 | } |
| 1588 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1589 | 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] | 1590 | { |
| 1591 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1592 | struct nfs4_exception exception = { }; |
| 1593 | int err; |
| 1594 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1595 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1596 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1597 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1598 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1599 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1600 | break; |
| 1601 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | } while (exception.retry); |
| 1603 | return err; |
| 1604 | } |
| 1605 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1606 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1607 | { |
| 1608 | struct nfs_open_context *ctx; |
| 1609 | int ret; |
| 1610 | |
| 1611 | ctx = nfs4_state_find_open_context(state); |
| 1612 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1613 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1614 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1615 | put_nfs_open_context(ctx); |
| 1616 | return ret; |
| 1617 | } |
| 1618 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1619 | 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] | 1620 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1621 | switch (err) { |
| 1622 | default: |
| 1623 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1624 | "%d.\n", __func__, err); |
| 1625 | case 0: |
| 1626 | case -ENOENT: |
| 1627 | case -ESTALE: |
| 1628 | break; |
| 1629 | case -NFS4ERR_BADSESSION: |
| 1630 | case -NFS4ERR_BADSLOT: |
| 1631 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1632 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1633 | case -NFS4ERR_DEADSESSION: |
| 1634 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1635 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1636 | return -EAGAIN; |
| 1637 | case -NFS4ERR_STALE_CLIENTID: |
| 1638 | case -NFS4ERR_STALE_STATEID: |
| 1639 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1640 | case -NFS4ERR_EXPIRED: |
| 1641 | /* Don't recall a delegation if it was lost */ |
| 1642 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1643 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1644 | case -NFS4ERR_MOVED: |
| 1645 | nfs4_schedule_migration_recovery(server); |
| 1646 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1647 | case -NFS4ERR_LEASE_MOVED: |
| 1648 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1649 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1650 | case -NFS4ERR_DELEG_REVOKED: |
| 1651 | case -NFS4ERR_ADMIN_REVOKED: |
| 1652 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1653 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1654 | nfs_inode_find_state_and_recover(state->inode, |
| 1655 | stateid); |
| 1656 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1657 | return 0; |
| 1658 | case -NFS4ERR_DELAY: |
| 1659 | case -NFS4ERR_GRACE: |
| 1660 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1661 | ssleep(1); |
| 1662 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1663 | case -ENOMEM: |
| 1664 | case -NFS4ERR_DENIED: |
| 1665 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1666 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | return err; |
| 1669 | } |
| 1670 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1671 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1672 | { |
| 1673 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1674 | struct nfs4_opendata *opendata; |
| 1675 | int err; |
| 1676 | |
| 1677 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1678 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1679 | if (IS_ERR(opendata)) |
| 1680 | return PTR_ERR(opendata); |
| 1681 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1682 | err = nfs4_open_recover(opendata, state); |
| 1683 | nfs4_opendata_put(opendata); |
| 1684 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1685 | } |
| 1686 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1687 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1688 | { |
| 1689 | struct nfs4_opendata *data = calldata; |
| 1690 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1691 | nfs40_setup_sequence(data->o_arg.server, &data->c_arg.seq_args, |
| 1692 | &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1695 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1696 | { |
| 1697 | struct nfs4_opendata *data = calldata; |
| 1698 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1699 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1700 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1701 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1702 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1703 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1704 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1705 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1706 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1707 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | static void nfs4_open_confirm_release(void *calldata) |
| 1711 | { |
| 1712 | struct nfs4_opendata *data = calldata; |
| 1713 | struct nfs4_state *state = NULL; |
| 1714 | |
| 1715 | /* If this request hasn't been cancelled, do nothing */ |
| 1716 | if (data->cancelled == 0) |
| 1717 | goto out_free; |
| 1718 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1719 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1720 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1721 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1722 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1723 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1724 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1725 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1729 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1730 | .rpc_call_done = nfs4_open_confirm_done, |
| 1731 | .rpc_release = nfs4_open_confirm_release, |
| 1732 | }; |
| 1733 | |
| 1734 | /* |
| 1735 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1736 | */ |
| 1737 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1738 | { |
| 1739 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1740 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1741 | struct rpc_message msg = { |
| 1742 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1743 | .rpc_argp = &data->c_arg, |
| 1744 | .rpc_resp = &data->c_res, |
| 1745 | .rpc_cred = data->owner->so_cred, |
| 1746 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1747 | struct rpc_task_setup task_setup_data = { |
| 1748 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1749 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1750 | .callback_ops = &nfs4_open_confirm_ops, |
| 1751 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1752 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1753 | .flags = RPC_TASK_ASYNC, |
| 1754 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | int status; |
| 1756 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1757 | 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] | 1758 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1759 | data->rpc_done = 0; |
| 1760 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1761 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1762 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1763 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1764 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1765 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1766 | if (status != 0) { |
| 1767 | data->cancelled = 1; |
| 1768 | smp_wmb(); |
| 1769 | } else |
| 1770 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1771 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | return status; |
| 1773 | } |
| 1774 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1775 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1777 | struct nfs4_opendata *data = calldata; |
| 1778 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1779 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1780 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1781 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1782 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1783 | /* |
| 1784 | * Check if we still need to send an OPEN call, or if we can use |
| 1785 | * a delegation instead. |
| 1786 | */ |
| 1787 | if (data->state != NULL) { |
| 1788 | struct nfs_delegation *delegation; |
| 1789 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1790 | 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] | 1791 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1792 | rcu_read_lock(); |
| 1793 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1794 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1795 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1796 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1797 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1798 | rcu_read_unlock(); |
| 1799 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1800 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1801 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1802 | switch (data->o_arg.claim) { |
| 1803 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1804 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1805 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1806 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1807 | case NFS4_OPEN_CLAIM_FH: |
| 1808 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1809 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1810 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1811 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1812 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1813 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1814 | &data->o_res.seq_res, |
| 1815 | task) != 0) |
| 1816 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1817 | |
| 1818 | /* Set the create mode (note dependency on the session type) */ |
| 1819 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1820 | if (data->o_arg.open_flags & O_EXCL) { |
| 1821 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1822 | if (nfs4_has_persistent_session(clp)) |
| 1823 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1824 | else if (clp->cl_mvops->minor_version > 0) |
| 1825 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1826 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1827 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1828 | unlock_no_action: |
| 1829 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1830 | out_no_action: |
| 1831 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1832 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1833 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1834 | } |
| 1835 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1836 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1837 | { |
| 1838 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1840 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1841 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1842 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1843 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1844 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1845 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1846 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1847 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1848 | case S_IFREG: |
| 1849 | break; |
| 1850 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1851 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1852 | break; |
| 1853 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1854 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1855 | break; |
| 1856 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1857 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1858 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1859 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1860 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1861 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1862 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1863 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1864 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1865 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1866 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1867 | static void nfs4_open_release(void *calldata) |
| 1868 | { |
| 1869 | struct nfs4_opendata *data = calldata; |
| 1870 | struct nfs4_state *state = NULL; |
| 1871 | |
| 1872 | /* If this request hasn't been cancelled, do nothing */ |
| 1873 | if (data->cancelled == 0) |
| 1874 | goto out_free; |
| 1875 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1876 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1877 | goto out_free; |
| 1878 | /* In case we need an open_confirm, no cleanup! */ |
| 1879 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1880 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1881 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1882 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1883 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1884 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1885 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1889 | .rpc_call_prepare = nfs4_open_prepare, |
| 1890 | .rpc_call_done = nfs4_open_done, |
| 1891 | .rpc_release = nfs4_open_release, |
| 1892 | }; |
| 1893 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1894 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1895 | { |
| 1896 | struct inode *dir = data->dir->d_inode; |
| 1897 | struct nfs_server *server = NFS_SERVER(dir); |
| 1898 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1899 | struct nfs_openres *o_res = &data->o_res; |
| 1900 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1901 | struct rpc_message msg = { |
| 1902 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1903 | .rpc_argp = o_arg, |
| 1904 | .rpc_resp = o_res, |
| 1905 | .rpc_cred = data->owner->so_cred, |
| 1906 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1907 | struct rpc_task_setup task_setup_data = { |
| 1908 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1909 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1910 | .callback_ops = &nfs4_open_ops, |
| 1911 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1912 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1913 | .flags = RPC_TASK_ASYNC, |
| 1914 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1915 | int status; |
| 1916 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1917 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1918 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1919 | data->rpc_done = 0; |
| 1920 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1921 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1922 | data->is_recover = 0; |
| 1923 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1924 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1925 | data->is_recover = 1; |
| 1926 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1927 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1928 | if (IS_ERR(task)) |
| 1929 | return PTR_ERR(task); |
| 1930 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1931 | if (status != 0) { |
| 1932 | data->cancelled = 1; |
| 1933 | smp_wmb(); |
| 1934 | } else |
| 1935 | status = data->rpc_status; |
| 1936 | rpc_put_task(task); |
| 1937 | |
| 1938 | return status; |
| 1939 | } |
| 1940 | |
| 1941 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1942 | { |
| 1943 | struct inode *dir = data->dir->d_inode; |
| 1944 | struct nfs_openres *o_res = &data->o_res; |
| 1945 | int status; |
| 1946 | |
| 1947 | status = nfs4_run_open_task(data, 1); |
| 1948 | if (status != 0 || !data->rpc_done) |
| 1949 | return status; |
| 1950 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1951 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1952 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1953 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1954 | status = _nfs4_proc_open_confirm(data); |
| 1955 | if (status != 0) |
| 1956 | return status; |
| 1957 | } |
| 1958 | |
| 1959 | return status; |
| 1960 | } |
| 1961 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1962 | /* |
| 1963 | * Additional permission checks in order to distinguish between an |
| 1964 | * open for read, and an open for execute. This works around the |
| 1965 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 1966 | * the same. |
| 1967 | * Note that in the non-execute case, we want to turn off permission |
| 1968 | * checking if we just created a new file (POSIX open() semantics). |
| 1969 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1970 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1971 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1972 | struct nfs4_state *state, fmode_t fmode, |
| 1973 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1974 | { |
| 1975 | struct nfs_access_entry cache; |
| 1976 | u32 mask; |
| 1977 | |
| 1978 | /* access call failed or for some reason the server doesn't |
| 1979 | * support any access modes -- defer access call until later */ |
| 1980 | if (opendata->o_res.access_supported == 0) |
| 1981 | return 0; |
| 1982 | |
| 1983 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1984 | /* |
| 1985 | * Use openflags to check for exec, because fmode won't |
| 1986 | * always have FMODE_EXEC set when file open for exec. |
| 1987 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1988 | if (openflags & __FMODE_EXEC) { |
| 1989 | /* ONLY check for exec rights */ |
| 1990 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 1991 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1992 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1993 | |
| 1994 | cache.cred = cred; |
| 1995 | cache.jiffies = jiffies; |
| 1996 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1997 | nfs_access_add_cache(state->inode, &cache); |
| 1998 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1999 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2000 | return 0; |
| 2001 | |
| 2002 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2003 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2004 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2005 | } |
| 2006 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2007 | /* |
| 2008 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2009 | */ |
| 2010 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2011 | { |
| 2012 | struct inode *dir = data->dir->d_inode; |
| 2013 | struct nfs_server *server = NFS_SERVER(dir); |
| 2014 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2015 | struct nfs_openres *o_res = &data->o_res; |
| 2016 | int status; |
| 2017 | |
| 2018 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2019 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2020 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2021 | if (status != 0) { |
| 2022 | if (status == -NFS4ERR_BADNAME && |
| 2023 | !(o_arg->open_flags & O_CREAT)) |
| 2024 | return -ENOENT; |
| 2025 | return status; |
| 2026 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2027 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2028 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2029 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2030 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2031 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2032 | if (o_arg->open_flags & O_EXCL) |
| 2033 | data->file_created = 1; |
| 2034 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2035 | data->file_created = 1; |
| 2036 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2037 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2038 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2040 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2042 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | } |
| 2044 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2045 | 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] | 2046 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2049 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2050 | { |
| 2051 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2052 | } |
| 2053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | /* |
| 2055 | * OPEN_EXPIRED: |
| 2056 | * reclaim state on the server after a network partition. |
| 2057 | * Assumes caller holds the appropriate lock |
| 2058 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2059 | 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] | 2060 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2061 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2062 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2064 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2065 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2066 | if (IS_ERR(opendata)) |
| 2067 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2068 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2069 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2070 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2071 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2072 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2075 | 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] | 2076 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2077 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2078 | struct nfs4_exception exception = { }; |
| 2079 | int err; |
| 2080 | |
| 2081 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2082 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2083 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2084 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2085 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2086 | switch (err) { |
| 2087 | default: |
| 2088 | goto out; |
| 2089 | case -NFS4ERR_GRACE: |
| 2090 | case -NFS4ERR_DELAY: |
| 2091 | nfs4_handle_exception(server, err, &exception); |
| 2092 | err = 0; |
| 2093 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2094 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2095 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2096 | return err; |
| 2097 | } |
| 2098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2100 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2102 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2104 | ctx = nfs4_state_find_open_context(state); |
| 2105 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2106 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2107 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2108 | put_nfs_open_context(ctx); |
| 2109 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2112 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2113 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2114 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2115 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2116 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2117 | struct nfs_delegation *delegation; |
| 2118 | struct rpc_cred *cred = NULL; |
| 2119 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2120 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2121 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2122 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 2123 | return; |
| 2124 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2125 | /* Get the delegation credential for use by test/free_stateid */ |
| 2126 | rcu_read_lock(); |
| 2127 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 2128 | if (delegation != NULL && |
| 2129 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 2130 | cred = get_rpccred(delegation->cred); |
| 2131 | rcu_read_unlock(); |
| 2132 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2133 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2134 | } else |
| 2135 | rcu_read_unlock(); |
| 2136 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2137 | if (status != NFS_OK) { |
| 2138 | /* Free the stateid unless the server explicitly |
| 2139 | * informs us the stateid is unrecognized. */ |
| 2140 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2141 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2142 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2143 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2144 | write_seqlock(&state->seqlock); |
| 2145 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2146 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2147 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2148 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2149 | |
| 2150 | if (cred != NULL) |
| 2151 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | /** |
| 2155 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2156 | * |
| 2157 | * @state: NFSv4 state for an inode |
| 2158 | * |
| 2159 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2160 | * Otherwise a negative NFS4ERR value is returned. |
| 2161 | */ |
| 2162 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2163 | { |
| 2164 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2165 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2166 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2167 | int status; |
| 2168 | |
| 2169 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2170 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2171 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2172 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2173 | return -NFS4ERR_BAD_STATEID; |
| 2174 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2175 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2176 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2177 | if (status != NFS_OK) { |
| 2178 | /* Free the stateid unless the server explicitly |
| 2179 | * informs us the stateid is unrecognized. */ |
| 2180 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2181 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2182 | |
| 2183 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2184 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2185 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2186 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2187 | } |
| 2188 | return status; |
| 2189 | } |
| 2190 | |
| 2191 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2192 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2193 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2194 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2195 | nfs41_clear_delegation_stateid(state); |
| 2196 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2197 | if (status != NFS_OK) |
| 2198 | status = nfs4_open_expired(sp, state); |
| 2199 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2200 | } |
| 2201 | #endif |
| 2202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2204 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2205 | * fields corresponding to attributes that were used to store the verifier. |
| 2206 | * Make sure we clobber those fields in the later setattr call |
| 2207 | */ |
| 2208 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2209 | { |
| 2210 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2211 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2212 | sattr->ia_valid |= ATTR_ATIME; |
| 2213 | |
| 2214 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2215 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2216 | sattr->ia_valid |= ATTR_MTIME; |
| 2217 | } |
| 2218 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2219 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2220 | fmode_t fmode, |
| 2221 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2222 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2223 | { |
| 2224 | struct nfs4_state_owner *sp = opendata->owner; |
| 2225 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2226 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2227 | struct nfs4_state *state; |
| 2228 | unsigned int seq; |
| 2229 | int ret; |
| 2230 | |
| 2231 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2232 | |
| 2233 | ret = _nfs4_proc_open(opendata); |
NeilBrown | 4fa2c54 | 2014-07-21 13:28:28 +1000 | [diff] [blame] | 2234 | if (ret != 0) { |
| 2235 | if (ret == -ENOENT) { |
NeilBrown | f39c010 | 2014-09-11 16:19:37 +1000 | [diff] [blame] | 2236 | dentry = opendata->dentry; |
| 2237 | if (dentry->d_inode) |
| 2238 | d_delete(dentry); |
| 2239 | else if (d_unhashed(dentry)) |
| 2240 | d_add(dentry, NULL); |
| 2241 | |
| 2242 | nfs_set_verifier(dentry, |
NeilBrown | 4fa2c54 | 2014-07-21 13:28:28 +1000 | [diff] [blame] | 2243 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2244 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2245 | goto out; |
NeilBrown | 4fa2c54 | 2014-07-21 13:28:28 +1000 | [diff] [blame] | 2246 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2247 | |
| 2248 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2249 | ret = PTR_ERR(state); |
| 2250 | if (IS_ERR(state)) |
| 2251 | goto out; |
| 2252 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2253 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2254 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2255 | dentry = opendata->dentry; |
| 2256 | if (dentry->d_inode == NULL) { |
| 2257 | /* FIXME: Is this d_drop() ever needed? */ |
| 2258 | d_drop(dentry); |
| 2259 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2260 | if (dentry == NULL) { |
| 2261 | dentry = opendata->dentry; |
| 2262 | } else if (dentry != ctx->dentry) { |
| 2263 | dput(ctx->dentry); |
| 2264 | ctx->dentry = dget(dentry); |
| 2265 | } |
| 2266 | nfs_set_verifier(dentry, |
| 2267 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2268 | } |
| 2269 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2270 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2271 | if (ret != 0) |
| 2272 | goto out; |
| 2273 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2274 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2275 | if (dentry->d_inode == state->inode) { |
| 2276 | nfs_inode_attach_open_context(ctx); |
| 2277 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2278 | nfs4_schedule_stateid_recovery(server, state); |
| 2279 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2280 | out: |
| 2281 | return ret; |
| 2282 | } |
| 2283 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2284 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2285 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2287 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2288 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2289 | int flags, |
| 2290 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2291 | struct nfs4_label *label, |
| 2292 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | { |
| 2294 | struct nfs4_state_owner *sp; |
| 2295 | struct nfs4_state *state = NULL; |
| 2296 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2297 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2298 | struct dentry *dentry = ctx->dentry; |
| 2299 | struct rpc_cred *cred = ctx->cred; |
| 2300 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2301 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2302 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2303 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2304 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | |
| 2306 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2308 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2309 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2311 | goto out_err; |
| 2312 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2313 | status = nfs4_recover_expired_lease(server); |
| 2314 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2315 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2316 | if (dentry->d_inode != NULL) |
| 2317 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2318 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2319 | if (dentry->d_inode) |
| 2320 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2321 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2322 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2323 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2324 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2326 | if (label) { |
| 2327 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2328 | if (IS_ERR(olabel)) { |
| 2329 | status = PTR_ERR(olabel); |
| 2330 | goto err_opendata_put; |
| 2331 | } |
| 2332 | } |
| 2333 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2334 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2335 | if (!opendata->f_attr.mdsthreshold) { |
| 2336 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2337 | if (!opendata->f_attr.mdsthreshold) |
| 2338 | goto err_free_label; |
| 2339 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2340 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2341 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2342 | if (dentry->d_inode != NULL) |
| 2343 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2344 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2345 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2346 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2347 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2348 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2349 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2350 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2351 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2352 | nfs4_exclusive_attrset(opendata, sattr); |
| 2353 | |
| 2354 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2355 | status = nfs4_do_setattr(state->inode, cred, |
| 2356 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2357 | state, label, olabel); |
| 2358 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2359 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2360 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2361 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2362 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2363 | } |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2364 | if (opendata->file_created) |
| 2365 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2366 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2367 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2368 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2369 | opendata->f_attr.mdsthreshold = NULL; |
| 2370 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2371 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2372 | nfs4_label_free(olabel); |
| 2373 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2374 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2377 | err_free_label: |
| 2378 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2379 | err_opendata_put: |
| 2380 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2381 | err_put_state_owner: |
| 2382 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | return status; |
| 2385 | } |
| 2386 | |
| 2387 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2388 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2389 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2390 | int flags, |
| 2391 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2392 | struct nfs4_label *label, |
| 2393 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2395 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | struct nfs4_exception exception = { }; |
| 2397 | struct nfs4_state *res; |
| 2398 | int status; |
| 2399 | |
| 2400 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2401 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2402 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2403 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | if (status == 0) |
| 2405 | break; |
| 2406 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2407 | * book-keeping w.r.t. state-changing operations |
| 2408 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2409 | * It is actually a sign of a bug on the client or on the server. |
| 2410 | * |
| 2411 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2412 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | * have unhashed the old state_owner for us, and that we can |
| 2414 | * therefore safely retry using a new one. We should still warn |
| 2415 | * the user though... |
| 2416 | */ |
| 2417 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2418 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2419 | " returned a bad sequence-id error!\n", |
| 2420 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | exception.retry = 1; |
| 2422 | continue; |
| 2423 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2424 | /* |
| 2425 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2426 | * state before it received the OPEN_CONFIRM. |
| 2427 | * Recover by retrying the request as per the discussion |
| 2428 | * on Page 181 of RFC3530. |
| 2429 | */ |
| 2430 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2431 | exception.retry = 1; |
| 2432 | continue; |
| 2433 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2434 | if (status == -EAGAIN) { |
| 2435 | /* We must have found a delegation */ |
| 2436 | exception.retry = 1; |
| 2437 | continue; |
| 2438 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2439 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2440 | continue; |
| 2441 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | status, &exception)); |
| 2443 | } while (exception.retry); |
| 2444 | return res; |
| 2445 | } |
| 2446 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2447 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2448 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2449 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2450 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2452 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2454 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | .iap = sattr, |
| 2456 | .server = server, |
| 2457 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2458 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | }; |
| 2460 | struct nfs_setattrres res = { |
| 2461 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2462 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | .server = server, |
| 2464 | }; |
| 2465 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2466 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2467 | .rpc_argp = &arg, |
| 2468 | .rpc_resp = &res, |
| 2469 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2471 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2472 | fmode_t fmode; |
| 2473 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2474 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2476 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2477 | if (ilabel) |
| 2478 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2479 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2480 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2482 | /* Servers should only apply open mode checks for file size changes */ |
| 2483 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2484 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2485 | |
| 2486 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2487 | /* Use that stateid */ |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2488 | } else if (truncate && state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2489 | struct nfs_lockowner lockowner = { |
| 2490 | .l_owner = current->files, |
| 2491 | .l_pid = current->tgid, |
| 2492 | }; |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2493 | if (!nfs4_valid_open_stateid(state)) |
| 2494 | return -EBADF; |
| 2495 | if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2496 | &lockowner) == -EIO) |
| 2497 | return -EBADF; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2498 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2499 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2501 | 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] | 2502 | if (status == 0 && state != NULL) |
| 2503 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2504 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2507 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2508 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2509 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2510 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2512 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2513 | struct nfs4_exception exception = { |
| 2514 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2515 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2516 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | int err; |
| 2518 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2519 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2520 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2521 | switch (err) { |
| 2522 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2523 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2524 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2525 | "applying open mode checks to " |
| 2526 | "a SETATTR that is not " |
| 2527 | "changing file size.\n", |
| 2528 | server->nfs_client->cl_hostname); |
| 2529 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2530 | if (state && !(state->state & FMODE_WRITE)) { |
| 2531 | err = -EBADF; |
| 2532 | if (sattr->ia_valid & ATTR_OPEN) |
| 2533 | err = -EACCES; |
| 2534 | goto out; |
| 2535 | } |
| 2536 | } |
| 2537 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2539 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | return err; |
| 2541 | } |
| 2542 | |
| 2543 | struct nfs4_closedata { |
| 2544 | struct inode *inode; |
| 2545 | struct nfs4_state *state; |
| 2546 | struct nfs_closeargs arg; |
| 2547 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2548 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2549 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2550 | bool roc; |
| 2551 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | }; |
| 2553 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2554 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2555 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2556 | struct nfs4_closedata *calldata = data; |
| 2557 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2558 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2559 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2560 | if (calldata->roc) |
| 2561 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2562 | nfs4_put_open_state(calldata->state); |
| 2563 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2564 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2565 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2566 | kfree(calldata); |
| 2567 | } |
| 2568 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2569 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2571 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2574 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2576 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2577 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2578 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2579 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | /* hmm. we are done with the inode, and in the process of freeing |
| 2581 | * the state_owner. we keep this around to process errors |
| 2582 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | switch (task->tk_status) { |
| 2584 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2585 | res_stateid = &calldata->res.stateid; |
| 2586 | if (calldata->arg.fmode == 0 && calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2587 | pnfs_roc_set_barrier(state->inode, |
| 2588 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2589 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2590 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2591 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2593 | case -NFS4ERR_OLD_STATEID: |
| 2594 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2596 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2597 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2599 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2600 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2601 | goto out_release; |
| 2602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | } |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2604 | nfs_clear_open_stateid(state, res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2605 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2606 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2607 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2608 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2611 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2613 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2614 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2615 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2616 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2617 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2618 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2619 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2620 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2621 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2622 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2623 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2624 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2625 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2626 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2627 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2628 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2629 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2630 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2631 | if (state->n_rdonly == 0) |
| 2632 | call_close |= is_rdonly; |
| 2633 | else if (is_rdonly) |
| 2634 | calldata->arg.fmode |= FMODE_READ; |
| 2635 | if (state->n_wronly == 0) |
| 2636 | call_close |= is_wronly; |
| 2637 | else if (is_wronly) |
| 2638 | calldata->arg.fmode |= FMODE_WRITE; |
| 2639 | } else if (is_rdwr) |
| 2640 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2641 | |
| 2642 | if (calldata->arg.fmode == 0) |
| 2643 | call_close |= is_rdwr; |
| 2644 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2645 | if (!nfs4_valid_open_stateid(state)) |
| 2646 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2647 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2648 | |
| 2649 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2650 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2651 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2652 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2653 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2654 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2655 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2656 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2657 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2658 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2659 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2660 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2661 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2662 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2663 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2664 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2665 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2666 | &calldata->arg.seq_args, |
| 2667 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2668 | task) != 0) |
| 2669 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2670 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2671 | return; |
| 2672 | out_no_action: |
| 2673 | task->tk_action = NULL; |
| 2674 | out_wait: |
| 2675 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2678 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2679 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2680 | .rpc_call_done = nfs4_close_done, |
| 2681 | .rpc_release = nfs4_free_closedata, |
| 2682 | }; |
| 2683 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2684 | static bool nfs4_state_has_opener(struct nfs4_state *state) |
| 2685 | { |
| 2686 | /* first check existing openers */ |
| 2687 | if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 && |
| 2688 | state->n_rdonly != 0) |
| 2689 | return true; |
| 2690 | |
| 2691 | if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 && |
| 2692 | state->n_wronly != 0) |
| 2693 | return true; |
| 2694 | |
| 2695 | if (test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 && |
| 2696 | state->n_rdwr != 0) |
| 2697 | return true; |
| 2698 | |
| 2699 | return false; |
| 2700 | } |
| 2701 | |
| 2702 | static bool nfs4_roc(struct inode *inode) |
| 2703 | { |
| 2704 | struct nfs_inode *nfsi = NFS_I(inode); |
| 2705 | struct nfs_open_context *ctx; |
| 2706 | struct nfs4_state *state; |
| 2707 | |
| 2708 | spin_lock(&inode->i_lock); |
| 2709 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 2710 | state = ctx->state; |
| 2711 | if (state == NULL) |
| 2712 | continue; |
| 2713 | if (nfs4_state_has_opener(state)) { |
| 2714 | spin_unlock(&inode->i_lock); |
| 2715 | return false; |
| 2716 | } |
| 2717 | } |
| 2718 | spin_unlock(&inode->i_lock); |
| 2719 | |
| 2720 | if (nfs4_check_delegation(inode, FMODE_READ)) |
| 2721 | return false; |
| 2722 | |
| 2723 | return pnfs_roc(inode); |
| 2724 | } |
| 2725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | /* |
| 2727 | * It is possible for data to be read/written from a mem-mapped file |
| 2728 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2729 | * This means that we can't safely call nfsv4 close on a file until |
| 2730 | * the inode is cleared. This in turn means that we are not good |
| 2731 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2732 | * share state even when we are done with one of the three share |
| 2733 | * stateid's in the inode. |
| 2734 | * |
| 2735 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2736 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2737 | 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] | 2738 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2739 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2741 | struct nfs4_state_owner *sp = state->owner; |
| 2742 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2743 | struct rpc_message msg = { |
| 2744 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2745 | .rpc_cred = state->owner->so_cred, |
| 2746 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2747 | struct rpc_task_setup task_setup_data = { |
| 2748 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2749 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2750 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2751 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2752 | .flags = RPC_TASK_ASYNC, |
| 2753 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2754 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2756 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2757 | &task_setup_data.rpc_client, &msg); |
| 2758 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2759 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2761 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2762 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2763 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2765 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2766 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2768 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2769 | if (calldata->arg.seqid == NULL) |
| 2770 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2771 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2772 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2773 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2774 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2775 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2776 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2777 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2778 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2779 | msg.rpc_argp = &calldata->arg; |
| 2780 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2781 | task_setup_data.callback_data = calldata; |
| 2782 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2783 | if (IS_ERR(task)) |
| 2784 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2785 | status = 0; |
| 2786 | if (wait) |
| 2787 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2788 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2789 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2790 | out_free_calldata: |
| 2791 | kfree(calldata); |
| 2792 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2793 | nfs4_put_open_state(state); |
| 2794 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2795 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | } |
| 2797 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2798 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2799 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 2800 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2803 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2804 | |
| 2805 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2807 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2808 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2809 | |
| 2810 | nfs4_label_release_security(label); |
| 2811 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2812 | if (IS_ERR(state)) |
| 2813 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2814 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2817 | 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] | 2818 | { |
| 2819 | if (ctx->state == NULL) |
| 2820 | return; |
| 2821 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2822 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2823 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2824 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2825 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2827 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 2828 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 2829 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2832 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2833 | struct nfs4_server_caps_arg args = { |
| 2834 | .fhandle = fhandle, |
| 2835 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | struct nfs4_server_caps_res res = {}; |
| 2837 | struct rpc_message msg = { |
| 2838 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2839 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | .rpc_resp = &res, |
| 2841 | }; |
| 2842 | int status; |
| 2843 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2844 | 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] | 2845 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2846 | /* Sanity check the server answers */ |
| 2847 | switch (server->nfs_client->cl_minorversion) { |
| 2848 | case 0: |
| 2849 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 2850 | res.attr_bitmask[2] = 0; |
| 2851 | break; |
| 2852 | case 1: |
| 2853 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 2854 | break; |
| 2855 | case 2: |
| 2856 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 2857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2859 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2860 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2861 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2862 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2863 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 2864 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 2865 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 2866 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | server->caps |= NFS_CAP_ACLS; |
| 2868 | if (res.has_links != 0) |
| 2869 | server->caps |= NFS_CAP_HARDLINKS; |
| 2870 | if (res.has_symlinks != 0) |
| 2871 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2872 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2873 | server->caps |= NFS_CAP_FILEID; |
| 2874 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2875 | server->caps |= NFS_CAP_MODE; |
| 2876 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2877 | server->caps |= NFS_CAP_NLINK; |
| 2878 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2879 | server->caps |= NFS_CAP_OWNER; |
| 2880 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2881 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2882 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2883 | server->caps |= NFS_CAP_ATIME; |
| 2884 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2885 | server->caps |= NFS_CAP_CTIME; |
| 2886 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2887 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2888 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2889 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2890 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2891 | #endif |
| 2892 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2893 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2894 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2895 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2896 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2897 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2898 | 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] | 2899 | server->cache_consistency_bitmask[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2901 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | return status; |
| 2905 | } |
| 2906 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2907 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | { |
| 2909 | struct nfs4_exception exception = { }; |
| 2910 | int err; |
| 2911 | do { |
| 2912 | err = nfs4_handle_exception(server, |
| 2913 | _nfs4_server_capabilities(server, fhandle), |
| 2914 | &exception); |
| 2915 | } while (exception.retry); |
| 2916 | return err; |
| 2917 | } |
| 2918 | |
| 2919 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2920 | struct nfs_fsinfo *info) |
| 2921 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2922 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2924 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | }; |
| 2926 | struct nfs4_lookup_res res = { |
| 2927 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2928 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | .fh = fhandle, |
| 2930 | }; |
| 2931 | struct rpc_message msg = { |
| 2932 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2933 | .rpc_argp = &args, |
| 2934 | .rpc_resp = &res, |
| 2935 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2936 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2937 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2938 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2939 | /* |
| 2940 | * Process the label in the upcoming getfattr |
| 2941 | */ |
| 2942 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2943 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2944 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2945 | 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] | 2946 | } |
| 2947 | |
| 2948 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2949 | struct nfs_fsinfo *info) |
| 2950 | { |
| 2951 | struct nfs4_exception exception = { }; |
| 2952 | int err; |
| 2953 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2954 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2955 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2956 | switch (err) { |
| 2957 | case 0: |
| 2958 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2959 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2960 | default: |
| 2961 | err = nfs4_handle_exception(server, err, &exception); |
| 2962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2964 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | return err; |
| 2966 | } |
| 2967 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2968 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2969 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2970 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2971 | struct rpc_auth_create_args auth_args = { |
| 2972 | .pseudoflavor = flavor, |
| 2973 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2974 | struct rpc_auth *auth; |
| 2975 | int ret; |
| 2976 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2977 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2978 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2979 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2980 | goto out; |
| 2981 | } |
| 2982 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2983 | out: |
| 2984 | return ret; |
| 2985 | } |
| 2986 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2987 | /* |
| 2988 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2989 | * |
| 2990 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2991 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2992 | * |
| 2993 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2994 | * negative errno value. |
| 2995 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2996 | 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] | 2997 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2999 | /* Per 3530bis 15.33.5 */ |
| 3000 | static const rpc_authflavor_t flav_array[] = { |
| 3001 | RPC_AUTH_GSS_KRB5P, |
| 3002 | RPC_AUTH_GSS_KRB5I, |
| 3003 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3004 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3005 | RPC_AUTH_NULL, |
| 3006 | }; |
| 3007 | int status = -EPERM; |
| 3008 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3010 | if (server->auth_info.flavor_len > 0) { |
| 3011 | /* try each flavor specified by user */ |
| 3012 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3013 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3014 | server->auth_info.flavors[i]); |
| 3015 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3016 | continue; |
| 3017 | break; |
| 3018 | } |
| 3019 | } else { |
| 3020 | /* no flavors specified by user, try default list */ |
| 3021 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3022 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3023 | flav_array[i]); |
| 3024 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3025 | continue; |
| 3026 | break; |
| 3027 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3028 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3029 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3030 | /* |
| 3031 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3032 | * to access the mount. It could also mean that we tried to mount |
| 3033 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3034 | * existing mount programs don't handle -EACCES very well so it should |
| 3035 | * be mapped to -EPERM instead. |
| 3036 | */ |
| 3037 | if (status == -EACCES) |
| 3038 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3039 | return status; |
| 3040 | } |
| 3041 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3042 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 3043 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 3044 | { |
| 3045 | int mv = server->nfs_client->cl_minorversion; |
| 3046 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 3047 | } |
| 3048 | |
| 3049 | /** |
| 3050 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3051 | * @server: initialized nfs_server handle |
| 3052 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3053 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3054 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3055 | * |
| 3056 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3057 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3058 | 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] | 3059 | struct nfs_fsinfo *info, |
| 3060 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3061 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3062 | int status; |
| 3063 | |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3064 | switch (auth_probe) { |
| 3065 | case false: |
| 3066 | status = nfs4_lookup_root(server, fhandle, info); |
| 3067 | if (status != -NFS4ERR_WRONGSEC) |
| 3068 | break; |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3069 | default: |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3070 | status = nfs4_do_find_root_sec(server, fhandle, info); |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3071 | } |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | if (status == 0) |
| 3074 | status = nfs4_server_capabilities(server, fhandle); |
| 3075 | if (status == 0) |
| 3076 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3077 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3078 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3081 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3082 | struct nfs_fsinfo *info) |
| 3083 | { |
| 3084 | int error; |
| 3085 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3086 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3087 | |
| 3088 | error = nfs4_server_capabilities(server, mntfh); |
| 3089 | if (error < 0) { |
| 3090 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3091 | return error; |
| 3092 | } |
| 3093 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3094 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3095 | if (IS_ERR(label)) |
| 3096 | return PTR_ERR(label); |
| 3097 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3098 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3099 | if (error < 0) { |
| 3100 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3101 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3105 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3106 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3107 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3108 | err_free_label: |
| 3109 | nfs4_label_free(label); |
| 3110 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3111 | return error; |
| 3112 | } |
| 3113 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3114 | /* |
| 3115 | * Get locations and (maybe) other attributes of a referral. |
| 3116 | * Note that we'll actually follow the referral later when |
| 3117 | * we detect fsid mismatch in inode revalidation |
| 3118 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3119 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3120 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3121 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3122 | { |
| 3123 | int status = -ENOMEM; |
| 3124 | struct page *page = NULL; |
| 3125 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3126 | |
| 3127 | page = alloc_page(GFP_KERNEL); |
| 3128 | if (page == NULL) |
| 3129 | goto out; |
| 3130 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3131 | if (locations == NULL) |
| 3132 | goto out; |
| 3133 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3134 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3135 | if (status != 0) |
| 3136 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3137 | |
| 3138 | /* |
| 3139 | * If the fsid didn't change, this is a migration event, not a |
| 3140 | * referral. Cause us to drop into the exception handler, which |
| 3141 | * will kick off migration recovery. |
| 3142 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3143 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3144 | dprintk("%s: server did not return a different fsid for" |
| 3145 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3146 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3147 | goto out; |
| 3148 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3149 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3150 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3151 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3152 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3153 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3154 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3155 | out: |
| 3156 | if (page) |
| 3157 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3158 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3159 | return status; |
| 3160 | } |
| 3161 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3162 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3163 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | { |
| 3165 | struct nfs4_getattr_arg args = { |
| 3166 | .fh = fhandle, |
| 3167 | .bitmask = server->attr_bitmask, |
| 3168 | }; |
| 3169 | struct nfs4_getattr_res res = { |
| 3170 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3171 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | .server = server, |
| 3173 | }; |
| 3174 | struct rpc_message msg = { |
| 3175 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3176 | .rpc_argp = &args, |
| 3177 | .rpc_resp = &res, |
| 3178 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3179 | |
| 3180 | args.bitmask = nfs4_bitmask(server, label); |
| 3181 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3182 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3183 | 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] | 3184 | } |
| 3185 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3186 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3187 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | { |
| 3189 | struct nfs4_exception exception = { }; |
| 3190 | int err; |
| 3191 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3192 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3193 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3194 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | &exception); |
| 3196 | } while (exception.retry); |
| 3197 | return err; |
| 3198 | } |
| 3199 | |
| 3200 | /* |
| 3201 | * The file is not closed if it is opened due to the a request to change |
| 3202 | * the size of the file. The open call will not be needed once the |
| 3203 | * VFS layer lookup-intents are implemented. |
| 3204 | * |
| 3205 | * Close is called when the inode is destroyed. |
| 3206 | * If we haven't opened the file for O_WRONLY, we |
| 3207 | * need to in the size_change case to obtain a stateid. |
| 3208 | * |
| 3209 | * Got race? |
| 3210 | * Because OPEN is always done by name in nfsv4, it is |
| 3211 | * possible that we opened a different file by the same |
| 3212 | * name. We can recognize this race condition, but we |
| 3213 | * can't do anything about it besides returning an error. |
| 3214 | * |
| 3215 | * This will be fixed with VFS changes (lookup-intent). |
| 3216 | */ |
| 3217 | static int |
| 3218 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3219 | struct iattr *sattr) |
| 3220 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3221 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3222 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3223 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3224 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | int status; |
| 3226 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3227 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3228 | sattr->ia_valid & ATTR_SIZE && |
| 3229 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3230 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3231 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3232 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3234 | /* Deal with open(O_TRUNC) */ |
| 3235 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3236 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3237 | |
| 3238 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3239 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3240 | return 0; |
| 3241 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3242 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3243 | if (sattr->ia_valid & ATTR_FILE) { |
| 3244 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3245 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3246 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3247 | if (ctx) { |
| 3248 | cred = ctx->cred; |
| 3249 | state = ctx->state; |
| 3250 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3251 | } |
| 3252 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3253 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3254 | if (IS_ERR(label)) |
| 3255 | return PTR_ERR(label); |
| 3256 | |
| 3257 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3258 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 3259 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3260 | nfs_setsecurity(inode, fattr, label); |
| 3261 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3262 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | return status; |
| 3264 | } |
| 3265 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3266 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3267 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3268 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3269 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3270 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3271 | int status; |
| 3272 | struct nfs4_lookup_arg args = { |
| 3273 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3274 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3275 | .name = name, |
| 3276 | }; |
| 3277 | struct nfs4_lookup_res res = { |
| 3278 | .server = server, |
| 3279 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3280 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3281 | .fh = fhandle, |
| 3282 | }; |
| 3283 | struct rpc_message msg = { |
| 3284 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3285 | .rpc_argp = &args, |
| 3286 | .rpc_resp = &res, |
| 3287 | }; |
| 3288 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3289 | args.bitmask = nfs4_bitmask(server, label); |
| 3290 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3291 | nfs_fattr_init(fattr); |
| 3292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3294 | 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] | 3295 | dprintk("NFS reply lookup: %d\n", status); |
| 3296 | return status; |
| 3297 | } |
| 3298 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3299 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3300 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3301 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3302 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3303 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3304 | fattr->nlink = 2; |
| 3305 | } |
| 3306 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3307 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3308 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3309 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3310 | { |
| 3311 | struct nfs4_exception exception = { }; |
| 3312 | struct rpc_clnt *client = *clnt; |
| 3313 | int err; |
| 3314 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3315 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3316 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3317 | switch (err) { |
| 3318 | case -NFS4ERR_BADNAME: |
| 3319 | err = -ENOENT; |
| 3320 | goto out; |
| 3321 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3322 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3323 | goto out; |
| 3324 | case -NFS4ERR_WRONGSEC: |
| 3325 | err = -EPERM; |
| 3326 | if (client != *clnt) |
| 3327 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3328 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3329 | if (IS_ERR(client)) |
| 3330 | return PTR_ERR(client); |
| 3331 | |
| 3332 | exception.retry = 1; |
| 3333 | break; |
| 3334 | default: |
| 3335 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3336 | } |
| 3337 | } while (exception.retry); |
| 3338 | |
| 3339 | out: |
| 3340 | if (err == 0) |
| 3341 | *clnt = client; |
| 3342 | else if (client != *clnt) |
| 3343 | rpc_shutdown_client(client); |
| 3344 | |
| 3345 | return err; |
| 3346 | } |
| 3347 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3348 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3349 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3350 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3352 | int status; |
| 3353 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3354 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3355 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3356 | if (client != NFS_CLIENT(dir)) { |
| 3357 | rpc_shutdown_client(client); |
| 3358 | nfs_fixup_secinfo_attributes(fattr); |
| 3359 | } |
| 3360 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3363 | struct rpc_clnt * |
| 3364 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3365 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3366 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3367 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3368 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3369 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3370 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3371 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3372 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3373 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3374 | } |
| 3375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3377 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3378 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | struct nfs4_accessargs args = { |
| 3380 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3381 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3383 | struct nfs4_accessres res = { |
| 3384 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3385 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | struct rpc_message msg = { |
| 3387 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3388 | .rpc_argp = &args, |
| 3389 | .rpc_resp = &res, |
| 3390 | .rpc_cred = entry->cred, |
| 3391 | }; |
| 3392 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3393 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | |
| 3395 | /* |
| 3396 | * Determine which access bits we want to ask for... |
| 3397 | */ |
| 3398 | if (mode & MAY_READ) |
| 3399 | args.access |= NFS4_ACCESS_READ; |
| 3400 | if (S_ISDIR(inode->i_mode)) { |
| 3401 | if (mode & MAY_WRITE) |
| 3402 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3403 | if (mode & MAY_EXEC) |
| 3404 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3405 | } else { |
| 3406 | if (mode & MAY_WRITE) |
| 3407 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3408 | if (mode & MAY_EXEC) |
| 3409 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3410 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3411 | |
| 3412 | res.fattr = nfs_alloc_fattr(); |
| 3413 | if (res.fattr == NULL) |
| 3414 | return -ENOMEM; |
| 3415 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3416 | 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] | 3417 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3418 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3419 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3421 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | return status; |
| 3423 | } |
| 3424 | |
| 3425 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3426 | { |
| 3427 | struct nfs4_exception exception = { }; |
| 3428 | int err; |
| 3429 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3430 | err = _nfs4_proc_access(inode, entry); |
| 3431 | trace_nfs4_access(inode, err); |
| 3432 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | &exception); |
| 3434 | } while (exception.retry); |
| 3435 | return err; |
| 3436 | } |
| 3437 | |
| 3438 | /* |
| 3439 | * TODO: For the time being, we don't try to get any attributes |
| 3440 | * along with any of the zero-copy operations READ, READDIR, |
| 3441 | * READLINK, WRITE. |
| 3442 | * |
| 3443 | * In the case of the first three, we want to put the GETATTR |
| 3444 | * after the read-type operation -- this is because it is hard |
| 3445 | * to predict the length of a GETATTR response in v4, and thus |
| 3446 | * align the READ data correctly. This means that the GETATTR |
| 3447 | * may end up partially falling into the page cache, and we should |
| 3448 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3449 | * To do this efficiently, we need to know the total length |
| 3450 | * of data received, which doesn't seem to be available outside |
| 3451 | * of the RPC layer. |
| 3452 | * |
| 3453 | * In the case of WRITE, we also want to put the GETATTR after |
| 3454 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3455 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | * |
| 3457 | * Both of these changes to the XDR layer would in fact be quite |
| 3458 | * minor, but I decided to leave them for a subsequent patch. |
| 3459 | */ |
| 3460 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3461 | unsigned int pgbase, unsigned int pglen) |
| 3462 | { |
| 3463 | struct nfs4_readlink args = { |
| 3464 | .fh = NFS_FH(inode), |
| 3465 | .pgbase = pgbase, |
| 3466 | .pglen = pglen, |
| 3467 | .pages = &page, |
| 3468 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3469 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | struct rpc_message msg = { |
| 3471 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3472 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3473 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | }; |
| 3475 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3476 | 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] | 3477 | } |
| 3478 | |
| 3479 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3480 | unsigned int pgbase, unsigned int pglen) |
| 3481 | { |
| 3482 | struct nfs4_exception exception = { }; |
| 3483 | int err; |
| 3484 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3485 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3486 | trace_nfs4_readlink(inode, err); |
| 3487 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | &exception); |
| 3489 | } while (exception.retry); |
| 3490 | return err; |
| 3491 | } |
| 3492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3494 | * 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] | 3495 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | static int |
| 3497 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3498 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3500 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3501 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | struct nfs4_state *state; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3503 | int opened = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | int status = 0; |
| 3505 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3506 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3507 | if (IS_ERR(ctx)) |
| 3508 | return PTR_ERR(ctx); |
| 3509 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3510 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3511 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3512 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3513 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, &opened); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | if (IS_ERR(state)) { |
| 3515 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3516 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3519 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3520 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | return status; |
| 3522 | } |
| 3523 | |
| 3524 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3525 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3526 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3527 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3529 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3531 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3532 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3533 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3535 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3536 | .rpc_argp = &args, |
| 3537 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3539 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3540 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3541 | 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] | 3542 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3543 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | return status; |
| 3545 | } |
| 3546 | |
| 3547 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3548 | { |
| 3549 | struct nfs4_exception exception = { }; |
| 3550 | int err; |
| 3551 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3552 | err = _nfs4_proc_remove(dir, name); |
| 3553 | trace_nfs4_remove(dir, name, err); |
| 3554 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | &exception); |
| 3556 | } while (exception.retry); |
| 3557 | return err; |
| 3558 | } |
| 3559 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3560 | 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] | 3561 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3562 | struct nfs_server *server = NFS_SERVER(dir); |
| 3563 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3564 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3566 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3568 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3569 | |
| 3570 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3573 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3574 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3575 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3576 | &data->args.seq_args, |
| 3577 | &data->res.seq_res, |
| 3578 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3581 | 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] | 3582 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3583 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3584 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3585 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3586 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3587 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3588 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3589 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3590 | return 0; |
| 3591 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3592 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3595 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3596 | { |
| 3597 | struct nfs_server *server = NFS_SERVER(dir); |
| 3598 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3599 | struct nfs_renameres *res = msg->rpc_resp; |
| 3600 | |
| 3601 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3602 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3603 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3604 | } |
| 3605 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3606 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3607 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3608 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3609 | &data->args.seq_args, |
| 3610 | &data->res.seq_res, |
| 3611 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3615 | struct inode *new_dir) |
| 3616 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3617 | struct nfs_renamedata *data = task->tk_calldata; |
| 3618 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3619 | |
| 3620 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3621 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3622 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3623 | return 0; |
| 3624 | |
| 3625 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3626 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3627 | return 1; |
| 3628 | } |
| 3629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3631 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3632 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | struct nfs4_link_arg arg = { |
| 3634 | .fh = NFS_FH(inode), |
| 3635 | .dir_fh = NFS_FH(dir), |
| 3636 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3637 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3639 | struct nfs4_link_res res = { |
| 3640 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3641 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3642 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | struct rpc_message msg = { |
| 3644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3645 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3646 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3648 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3650 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3651 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3652 | goto out; |
| 3653 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3654 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3655 | if (IS_ERR(res.label)) { |
| 3656 | status = PTR_ERR(res.label); |
| 3657 | goto out; |
| 3658 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3659 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3660 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3661 | 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] | 3662 | if (!status) { |
| 3663 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3664 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3665 | if (!status) |
| 3666 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3667 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3668 | |
| 3669 | |
| 3670 | nfs4_label_free(res.label); |
| 3671 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3672 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3673 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | return status; |
| 3675 | } |
| 3676 | |
| 3677 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3678 | { |
| 3679 | struct nfs4_exception exception = { }; |
| 3680 | int err; |
| 3681 | do { |
| 3682 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3683 | _nfs4_proc_link(inode, dir, name), |
| 3684 | &exception); |
| 3685 | } while (exception.retry); |
| 3686 | return err; |
| 3687 | } |
| 3688 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3689 | struct nfs4_createdata { |
| 3690 | struct rpc_message msg; |
| 3691 | struct nfs4_create_arg arg; |
| 3692 | struct nfs4_create_res res; |
| 3693 | struct nfs_fh fh; |
| 3694 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3695 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3696 | }; |
| 3697 | |
| 3698 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3699 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3700 | { |
| 3701 | struct nfs4_createdata *data; |
| 3702 | |
| 3703 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3704 | if (data != NULL) { |
| 3705 | struct nfs_server *server = NFS_SERVER(dir); |
| 3706 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3707 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3708 | if (IS_ERR(data->label)) |
| 3709 | goto out_free; |
| 3710 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3711 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3712 | data->msg.rpc_argp = &data->arg; |
| 3713 | data->msg.rpc_resp = &data->res; |
| 3714 | data->arg.dir_fh = NFS_FH(dir); |
| 3715 | data->arg.server = server; |
| 3716 | data->arg.name = name; |
| 3717 | data->arg.attrs = sattr; |
| 3718 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3719 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3720 | data->res.server = server; |
| 3721 | data->res.fh = &data->fh; |
| 3722 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3723 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3724 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3725 | } |
| 3726 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3727 | out_free: |
| 3728 | kfree(data); |
| 3729 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3733 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3734 | 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] | 3735 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3736 | if (status == 0) { |
| 3737 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3738 | 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] | 3739 | } |
| 3740 | return status; |
| 3741 | } |
| 3742 | |
| 3743 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3744 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3745 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3746 | kfree(data); |
| 3747 | } |
| 3748 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3749 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3750 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3751 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3753 | struct nfs4_createdata *data; |
| 3754 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3756 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3757 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3758 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3759 | status = -ENOMEM; |
| 3760 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3761 | if (data == NULL) |
| 3762 | goto out; |
| 3763 | |
| 3764 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3765 | data->arg.u.symlink.pages = &page; |
| 3766 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3767 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3769 | status = nfs4_do_create(dir, dentry, data); |
| 3770 | |
| 3771 | nfs4_free_createdata(data); |
| 3772 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | return status; |
| 3774 | } |
| 3775 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3776 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3777 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | { |
| 3779 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3780 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3782 | |
| 3783 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3786 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3787 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3788 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | &exception); |
| 3790 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3791 | |
| 3792 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | return err; |
| 3794 | } |
| 3795 | |
| 3796 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3797 | struct iattr *sattr, struct nfs4_label *label) |
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 | struct nfs4_createdata *data; |
| 3800 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3802 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3803 | if (data == NULL) |
| 3804 | goto out; |
| 3805 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3806 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3807 | status = nfs4_do_create(dir, dentry, data); |
| 3808 | |
| 3809 | nfs4_free_createdata(data); |
| 3810 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | return status; |
| 3812 | } |
| 3813 | |
| 3814 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3815 | struct iattr *sattr) |
| 3816 | { |
| 3817 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3818 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3820 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3821 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3822 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3823 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3825 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3826 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3827 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | &exception); |
| 3829 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3830 | nfs4_label_release_security(label); |
| 3831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | return err; |
| 3833 | } |
| 3834 | |
| 3835 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3836 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | { |
| 3838 | struct inode *dir = dentry->d_inode; |
| 3839 | struct nfs4_readdir_arg args = { |
| 3840 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3841 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | .pgbase = 0, |
| 3843 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3844 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3845 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | }; |
| 3847 | struct nfs4_readdir_res res; |
| 3848 | struct rpc_message msg = { |
| 3849 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3850 | .rpc_argp = &args, |
| 3851 | .rpc_resp = &res, |
| 3852 | .rpc_cred = cred, |
| 3853 | }; |
| 3854 | int status; |
| 3855 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 3856 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 3857 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3858 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3859 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3861 | 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] | 3862 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3863 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3864 | status += args.pgbase; |
| 3865 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3866 | |
| 3867 | nfs_invalidate_atime(dir); |
| 3868 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3869 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | return status; |
| 3871 | } |
| 3872 | |
| 3873 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3874 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | { |
| 3876 | struct nfs4_exception exception = { }; |
| 3877 | int err; |
| 3878 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3879 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3880 | pages, count, plus); |
| 3881 | trace_nfs4_readdir(dentry->d_inode, err); |
| 3882 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | &exception); |
| 3884 | } while (exception.retry); |
| 3885 | return err; |
| 3886 | } |
| 3887 | |
| 3888 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3889 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3891 | struct nfs4_createdata *data; |
| 3892 | int mode = sattr->ia_mode; |
| 3893 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3895 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3896 | if (data == NULL) |
| 3897 | goto out; |
| 3898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3900 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3902 | data->arg.ftype = NF4BLK; |
| 3903 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3904 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | } |
| 3906 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3907 | data->arg.ftype = NF4CHR; |
| 3908 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3909 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3910 | } else if (!S_ISSOCK(mode)) { |
| 3911 | status = -EINVAL; |
| 3912 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3914 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3915 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3916 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3917 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3918 | nfs4_free_createdata(data); |
| 3919 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | return status; |
| 3921 | } |
| 3922 | |
| 3923 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3924 | struct iattr *sattr, dev_t rdev) |
| 3925 | { |
| 3926 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3927 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3929 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3930 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3931 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3932 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3934 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3935 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3936 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | &exception); |
| 3938 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3939 | |
| 3940 | nfs4_label_release_security(label); |
| 3941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | return err; |
| 3943 | } |
| 3944 | |
| 3945 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3946 | struct nfs_fsstat *fsstat) |
| 3947 | { |
| 3948 | struct nfs4_statfs_arg args = { |
| 3949 | .fh = fhandle, |
| 3950 | .bitmask = server->attr_bitmask, |
| 3951 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3952 | struct nfs4_statfs_res res = { |
| 3953 | .fsstat = fsstat, |
| 3954 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | struct rpc_message msg = { |
| 3956 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3957 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3958 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | }; |
| 3960 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3961 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3962 | 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] | 3963 | } |
| 3964 | |
| 3965 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3966 | { |
| 3967 | struct nfs4_exception exception = { }; |
| 3968 | int err; |
| 3969 | do { |
| 3970 | err = nfs4_handle_exception(server, |
| 3971 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3972 | &exception); |
| 3973 | } while (exception.retry); |
| 3974 | return err; |
| 3975 | } |
| 3976 | |
| 3977 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3978 | struct nfs_fsinfo *fsinfo) |
| 3979 | { |
| 3980 | struct nfs4_fsinfo_arg args = { |
| 3981 | .fh = fhandle, |
| 3982 | .bitmask = server->attr_bitmask, |
| 3983 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3984 | struct nfs4_fsinfo_res res = { |
| 3985 | .fsinfo = fsinfo, |
| 3986 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | struct rpc_message msg = { |
| 3988 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3989 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3990 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | }; |
| 3992 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3993 | 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] | 3994 | } |
| 3995 | |
| 3996 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3997 | { |
| 3998 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3999 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | int err; |
| 4001 | |
| 4002 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4003 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4004 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4005 | if (err == 0) { |
| 4006 | struct nfs_client *clp = server->nfs_client; |
| 4007 | |
| 4008 | spin_lock(&clp->cl_lock); |
| 4009 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 4010 | clp->cl_last_renewal = now; |
| 4011 | spin_unlock(&clp->cl_lock); |
| 4012 | break; |
| 4013 | } |
| 4014 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | } while (exception.retry); |
| 4016 | return err; |
| 4017 | } |
| 4018 | |
| 4019 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4020 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4021 | int error; |
| 4022 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4023 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4024 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4025 | if (error == 0) { |
| 4026 | /* block layout checks this! */ |
| 4027 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4028 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4029 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4030 | |
| 4031 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4035 | struct nfs_pathconf *pathconf) |
| 4036 | { |
| 4037 | struct nfs4_pathconf_arg args = { |
| 4038 | .fh = fhandle, |
| 4039 | .bitmask = server->attr_bitmask, |
| 4040 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4041 | struct nfs4_pathconf_res res = { |
| 4042 | .pathconf = pathconf, |
| 4043 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | struct rpc_message msg = { |
| 4045 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4046 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4047 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | }; |
| 4049 | |
| 4050 | /* None of the pathconf attributes are mandatory to implement */ |
| 4051 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4052 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4053 | return 0; |
| 4054 | } |
| 4055 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4056 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4057 | 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] | 4058 | } |
| 4059 | |
| 4060 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4061 | struct nfs_pathconf *pathconf) |
| 4062 | { |
| 4063 | struct nfs4_exception exception = { }; |
| 4064 | int err; |
| 4065 | |
| 4066 | do { |
| 4067 | err = nfs4_handle_exception(server, |
| 4068 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4069 | &exception); |
| 4070 | } while (exception.retry); |
| 4071 | return err; |
| 4072 | } |
| 4073 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4074 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4075 | const struct nfs_open_context *ctx, |
| 4076 | const struct nfs_lock_context *l_ctx, |
| 4077 | fmode_t fmode) |
| 4078 | { |
| 4079 | const struct nfs_lockowner *lockowner = NULL; |
| 4080 | |
| 4081 | if (l_ctx != NULL) |
| 4082 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4083 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4084 | } |
| 4085 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4086 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4087 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4088 | const struct nfs_open_context *ctx, |
| 4089 | const struct nfs_lock_context *l_ctx, |
| 4090 | fmode_t fmode) |
| 4091 | { |
| 4092 | nfs4_stateid current_stateid; |
| 4093 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4094 | /* If the current stateid represents a lost lock, then exit */ |
| 4095 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4096 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4097 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4098 | } |
| 4099 | |
| 4100 | static bool nfs4_error_stateid_expired(int err) |
| 4101 | { |
| 4102 | switch (err) { |
| 4103 | case -NFS4ERR_DELEG_REVOKED: |
| 4104 | case -NFS4ERR_ADMIN_REVOKED: |
| 4105 | case -NFS4ERR_BAD_STATEID: |
| 4106 | case -NFS4ERR_STALE_STATEID: |
| 4107 | case -NFS4ERR_OLD_STATEID: |
| 4108 | case -NFS4ERR_OPENMODE: |
| 4109 | case -NFS4ERR_EXPIRED: |
| 4110 | return true; |
| 4111 | } |
| 4112 | return false; |
| 4113 | } |
| 4114 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4115 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4116 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4117 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4118 | } |
| 4119 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4120 | 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] | 4121 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4122 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4124 | trace_nfs4_read(hdr, task->tk_status); |
| 4125 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4126 | hdr->args.context->state, |
| 4127 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4128 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4129 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4131 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4132 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4134 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4135 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4138 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4139 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4140 | { |
| 4141 | |
| 4142 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4143 | nfs4_stateid_is_current(&args->stateid, |
| 4144 | args->context, |
| 4145 | args->lock_context, |
| 4146 | FMODE_READ)) |
| 4147 | return false; |
| 4148 | rpc_restart_call_prepare(task); |
| 4149 | return true; |
| 4150 | } |
| 4151 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4152 | 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] | 4153 | { |
| 4154 | |
| 4155 | dprintk("--> %s\n", __func__); |
| 4156 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4157 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4158 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4159 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4160 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4161 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4162 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4165 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4166 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4168 | hdr->timestamp = jiffies; |
| 4169 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4170 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4171 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | } |
| 4173 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4174 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4175 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4176 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4177 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4178 | &hdr->args.seq_args, |
| 4179 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4180 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4181 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4182 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4183 | hdr->args.lock_context, |
| 4184 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4185 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4186 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4187 | return -EIO; |
| 4188 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4191 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4192 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4194 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4195 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4196 | trace_nfs4_write(hdr, task->tk_status); |
| 4197 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4198 | hdr->args.context->state, |
| 4199 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4200 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4201 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4203 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4204 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
| 4205 | nfs_post_op_update_inode_force_wcc(inode, &hdr->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4206 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4207 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4210 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4211 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4212 | { |
| 4213 | |
| 4214 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4215 | nfs4_stateid_is_current(&args->stateid, |
| 4216 | args->context, |
| 4217 | args->lock_context, |
| 4218 | FMODE_WRITE)) |
| 4219 | return false; |
| 4220 | rpc_restart_call_prepare(task); |
| 4221 | return true; |
| 4222 | } |
| 4223 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4224 | 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] | 4225 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4226 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4227 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4228 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4229 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4230 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4231 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4232 | } |
| 4233 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4234 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4235 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4236 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4237 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4238 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4239 | return false; |
| 4240 | /* Otherwise, request attributes if and only if we don't hold |
| 4241 | * a delegation |
| 4242 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4243 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4244 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4245 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4246 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4247 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4249 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4250 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4251 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4252 | hdr->args.bitmask = NULL; |
| 4253 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4254 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4255 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4256 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4257 | if (!hdr->pgio_done_cb) |
| 4258 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4259 | hdr->res.server = server; |
| 4260 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4262 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4263 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4266 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4267 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4268 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4269 | &data->args.seq_args, |
| 4270 | &data->res.seq_res, |
| 4271 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | } |
| 4273 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4274 | 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] | 4275 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4277 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4278 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4279 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4280 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4281 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4282 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4284 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4287 | 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] | 4288 | { |
| 4289 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4290 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4291 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4292 | } |
| 4293 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4294 | 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] | 4295 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4296 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4297 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4298 | if (data->commit_done_cb == NULL) |
| 4299 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4300 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4301 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4302 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4305 | struct nfs4_renewdata { |
| 4306 | struct nfs_client *client; |
| 4307 | unsigned long timestamp; |
| 4308 | }; |
| 4309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | /* |
| 4311 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4312 | * standalone procedure for queueing an asynchronous RENEW. |
| 4313 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4314 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4315 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4316 | struct nfs4_renewdata *data = calldata; |
| 4317 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4318 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4319 | if (atomic_read(&clp->cl_count) > 1) |
| 4320 | nfs4_schedule_state_renewal(clp); |
| 4321 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4322 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4323 | } |
| 4324 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4325 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4327 | struct nfs4_renewdata *data = calldata; |
| 4328 | struct nfs_client *clp = data->client; |
| 4329 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4331 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4332 | switch (task->tk_status) { |
| 4333 | case 0: |
| 4334 | break; |
| 4335 | case -NFS4ERR_LEASE_MOVED: |
| 4336 | nfs4_schedule_lease_moved_recovery(clp); |
| 4337 | break; |
| 4338 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4339 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4340 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4341 | return; |
| 4342 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4343 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4344 | return; |
| 4345 | } |
| 4346 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4348 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4351 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4352 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4353 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4354 | }; |
| 4355 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4356 | 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] | 4357 | { |
| 4358 | struct rpc_message msg = { |
| 4359 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4360 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4361 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4363 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4365 | if (renew_flags == 0) |
| 4366 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4367 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4368 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4369 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4370 | if (data == NULL) |
| 4371 | return -ENOMEM; |
| 4372 | data->client = clp; |
| 4373 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4374 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4375 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | } |
| 4377 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4378 | 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] | 4379 | { |
| 4380 | struct rpc_message msg = { |
| 4381 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4382 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4383 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | }; |
| 4385 | unsigned long now = jiffies; |
| 4386 | int status; |
| 4387 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4388 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | if (status < 0) |
| 4390 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4391 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | return 0; |
| 4393 | } |
| 4394 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4395 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4396 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4397 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4398 | } |
| 4399 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4400 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4401 | * 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] | 4402 | * the stack. |
| 4403 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4404 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4405 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4406 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4407 | struct page **pages, unsigned int *pgbase) |
| 4408 | { |
| 4409 | struct page *newpage, **spages; |
| 4410 | int rc = 0; |
| 4411 | size_t len; |
| 4412 | spages = pages; |
| 4413 | |
| 4414 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4415 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4416 | newpage = alloc_page(GFP_KERNEL); |
| 4417 | |
| 4418 | if (newpage == NULL) |
| 4419 | goto unwind; |
| 4420 | memcpy(page_address(newpage), buf, len); |
| 4421 | buf += len; |
| 4422 | buflen -= len; |
| 4423 | *pages++ = newpage; |
| 4424 | rc++; |
| 4425 | } while (buflen != 0); |
| 4426 | |
| 4427 | return rc; |
| 4428 | |
| 4429 | unwind: |
| 4430 | for(; rc > 0; rc--) |
| 4431 | __free_page(spages[rc-1]); |
| 4432 | return -ENOMEM; |
| 4433 | } |
| 4434 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4435 | struct nfs4_cached_acl { |
| 4436 | int cached; |
| 4437 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4438 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4439 | }; |
| 4440 | |
| 4441 | 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] | 4442 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4443 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4444 | |
| 4445 | spin_lock(&inode->i_lock); |
| 4446 | kfree(nfsi->nfs4_acl); |
| 4447 | nfsi->nfs4_acl = acl; |
| 4448 | spin_unlock(&inode->i_lock); |
| 4449 | } |
| 4450 | |
| 4451 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4452 | { |
| 4453 | nfs4_set_cached_acl(inode, NULL); |
| 4454 | } |
| 4455 | |
| 4456 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4457 | { |
| 4458 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4459 | struct nfs4_cached_acl *acl; |
| 4460 | int ret = -ENOENT; |
| 4461 | |
| 4462 | spin_lock(&inode->i_lock); |
| 4463 | acl = nfsi->nfs4_acl; |
| 4464 | if (acl == NULL) |
| 4465 | goto out; |
| 4466 | if (buf == NULL) /* user is just asking for length */ |
| 4467 | goto out_len; |
| 4468 | if (acl->cached == 0) |
| 4469 | goto out; |
| 4470 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4471 | if (acl->len > buflen) |
| 4472 | goto out; |
| 4473 | memcpy(buf, acl->data, acl->len); |
| 4474 | out_len: |
| 4475 | ret = acl->len; |
| 4476 | out: |
| 4477 | spin_unlock(&inode->i_lock); |
| 4478 | return ret; |
| 4479 | } |
| 4480 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4481 | 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] | 4482 | { |
| 4483 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4484 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4485 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4486 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4487 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4488 | if (acl == NULL) |
| 4489 | goto out; |
| 4490 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4491 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4492 | } else { |
| 4493 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4494 | if (acl == NULL) |
| 4495 | goto out; |
| 4496 | acl->cached = 0; |
| 4497 | } |
| 4498 | acl->len = acl_len; |
| 4499 | out: |
| 4500 | nfs4_set_cached_acl(inode, acl); |
| 4501 | } |
| 4502 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4503 | /* |
| 4504 | * The getxattr API returns the required buffer length when called with a |
| 4505 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4506 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4507 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4508 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4509 | * the cache. If not so, we throw away the page, and cache the required |
| 4510 | * length. The next getxattr call will then produce another round trip to |
| 4511 | * the server, this time with the input buf of the required size. |
| 4512 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4513 | 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] | 4514 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4515 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4516 | struct nfs_getaclargs args = { |
| 4517 | .fh = NFS_FH(inode), |
| 4518 | .acl_pages = pages, |
| 4519 | .acl_len = buflen, |
| 4520 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4521 | struct nfs_getaclres res = { |
| 4522 | .acl_len = buflen, |
| 4523 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4524 | struct rpc_message msg = { |
| 4525 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4526 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4527 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4528 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4529 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4530 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4531 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4532 | /* As long as we're doing a round trip to the server anyway, |
| 4533 | * let's be prepared for a page of acl data. */ |
| 4534 | if (npages == 0) |
| 4535 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4536 | if (npages > ARRAY_SIZE(pages)) |
| 4537 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4538 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4539 | for (i = 0; i < npages; i++) { |
| 4540 | pages[i] = alloc_page(GFP_KERNEL); |
| 4541 | if (!pages[i]) |
| 4542 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4543 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4544 | |
| 4545 | /* for decoding across pages */ |
| 4546 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4547 | if (!res.acl_scratch) |
| 4548 | goto out_free; |
| 4549 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4550 | args.acl_len = npages * PAGE_SIZE; |
| 4551 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4552 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4553 | 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] | 4554 | __func__, buf, buflen, npages, args.acl_len); |
| 4555 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4556 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4557 | if (ret) |
| 4558 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4559 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4560 | /* Handle the case where the passed-in buffer is too short */ |
| 4561 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4562 | /* Did the user only issue a request for the acl length? */ |
| 4563 | if (buf == NULL) |
| 4564 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4565 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4566 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4567 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4568 | 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] | 4569 | if (buf) { |
| 4570 | if (res.acl_len > buflen) { |
| 4571 | ret = -ERANGE; |
| 4572 | goto out_free; |
| 4573 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4574 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4575 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4576 | out_ok: |
| 4577 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4578 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4579 | for (i = 0; i < npages; i++) |
| 4580 | if (pages[i]) |
| 4581 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4582 | if (res.acl_scratch) |
| 4583 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4584 | return ret; |
| 4585 | } |
| 4586 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4587 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4588 | { |
| 4589 | struct nfs4_exception exception = { }; |
| 4590 | ssize_t ret; |
| 4591 | do { |
| 4592 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4593 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4594 | if (ret >= 0) |
| 4595 | break; |
| 4596 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4597 | } while (exception.retry); |
| 4598 | return ret; |
| 4599 | } |
| 4600 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4601 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4602 | { |
| 4603 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4604 | int ret; |
| 4605 | |
| 4606 | if (!nfs4_server_supports_acls(server)) |
| 4607 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4608 | ret = nfs_revalidate_inode(server, inode); |
| 4609 | if (ret < 0) |
| 4610 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4611 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4612 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4613 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4614 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4615 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4616 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4617 | return ret; |
| 4618 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4621 | 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] | 4622 | { |
| 4623 | struct nfs_server *server = NFS_SERVER(inode); |
| 4624 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4625 | struct nfs_setaclargs arg = { |
| 4626 | .fh = NFS_FH(inode), |
| 4627 | .acl_pages = pages, |
| 4628 | .acl_len = buflen, |
| 4629 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4630 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4631 | struct rpc_message msg = { |
| 4632 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4633 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4634 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4635 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4636 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4637 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4638 | |
| 4639 | if (!nfs4_server_supports_acls(server)) |
| 4640 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4641 | if (npages > ARRAY_SIZE(pages)) |
| 4642 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4643 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4644 | if (i < 0) |
| 4645 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4646 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4647 | 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] | 4648 | |
| 4649 | /* |
| 4650 | * Free each page after tx, so the only ref left is |
| 4651 | * held by the network stack |
| 4652 | */ |
| 4653 | for (; i > 0; i--) |
| 4654 | put_page(pages[i-1]); |
| 4655 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4656 | /* |
| 4657 | * Acl update can result in inode attribute update. |
| 4658 | * so mark the attribute cache invalid. |
| 4659 | */ |
| 4660 | spin_lock(&inode->i_lock); |
| 4661 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4662 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4663 | nfs_access_zap_cache(inode); |
| 4664 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4665 | return ret; |
| 4666 | } |
| 4667 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4668 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4669 | { |
| 4670 | struct nfs4_exception exception = { }; |
| 4671 | int err; |
| 4672 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4673 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4674 | trace_nfs4_set_acl(inode, err); |
| 4675 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4676 | &exception); |
| 4677 | } while (exception.retry); |
| 4678 | return err; |
| 4679 | } |
| 4680 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4681 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4682 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4683 | size_t buflen) |
| 4684 | { |
| 4685 | struct nfs_server *server = NFS_SERVER(inode); |
| 4686 | struct nfs_fattr fattr; |
| 4687 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4688 | |
| 4689 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4690 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4691 | .fh = NFS_FH(inode), |
| 4692 | .bitmask = bitmask, |
| 4693 | }; |
| 4694 | struct nfs4_getattr_res res = { |
| 4695 | .fattr = &fattr, |
| 4696 | .label = &label, |
| 4697 | .server = server, |
| 4698 | }; |
| 4699 | struct rpc_message msg = { |
| 4700 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4701 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4702 | .rpc_resp = &res, |
| 4703 | }; |
| 4704 | int ret; |
| 4705 | |
| 4706 | nfs_fattr_init(&fattr); |
| 4707 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4708 | 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] | 4709 | if (ret) |
| 4710 | return ret; |
| 4711 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4712 | return -ENOENT; |
| 4713 | if (buflen < label.len) |
| 4714 | return -ERANGE; |
| 4715 | return 0; |
| 4716 | } |
| 4717 | |
| 4718 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4719 | size_t buflen) |
| 4720 | { |
| 4721 | struct nfs4_exception exception = { }; |
| 4722 | int err; |
| 4723 | |
| 4724 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4725 | return -EOPNOTSUPP; |
| 4726 | |
| 4727 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4728 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4729 | trace_nfs4_get_security_label(inode, err); |
| 4730 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4731 | &exception); |
| 4732 | } while (exception.retry); |
| 4733 | return err; |
| 4734 | } |
| 4735 | |
| 4736 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4737 | struct nfs4_label *ilabel, |
| 4738 | struct nfs_fattr *fattr, |
| 4739 | struct nfs4_label *olabel) |
| 4740 | { |
| 4741 | |
| 4742 | struct iattr sattr = {0}; |
| 4743 | struct nfs_server *server = NFS_SERVER(inode); |
| 4744 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4745 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4746 | .fh = NFS_FH(inode), |
| 4747 | .iap = &sattr, |
| 4748 | .server = server, |
| 4749 | .bitmask = bitmask, |
| 4750 | .label = ilabel, |
| 4751 | }; |
| 4752 | struct nfs_setattrres res = { |
| 4753 | .fattr = fattr, |
| 4754 | .label = olabel, |
| 4755 | .server = server, |
| 4756 | }; |
| 4757 | struct rpc_message msg = { |
| 4758 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4759 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4760 | .rpc_resp = &res, |
| 4761 | }; |
| 4762 | int status; |
| 4763 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4764 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4765 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4766 | 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] | 4767 | if (status) |
| 4768 | dprintk("%s failed: %d\n", __func__, status); |
| 4769 | |
| 4770 | return status; |
| 4771 | } |
| 4772 | |
| 4773 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4774 | struct nfs4_label *ilabel, |
| 4775 | struct nfs_fattr *fattr, |
| 4776 | struct nfs4_label *olabel) |
| 4777 | { |
| 4778 | struct nfs4_exception exception = { }; |
| 4779 | int err; |
| 4780 | |
| 4781 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4782 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4783 | fattr, olabel); |
| 4784 | trace_nfs4_set_security_label(inode, err); |
| 4785 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4786 | &exception); |
| 4787 | } while (exception.retry); |
| 4788 | return err; |
| 4789 | } |
| 4790 | |
| 4791 | static int |
| 4792 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4793 | { |
| 4794 | struct nfs4_label ilabel, *olabel = NULL; |
| 4795 | struct nfs_fattr fattr; |
| 4796 | struct rpc_cred *cred; |
| 4797 | struct inode *inode = dentry->d_inode; |
| 4798 | int status; |
| 4799 | |
| 4800 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4801 | return -EOPNOTSUPP; |
| 4802 | |
| 4803 | nfs_fattr_init(&fattr); |
| 4804 | |
| 4805 | ilabel.pi = 0; |
| 4806 | ilabel.lfs = 0; |
| 4807 | ilabel.label = (char *)buf; |
| 4808 | ilabel.len = buflen; |
| 4809 | |
| 4810 | cred = rpc_lookup_cred(); |
| 4811 | if (IS_ERR(cred)) |
| 4812 | return PTR_ERR(cred); |
| 4813 | |
| 4814 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4815 | if (IS_ERR(olabel)) { |
| 4816 | status = -PTR_ERR(olabel); |
| 4817 | goto out; |
| 4818 | } |
| 4819 | |
| 4820 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4821 | if (status == 0) |
| 4822 | nfs_setsecurity(inode, &fattr, olabel); |
| 4823 | |
| 4824 | nfs4_label_free(olabel); |
| 4825 | out: |
| 4826 | put_rpccred(cred); |
| 4827 | return status; |
| 4828 | } |
| 4829 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4830 | |
| 4831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | static int |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4833 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, |
| 4834 | struct nfs4_state *state, long *timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4836 | struct nfs_client *clp = server->nfs_client; |
| 4837 | |
| 4838 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | return 0; |
| 4840 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4841 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4842 | case -NFS4ERR_ADMIN_REVOKED: |
| 4843 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4844 | if (state == NULL) |
| 4845 | break; |
| 4846 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4847 | case -NFS4ERR_OPENMODE: |
| 4848 | if (state == NULL) |
| 4849 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4850 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4851 | goto recovery_failed; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4852 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4853 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4854 | if (state != NULL) { |
| 4855 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4856 | goto recovery_failed; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4859 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4860 | nfs4_schedule_lease_recovery(clp); |
| 4861 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4862 | case -NFS4ERR_MOVED: |
| 4863 | if (nfs4_schedule_migration_recovery(server) < 0) |
| 4864 | goto recovery_failed; |
| 4865 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 4866 | case -NFS4ERR_LEASE_MOVED: |
| 4867 | nfs4_schedule_lease_moved_recovery(clp); |
| 4868 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4869 | #if defined(CONFIG_NFS_V4_1) |
| 4870 | case -NFS4ERR_BADSESSION: |
| 4871 | case -NFS4ERR_BADSLOT: |
| 4872 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4873 | case -NFS4ERR_DEADSESSION: |
| 4874 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4875 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4876 | case -NFS4ERR_SEQ_MISORDERED: |
| 4877 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4878 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4879 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4a82fd7 | 2013-11-15 16:36:16 -0500 | [diff] [blame] | 4880 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4881 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4883 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4884 | rpc_delay(task, nfs4_update_delay(timeout)); |
| 4885 | goto restart_call; |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4886 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4888 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | case -NFS4ERR_OLD_STATEID: |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4890 | goto restart_call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | } |
| 4892 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4893 | return 0; |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4894 | recovery_failed: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4895 | task->tk_status = -EIO; |
| 4896 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4897 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4898 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4899 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4900 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4901 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 4902 | goto recovery_failed; |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4903 | restart_call: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4904 | task->tk_status = 0; |
| 4905 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | } |
| 4907 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4908 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4909 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4910 | { |
| 4911 | __be32 verf[2]; |
| 4912 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4913 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4914 | /* An impossible timestamp guarantees this value |
| 4915 | * will never match a generated boot time. */ |
| 4916 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4917 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4918 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4919 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4920 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4921 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4922 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4923 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4924 | } |
| 4925 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4926 | static unsigned int |
| 4927 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4928 | char *buf, size_t len) |
| 4929 | { |
| 4930 | unsigned int result; |
| 4931 | |
| 4932 | rcu_read_lock(); |
| 4933 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4934 | clp->cl_ipaddr, |
| 4935 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4936 | RPC_DISPLAY_ADDR), |
| 4937 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4938 | RPC_DISPLAY_PROTO)); |
| 4939 | rcu_read_unlock(); |
| 4940 | return result; |
| 4941 | } |
| 4942 | |
| 4943 | static unsigned int |
| 4944 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4945 | char *buf, size_t len) |
| 4946 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4947 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4948 | |
| 4949 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4950 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4951 | clp->rpc_ops->version, |
| 4952 | clp->cl_minorversion, |
| 4953 | nfs4_client_id_uniquifier, |
| 4954 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4955 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4956 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4957 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4958 | } |
| 4959 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 4960 | /* |
| 4961 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 4962 | * services. Advertise one based on the address family of the |
| 4963 | * clientaddr. |
| 4964 | */ |
| 4965 | static unsigned int |
| 4966 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 4967 | { |
| 4968 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 4969 | return scnprintf(buf, len, "tcp6"); |
| 4970 | else |
| 4971 | return scnprintf(buf, len, "tcp"); |
| 4972 | } |
| 4973 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 4974 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 4975 | { |
| 4976 | struct nfs4_setclientid *sc = calldata; |
| 4977 | |
| 4978 | if (task->tk_status == 0) |
| 4979 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 4980 | } |
| 4981 | |
| 4982 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 4983 | .rpc_call_done = nfs4_setclientid_done, |
| 4984 | }; |
| 4985 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4986 | /** |
| 4987 | * nfs4_proc_setclientid - Negotiate client ID |
| 4988 | * @clp: state data structure |
| 4989 | * @program: RPC program for NFSv4 callback service |
| 4990 | * @port: IP port number for NFS4 callback service |
| 4991 | * @cred: RPC credential to use for this call |
| 4992 | * @res: where to place the result |
| 4993 | * |
| 4994 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4995 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4996 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4997 | unsigned short port, struct rpc_cred *cred, |
| 4998 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | { |
| 5000 | nfs4_verifier sc_verifier; |
| 5001 | struct nfs4_setclientid setclientid = { |
| 5002 | .sc_verifier = &sc_verifier, |
| 5003 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 5004 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | }; |
| 5006 | struct rpc_message msg = { |
| 5007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5008 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5009 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5010 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5012 | struct rpc_task *task; |
| 5013 | struct rpc_task_setup task_setup_data = { |
| 5014 | .rpc_client = clp->cl_rpcclient, |
| 5015 | .rpc_message = &msg, |
| 5016 | .callback_ops = &nfs4_setclientid_ops, |
| 5017 | .callback_data = &setclientid, |
| 5018 | .flags = RPC_TASK_TIMEOUT, |
| 5019 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5020 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5022 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5023 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5024 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5025 | setclientid.sc_name_len = |
| 5026 | nfs4_init_uniform_client_string(clp, |
| 5027 | setclientid.sc_name, |
| 5028 | sizeof(setclientid.sc_name)); |
| 5029 | else |
| 5030 | setclientid.sc_name_len = |
| 5031 | nfs4_init_nonuniform_client_string(clp, |
| 5032 | setclientid.sc_name, |
| 5033 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5034 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5035 | setclientid.sc_netid_len = |
| 5036 | nfs4_init_callback_netid(clp, |
| 5037 | setclientid.sc_netid, |
| 5038 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5039 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5040 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5042 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5043 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 5044 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5045 | setclientid.sc_name_len, setclientid.sc_name); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5046 | task = rpc_run_task(&task_setup_data); |
| 5047 | if (IS_ERR(task)) { |
| 5048 | status = PTR_ERR(task); |
| 5049 | goto out; |
| 5050 | } |
| 5051 | status = task->tk_status; |
| 5052 | if (setclientid.sc_cred) { |
| 5053 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5054 | put_rpccred(setclientid.sc_cred); |
| 5055 | } |
| 5056 | rpc_put_task(task); |
| 5057 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5058 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5059 | dprintk("NFS reply setclientid: %d\n", status); |
| 5060 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | } |
| 5062 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5063 | /** |
| 5064 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5065 | * @clp: state data structure |
| 5066 | * @res: result of a previous SETCLIENTID |
| 5067 | * @cred: RPC credential to use for this call |
| 5068 | * |
| 5069 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5070 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5071 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5072 | struct nfs4_setclientid_res *arg, |
| 5073 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | struct rpc_message msg = { |
| 5076 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5077 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5078 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | int status; |
| 5081 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5082 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5083 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5084 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5085 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5086 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5087 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | return status; |
| 5089 | } |
| 5090 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5091 | struct nfs4_delegreturndata { |
| 5092 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5093 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5094 | struct nfs_fh fh; |
| 5095 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5096 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5097 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5098 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5099 | struct inode *inode; |
| 5100 | bool roc; |
| 5101 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5102 | }; |
| 5103 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5104 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5105 | { |
| 5106 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5107 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5108 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5109 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5110 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5111 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5112 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5113 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5114 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5115 | case -NFS4ERR_ADMIN_REVOKED: |
| 5116 | case -NFS4ERR_DELEG_REVOKED: |
| 5117 | case -NFS4ERR_BAD_STATEID: |
| 5118 | case -NFS4ERR_OLD_STATEID: |
| 5119 | case -NFS4ERR_STALE_STATEID: |
| 5120 | case -NFS4ERR_EXPIRED: |
| 5121 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5122 | if (data->roc) |
| 5123 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5124 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5125 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5126 | if (nfs4_async_handle_error(task, data->res.server, |
| 5127 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5128 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5129 | return; |
| 5130 | } |
| 5131 | } |
| 5132 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | static void nfs4_delegreturn_release(void *calldata) |
| 5136 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5137 | struct nfs4_delegreturndata *data = calldata; |
| 5138 | |
| 5139 | if (data->roc) |
| 5140 | pnfs_roc_release(data->inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5141 | kfree(calldata); |
| 5142 | } |
| 5143 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5144 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5145 | { |
| 5146 | struct nfs4_delegreturndata *d_data; |
| 5147 | |
| 5148 | d_data = (struct nfs4_delegreturndata *)data; |
| 5149 | |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5150 | if (d_data->roc && |
| 5151 | pnfs_roc_drain(d_data->inode, &d_data->roc_barrier, task)) |
| 5152 | return; |
| 5153 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5154 | nfs4_setup_sequence(d_data->res.server, |
| 5155 | &d_data->args.seq_args, |
| 5156 | &d_data->res.seq_res, |
| 5157 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5158 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5159 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5160 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5161 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5162 | .rpc_call_done = nfs4_delegreturn_done, |
| 5163 | .rpc_release = nfs4_delegreturn_release, |
| 5164 | }; |
| 5165 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5166 | 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] | 5167 | { |
| 5168 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5169 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5170 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5171 | struct rpc_message msg = { |
| 5172 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5173 | .rpc_cred = cred, |
| 5174 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5175 | struct rpc_task_setup task_setup_data = { |
| 5176 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5177 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5178 | .callback_ops = &nfs4_delegreturn_ops, |
| 5179 | .flags = RPC_TASK_ASYNC, |
| 5180 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5181 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5182 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5183 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5184 | if (data == NULL) |
| 5185 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5186 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5187 | data->args.fhandle = &data->fh; |
| 5188 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5189 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5190 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5191 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5192 | data->res.fattr = &data->fattr; |
| 5193 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5194 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5195 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5196 | data->rpc_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5197 | data->inode = inode; |
| 5198 | data->roc = list_empty(&NFS_I(inode)->open_files) ? |
| 5199 | pnfs_roc(inode) : false; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5200 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5201 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5202 | msg.rpc_argp = &data->args; |
| 5203 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5204 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5205 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5206 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5207 | if (!issync) |
| 5208 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5209 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5210 | if (status != 0) |
| 5211 | goto out; |
| 5212 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5213 | if (status == 0) |
| 5214 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5215 | else |
| 5216 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5217 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5218 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5219 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | } |
| 5221 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5222 | 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] | 5223 | { |
| 5224 | struct nfs_server *server = NFS_SERVER(inode); |
| 5225 | struct nfs4_exception exception = { }; |
| 5226 | int err; |
| 5227 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5228 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5229 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | switch (err) { |
| 5231 | case -NFS4ERR_STALE_STATEID: |
| 5232 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5233 | case 0: |
| 5234 | return 0; |
| 5235 | } |
| 5236 | err = nfs4_handle_exception(server, err, &exception); |
| 5237 | } while (exception.retry); |
| 5238 | return err; |
| 5239 | } |
| 5240 | |
| 5241 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5242 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5243 | |
| 5244 | /* |
| 5245 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5246 | */ |
| 5247 | static unsigned long |
| 5248 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5249 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5250 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | timeout <<= 1; |
| 5252 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5253 | return NFS4_LOCK_MAXTIMEOUT; |
| 5254 | return timeout; |
| 5255 | } |
| 5256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5258 | { |
| 5259 | struct inode *inode = state->inode; |
| 5260 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5261 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5262 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5264 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5265 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5266 | struct nfs_lockt_res res = { |
| 5267 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5268 | }; |
| 5269 | struct rpc_message msg = { |
| 5270 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5271 | .rpc_argp = &arg, |
| 5272 | .rpc_resp = &res, |
| 5273 | .rpc_cred = state->owner->so_cred, |
| 5274 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 | struct nfs4_lock_state *lsp; |
| 5276 | int status; |
| 5277 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5278 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5279 | status = nfs4_set_lock_state(state, request); |
| 5280 | if (status != 0) |
| 5281 | goto out; |
| 5282 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5283 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5284 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5285 | 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] | 5286 | switch (status) { |
| 5287 | case 0: |
| 5288 | request->fl_type = F_UNLCK; |
| 5289 | break; |
| 5290 | case -NFS4ERR_DENIED: |
| 5291 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5293 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5294 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5295 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | return status; |
| 5297 | } |
| 5298 | |
| 5299 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5300 | { |
| 5301 | struct nfs4_exception exception = { }; |
| 5302 | int err; |
| 5303 | |
| 5304 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5305 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5306 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5307 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5308 | &exception); |
| 5309 | } while (exception.retry); |
| 5310 | return err; |
| 5311 | } |
| 5312 | |
| 5313 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5314 | { |
| 5315 | int res = 0; |
| 5316 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5317 | case FL_POSIX: |
| 5318 | res = posix_lock_file_wait(file, fl); |
| 5319 | break; |
| 5320 | case FL_FLOCK: |
| 5321 | res = flock_lock_file_wait(file, fl); |
| 5322 | break; |
| 5323 | default: |
| 5324 | BUG(); |
| 5325 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | return res; |
| 5327 | } |
| 5328 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5329 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5330 | struct nfs_locku_args arg; |
| 5331 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5332 | struct nfs4_lock_state *lsp; |
| 5333 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5334 | struct file_lock fl; |
| 5335 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5336 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5337 | }; |
| 5338 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5339 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5340 | struct nfs_open_context *ctx, |
| 5341 | struct nfs4_lock_state *lsp, |
| 5342 | struct nfs_seqid *seqid) |
| 5343 | { |
| 5344 | struct nfs4_unlockdata *p; |
| 5345 | struct inode *inode = lsp->ls_state->inode; |
| 5346 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5347 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5348 | if (p == NULL) |
| 5349 | return NULL; |
| 5350 | p->arg.fh = NFS_FH(inode); |
| 5351 | p->arg.fl = &p->fl; |
| 5352 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5353 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5354 | p->arg.stateid = &lsp->ls_stateid; |
| 5355 | p->lsp = lsp; |
| 5356 | atomic_inc(&lsp->ls_count); |
| 5357 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5358 | p->ctx = get_nfs_open_context(ctx); |
| 5359 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5360 | p->server = NFS_SERVER(inode); |
| 5361 | return p; |
| 5362 | } |
| 5363 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5364 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5365 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5366 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5367 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5368 | nfs4_put_lock_state(calldata->lsp); |
| 5369 | put_nfs_open_context(calldata->ctx); |
| 5370 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5371 | } |
| 5372 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5373 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5374 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5375 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5376 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5377 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5378 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5379 | switch (task->tk_status) { |
| 5380 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5381 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5382 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5383 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5384 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5385 | case -NFS4ERR_BAD_STATEID: |
| 5386 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5387 | case -NFS4ERR_STALE_STATEID: |
| 5388 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5389 | break; |
| 5390 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5391 | if (nfs4_async_handle_error(task, calldata->server, |
| 5392 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5393 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5394 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5395 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5396 | } |
| 5397 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5398 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5399 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5400 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5401 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5402 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5403 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5404 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5405 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5406 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5407 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5408 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5409 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5410 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5411 | &calldata->res.seq_res, |
| 5412 | task) != 0) |
| 5413 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5414 | return; |
| 5415 | out_no_action: |
| 5416 | task->tk_action = NULL; |
| 5417 | out_wait: |
| 5418 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5419 | } |
| 5420 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5421 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5422 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5423 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5424 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5425 | }; |
| 5426 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5427 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5428 | struct nfs_open_context *ctx, |
| 5429 | struct nfs4_lock_state *lsp, |
| 5430 | struct nfs_seqid *seqid) |
| 5431 | { |
| 5432 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5433 | struct rpc_message msg = { |
| 5434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5435 | .rpc_cred = ctx->cred, |
| 5436 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5437 | struct rpc_task_setup task_setup_data = { |
| 5438 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5439 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5440 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5441 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5442 | .flags = RPC_TASK_ASYNC, |
| 5443 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5444 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5445 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5446 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5447 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5448 | /* Ensure this is an unlock - when canceling a lock, the |
| 5449 | * canceled lock is passed in, and it won't be an unlock. |
| 5450 | */ |
| 5451 | fl->fl_type = F_UNLCK; |
| 5452 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5453 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5454 | if (data == NULL) { |
| 5455 | nfs_free_seqid(seqid); |
| 5456 | return ERR_PTR(-ENOMEM); |
| 5457 | } |
| 5458 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5459 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5460 | msg.rpc_argp = &data->arg; |
| 5461 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5462 | task_setup_data.callback_data = data; |
| 5463 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5464 | } |
| 5465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5467 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5468 | struct inode *inode = state->inode; |
| 5469 | struct nfs4_state_owner *sp = state->owner; |
| 5470 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5471 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5472 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5473 | struct rpc_task *task; |
| 5474 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5475 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5476 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5477 | status = nfs4_set_lock_state(state, request); |
| 5478 | /* Unlock _before_ we do the RPC call */ |
| 5479 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5480 | /* Exclude nfs_delegation_claim_locks() */ |
| 5481 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5482 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5483 | down_read(&nfsi->rwsem); |
| 5484 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5485 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5486 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5487 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5488 | } |
| 5489 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5490 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5491 | if (status != 0) |
| 5492 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5493 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5494 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5495 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5496 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5497 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5498 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5499 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5500 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5501 | 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] | 5502 | status = PTR_ERR(task); |
| 5503 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5504 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5505 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5506 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5507 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5508 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5509 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5510 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5511 | } |
| 5512 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5513 | struct nfs4_lockdata { |
| 5514 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5515 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5516 | struct nfs4_lock_state *lsp; |
| 5517 | struct nfs_open_context *ctx; |
| 5518 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5519 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5520 | int rpc_status; |
| 5521 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5522 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5523 | }; |
| 5524 | |
| 5525 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5526 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5527 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5528 | { |
| 5529 | struct nfs4_lockdata *p; |
| 5530 | struct inode *inode = lsp->ls_state->inode; |
| 5531 | struct nfs_server *server = NFS_SERVER(inode); |
| 5532 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5533 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5534 | if (p == NULL) |
| 5535 | return NULL; |
| 5536 | |
| 5537 | p->arg.fh = NFS_FH(inode); |
| 5538 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5539 | 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] | 5540 | if (p->arg.open_seqid == NULL) |
| 5541 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5542 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5543 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5544 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5545 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5546 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5547 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5548 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5549 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5550 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5551 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5552 | atomic_inc(&lsp->ls_count); |
| 5553 | p->ctx = get_nfs_open_context(ctx); |
| 5554 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5555 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5556 | out_free_seqid: |
| 5557 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5558 | out_free: |
| 5559 | kfree(p); |
| 5560 | return NULL; |
| 5561 | } |
| 5562 | |
| 5563 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5564 | { |
| 5565 | struct nfs4_lockdata *data = calldata; |
| 5566 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5568 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5569 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5570 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5571 | /* Do we need to do an open_to_lock_owner? */ |
| 5572 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5573 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5574 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5575 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5576 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5577 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5578 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5579 | } else |
| 5580 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5581 | if (!nfs4_valid_open_stateid(state)) { |
| 5582 | data->rpc_status = -EBADF; |
| 5583 | task->tk_action = NULL; |
| 5584 | goto out_release_open_seqid; |
| 5585 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5586 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5587 | if (nfs4_setup_sequence(data->server, |
| 5588 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5589 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5590 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5591 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5592 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5593 | nfs_release_seqid(data->arg.open_seqid); |
| 5594 | out_release_lock_seqid: |
| 5595 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5596 | out_wait: |
| 5597 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5598 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5599 | } |
| 5600 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5601 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5602 | { |
| 5603 | struct nfs4_lockdata *data = calldata; |
| 5604 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5605 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5606 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5607 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5608 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5609 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5610 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5611 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5612 | if (data->rpc_status == 0) |
| 5613 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5614 | else |
| 5615 | goto out; |
| 5616 | } |
| 5617 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5618 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5619 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5620 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5621 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5622 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5623 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | static void nfs4_lock_release(void *calldata) |
| 5627 | { |
| 5628 | struct nfs4_lockdata *data = calldata; |
| 5629 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5630 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5631 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5632 | if (data->cancelled != 0) { |
| 5633 | struct rpc_task *task; |
| 5634 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5635 | data->arg.lock_seqid); |
| 5636 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5637 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5638 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5639 | } else |
| 5640 | nfs_free_seqid(data->arg.lock_seqid); |
| 5641 | nfs4_put_lock_state(data->lsp); |
| 5642 | put_nfs_open_context(data->ctx); |
| 5643 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5644 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5648 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5649 | .rpc_call_done = nfs4_lock_done, |
| 5650 | .rpc_release = nfs4_lock_release, |
| 5651 | }; |
| 5652 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5653 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5654 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5655 | switch (error) { |
| 5656 | case -NFS4ERR_ADMIN_REVOKED: |
| 5657 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5658 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5659 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5660 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5661 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5662 | break; |
| 5663 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5664 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5665 | case -NFS4ERR_EXPIRED: |
| 5666 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5667 | }; |
| 5668 | } |
| 5669 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5670 | 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] | 5671 | { |
| 5672 | struct nfs4_lockdata *data; |
| 5673 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5674 | struct rpc_message msg = { |
| 5675 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5676 | .rpc_cred = state->owner->so_cred, |
| 5677 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5678 | struct rpc_task_setup task_setup_data = { |
| 5679 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5680 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5681 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5682 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5683 | .flags = RPC_TASK_ASYNC, |
| 5684 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5685 | int ret; |
| 5686 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5687 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5688 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5689 | fl->fl_u.nfs4_fl.owner, |
| 5690 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5691 | if (data == NULL) |
| 5692 | return -ENOMEM; |
| 5693 | if (IS_SETLKW(cmd)) |
| 5694 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5695 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5696 | msg.rpc_argp = &data->arg; |
| 5697 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5698 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5699 | if (recovery_type > NFS_LOCK_NEW) { |
| 5700 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5701 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5702 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5703 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5704 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5705 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5706 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5707 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5708 | if (ret == 0) { |
| 5709 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5710 | if (ret) |
| 5711 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5712 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5713 | } else |
| 5714 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5715 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5716 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5717 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5721 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5722 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5723 | struct nfs4_exception exception = { |
| 5724 | .inode = state->inode, |
| 5725 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5726 | int err; |
| 5727 | |
| 5728 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5729 | /* Cache the lock if possible... */ |
| 5730 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5731 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5732 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5733 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5734 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5735 | break; |
| 5736 | nfs4_handle_exception(server, err, &exception); |
| 5737 | } while (exception.retry); |
| 5738 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5742 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5743 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5744 | struct nfs4_exception exception = { |
| 5745 | .inode = state->inode, |
| 5746 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5747 | int err; |
| 5748 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5749 | err = nfs4_set_lock_state(state, request); |
| 5750 | if (err != 0) |
| 5751 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 5752 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5753 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 5754 | return 0; |
| 5755 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5756 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5757 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5758 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5759 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5760 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5761 | switch (err) { |
| 5762 | default: |
| 5763 | goto out; |
| 5764 | case -NFS4ERR_GRACE: |
| 5765 | case -NFS4ERR_DELAY: |
| 5766 | nfs4_handle_exception(server, err, &exception); |
| 5767 | err = 0; |
| 5768 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5769 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5770 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5771 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5772 | } |
| 5773 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5774 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5775 | /** |
| 5776 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5777 | * |
| 5778 | * @state: NFSv4 state for an inode |
| 5779 | * |
| 5780 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5781 | * Otherwise a negative NFS4ERR value is returned. |
| 5782 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5783 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5784 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5785 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5786 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5787 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5788 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5789 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5790 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5791 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5792 | |
| 5793 | status = nfs41_test_stateid(server, |
| 5794 | &lsp->ls_stateid, |
| 5795 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5796 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5797 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5798 | /* Free the stateid unless the server |
| 5799 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5800 | if (status != -NFS4ERR_BAD_STATEID) |
| 5801 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5802 | &lsp->ls_stateid, |
| 5803 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5804 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5805 | ret = status; |
| 5806 | } |
| 5807 | } |
| 5808 | }; |
| 5809 | |
| 5810 | return ret; |
| 5811 | } |
| 5812 | |
| 5813 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5814 | { |
| 5815 | int status = NFS_OK; |
| 5816 | |
| 5817 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5818 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5819 | if (status != NFS_OK) |
| 5820 | status = nfs4_lock_expired(state, request); |
| 5821 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5822 | } |
| 5823 | #endif |
| 5824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5826 | { |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5827 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5828 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5829 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5830 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5831 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5832 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5833 | if ((fl_flags & FL_POSIX) && |
| 5834 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5835 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5836 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5837 | status = nfs4_set_lock_state(state, request); |
| 5838 | if (status != 0) |
| 5839 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5840 | request->fl_flags |= FL_ACCESS; |
| 5841 | status = do_vfs_lock(request->fl_file, request); |
| 5842 | if (status < 0) |
| 5843 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5844 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5845 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5846 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5847 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5848 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5849 | status = do_vfs_lock(request->fl_file, request); |
| 5850 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5851 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5852 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5853 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5854 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5855 | if (status != 0) |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5856 | goto out; |
| 5857 | down_read(&nfsi->rwsem); |
| 5858 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5859 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5860 | goto out_unlock; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5861 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5862 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5863 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5864 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5865 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5866 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5867 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5868 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5869 | out: |
| 5870 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | return status; |
| 5872 | } |
| 5873 | |
| 5874 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5875 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5876 | struct nfs4_exception exception = { |
| 5877 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5878 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5879 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | int err; |
| 5881 | |
| 5882 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5883 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5884 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5885 | if (err == -NFS4ERR_DENIED) |
| 5886 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5887 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5888 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5889 | } while (exception.retry); |
| 5890 | return err; |
| 5891 | } |
| 5892 | |
| 5893 | static int |
| 5894 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5895 | { |
| 5896 | struct nfs_open_context *ctx; |
| 5897 | struct nfs4_state *state; |
| 5898 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5899 | int status; |
| 5900 | |
| 5901 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5902 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5903 | state = ctx->state; |
| 5904 | |
| 5905 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5906 | return -EINVAL; |
| 5907 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5908 | if (IS_GETLK(cmd)) { |
| 5909 | if (state != NULL) |
| 5910 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5911 | return 0; |
| 5912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5913 | |
| 5914 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5915 | return -EINVAL; |
| 5916 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5917 | if (request->fl_type == F_UNLCK) { |
| 5918 | if (state != NULL) |
| 5919 | return nfs4_proc_unlck(state, cmd, request); |
| 5920 | return 0; |
| 5921 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5923 | if (state == NULL) |
| 5924 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5925 | /* |
| 5926 | * Don't rely on the VFS having checked the file open mode, |
| 5927 | * since it won't do this for flock() locks. |
| 5928 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5929 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5930 | case F_RDLCK: |
| 5931 | if (!(filp->f_mode & FMODE_READ)) |
| 5932 | return -EBADF; |
| 5933 | break; |
| 5934 | case F_WRLCK: |
| 5935 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5936 | return -EBADF; |
| 5937 | } |
| 5938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | do { |
| 5940 | status = nfs4_proc_setlk(state, cmd, request); |
| 5941 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5942 | break; |
| 5943 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5944 | status = -ERESTARTSYS; |
| 5945 | if (signalled()) |
| 5946 | break; |
| 5947 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5948 | return status; |
| 5949 | } |
| 5950 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5951 | 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] | 5952 | { |
| 5953 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5954 | int err; |
| 5955 | |
| 5956 | err = nfs4_set_lock_state(state, fl); |
| 5957 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5958 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5959 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5960 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5961 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5962 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5963 | struct nfs_release_lockowner_data { |
| 5964 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5965 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5966 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 5967 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5968 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5969 | }; |
| 5970 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5971 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 5972 | { |
| 5973 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 5974 | struct nfs_server *server = data->server; |
| 5975 | nfs40_setup_sequence(server, &data->args.seq_args, |
| 5976 | &data->res.seq_res, task); |
| 5977 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5978 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 5982 | { |
| 5983 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5984 | struct nfs_server *server = data->server; |
| 5985 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 5986 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5987 | |
| 5988 | switch (task->tk_status) { |
| 5989 | case 0: |
| 5990 | renew_lease(server, data->timestamp); |
| 5991 | break; |
| 5992 | case -NFS4ERR_STALE_CLIENTID: |
| 5993 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 5994 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5995 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 5996 | case -NFS4ERR_LEASE_MOVED: |
| 5997 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5998 | if (nfs4_async_handle_error(task, server, |
| 5999 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6000 | rpc_restart_call_prepare(task); |
| 6001 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6002 | } |
| 6003 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6004 | static void nfs4_release_lockowner_release(void *calldata) |
| 6005 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6006 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6007 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6008 | kfree(calldata); |
| 6009 | } |
| 6010 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6011 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6012 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6013 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6014 | .rpc_release = nfs4_release_lockowner_release, |
| 6015 | }; |
| 6016 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6017 | static void |
| 6018 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6019 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6020 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6021 | struct rpc_message msg = { |
| 6022 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6023 | }; |
| 6024 | |
| 6025 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6026 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6027 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6028 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6029 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6030 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6031 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6032 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6033 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6034 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6035 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6036 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6037 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6038 | msg.rpc_resp = &data->res; |
| 6039 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6040 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6041 | } |
| 6042 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6043 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6044 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6045 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 6046 | const void *buf, size_t buflen, |
| 6047 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6048 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6049 | if (strcmp(key, "") != 0) |
| 6050 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6051 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6052 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6053 | } |
| 6054 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6055 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 6056 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 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 | if (strcmp(key, "") != 0) |
| 6059 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6060 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6061 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6062 | } |
| 6063 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6064 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 6065 | size_t list_len, const char *name, |
| 6066 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6067 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6068 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6069 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 6070 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 6071 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6072 | |
| 6073 | if (list && len <= list_len) |
| 6074 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6075 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6076 | } |
| 6077 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6078 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 6079 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 6080 | { |
| 6081 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 6082 | } |
| 6083 | |
| 6084 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 6085 | const void *buf, size_t buflen, |
| 6086 | int flags, int type) |
| 6087 | { |
| 6088 | if (security_ismaclabel(key)) |
| 6089 | return nfs4_set_security_label(dentry, buf, buflen); |
| 6090 | |
| 6091 | return -EOPNOTSUPP; |
| 6092 | } |
| 6093 | |
| 6094 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 6095 | void *buf, size_t buflen, int type) |
| 6096 | { |
| 6097 | if (security_ismaclabel(key)) |
| 6098 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 6099 | return -EOPNOTSUPP; |
| 6100 | } |
| 6101 | |
| 6102 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 6103 | size_t list_len, const char *name, |
| 6104 | size_t name_len, int type) |
| 6105 | { |
| 6106 | size_t len = 0; |
| 6107 | |
| 6108 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 6109 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 6110 | if (list && len <= list_len) |
| 6111 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 6112 | } |
| 6113 | return len; |
| 6114 | } |
| 6115 | |
| 6116 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6117 | .prefix = XATTR_SECURITY_PREFIX, |
| 6118 | .list = nfs4_xattr_list_nfs4_label, |
| 6119 | .get = nfs4_xattr_get_nfs4_label, |
| 6120 | .set = nfs4_xattr_set_nfs4_label, |
| 6121 | }; |
| 6122 | #endif |
| 6123 | |
| 6124 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6125 | /* |
| 6126 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6127 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6128 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6129 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6130 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6131 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6132 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6133 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6134 | return; |
| 6135 | |
| 6136 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6137 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6138 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6139 | fattr->nlink = 2; |
| 6140 | } |
| 6141 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6142 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6143 | const struct qstr *name, |
| 6144 | struct nfs4_fs_locations *fs_locations, |
| 6145 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6146 | { |
| 6147 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6148 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6149 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6150 | }; |
| 6151 | struct nfs4_fs_locations_arg args = { |
| 6152 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6153 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6154 | .page = page, |
| 6155 | .bitmask = bitmask, |
| 6156 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6157 | struct nfs4_fs_locations_res res = { |
| 6158 | .fs_locations = fs_locations, |
| 6159 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6160 | struct rpc_message msg = { |
| 6161 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6162 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6163 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6164 | }; |
| 6165 | int status; |
| 6166 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6167 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6168 | |
| 6169 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6170 | * is not supported */ |
| 6171 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6172 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6173 | else |
| 6174 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6175 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6176 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6177 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6178 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6179 | 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] | 6180 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6181 | return status; |
| 6182 | } |
| 6183 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6184 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6185 | const struct qstr *name, |
| 6186 | struct nfs4_fs_locations *fs_locations, |
| 6187 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6188 | { |
| 6189 | struct nfs4_exception exception = { }; |
| 6190 | int err; |
| 6191 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6192 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6193 | fs_locations, page); |
| 6194 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6195 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6196 | &exception); |
| 6197 | } while (exception.retry); |
| 6198 | return err; |
| 6199 | } |
| 6200 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6201 | /* |
| 6202 | * This operation also signals the server that this client is |
| 6203 | * performing migration recovery. The server can stop returning |
| 6204 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6205 | * appended to this compound to identify the client ID which is |
| 6206 | * performing recovery. |
| 6207 | */ |
| 6208 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6209 | struct nfs4_fs_locations *locations, |
| 6210 | struct page *page, struct rpc_cred *cred) |
| 6211 | { |
| 6212 | struct nfs_server *server = NFS_SERVER(inode); |
| 6213 | struct rpc_clnt *clnt = server->client; |
| 6214 | u32 bitmask[2] = { |
| 6215 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6216 | }; |
| 6217 | struct nfs4_fs_locations_arg args = { |
| 6218 | .clientid = server->nfs_client->cl_clientid, |
| 6219 | .fh = NFS_FH(inode), |
| 6220 | .page = page, |
| 6221 | .bitmask = bitmask, |
| 6222 | .migration = 1, /* skip LOOKUP */ |
| 6223 | .renew = 1, /* append RENEW */ |
| 6224 | }; |
| 6225 | struct nfs4_fs_locations_res res = { |
| 6226 | .fs_locations = locations, |
| 6227 | .migration = 1, |
| 6228 | .renew = 1, |
| 6229 | }; |
| 6230 | struct rpc_message msg = { |
| 6231 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6232 | .rpc_argp = &args, |
| 6233 | .rpc_resp = &res, |
| 6234 | .rpc_cred = cred, |
| 6235 | }; |
| 6236 | unsigned long now = jiffies; |
| 6237 | int status; |
| 6238 | |
| 6239 | nfs_fattr_init(&locations->fattr); |
| 6240 | locations->server = server; |
| 6241 | locations->nlocations = 0; |
| 6242 | |
| 6243 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6244 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6245 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6246 | &args.seq_args, &res.seq_res); |
| 6247 | if (status) |
| 6248 | return status; |
| 6249 | |
| 6250 | renew_lease(server, now); |
| 6251 | return 0; |
| 6252 | } |
| 6253 | |
| 6254 | #ifdef CONFIG_NFS_V4_1 |
| 6255 | |
| 6256 | /* |
| 6257 | * This operation also signals the server that this client is |
| 6258 | * performing migration recovery. The server can stop asserting |
| 6259 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6260 | * performing this operation is identified in the SEQUENCE |
| 6261 | * operation in this compound. |
| 6262 | * |
| 6263 | * When the client supports GETATTR(fs_locations_info), it can |
| 6264 | * be plumbed in here. |
| 6265 | */ |
| 6266 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6267 | struct nfs4_fs_locations *locations, |
| 6268 | struct page *page, struct rpc_cred *cred) |
| 6269 | { |
| 6270 | struct nfs_server *server = NFS_SERVER(inode); |
| 6271 | struct rpc_clnt *clnt = server->client; |
| 6272 | u32 bitmask[2] = { |
| 6273 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6274 | }; |
| 6275 | struct nfs4_fs_locations_arg args = { |
| 6276 | .fh = NFS_FH(inode), |
| 6277 | .page = page, |
| 6278 | .bitmask = bitmask, |
| 6279 | .migration = 1, /* skip LOOKUP */ |
| 6280 | }; |
| 6281 | struct nfs4_fs_locations_res res = { |
| 6282 | .fs_locations = locations, |
| 6283 | .migration = 1, |
| 6284 | }; |
| 6285 | struct rpc_message msg = { |
| 6286 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6287 | .rpc_argp = &args, |
| 6288 | .rpc_resp = &res, |
| 6289 | .rpc_cred = cred, |
| 6290 | }; |
| 6291 | int status; |
| 6292 | |
| 6293 | nfs_fattr_init(&locations->fattr); |
| 6294 | locations->server = server; |
| 6295 | locations->nlocations = 0; |
| 6296 | |
| 6297 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6298 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6299 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6300 | &args.seq_args, &res.seq_res); |
| 6301 | if (status == NFS4_OK && |
| 6302 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6303 | status = -NFS4ERR_LEASE_MOVED; |
| 6304 | return status; |
| 6305 | } |
| 6306 | |
| 6307 | #endif /* CONFIG_NFS_V4_1 */ |
| 6308 | |
| 6309 | /** |
| 6310 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6311 | * @inode: inode on FSID that is migrating |
| 6312 | * @locations: result of query |
| 6313 | * @page: buffer |
| 6314 | * @cred: credential to use for this operation |
| 6315 | * |
| 6316 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6317 | * operation failed, or a negative errno if a local error occurred. |
| 6318 | * |
| 6319 | * On success, "locations" is filled in, but if the server has |
| 6320 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6321 | * asserted. |
| 6322 | * |
| 6323 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6324 | * from this client that require migration recovery. |
| 6325 | */ |
| 6326 | int nfs4_proc_get_locations(struct inode *inode, |
| 6327 | struct nfs4_fs_locations *locations, |
| 6328 | struct page *page, struct rpc_cred *cred) |
| 6329 | { |
| 6330 | struct nfs_server *server = NFS_SERVER(inode); |
| 6331 | struct nfs_client *clp = server->nfs_client; |
| 6332 | const struct nfs4_mig_recovery_ops *ops = |
| 6333 | clp->cl_mvops->mig_recovery_ops; |
| 6334 | struct nfs4_exception exception = { }; |
| 6335 | int status; |
| 6336 | |
| 6337 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6338 | (unsigned long long)server->fsid.major, |
| 6339 | (unsigned long long)server->fsid.minor, |
| 6340 | clp->cl_hostname); |
| 6341 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6342 | |
| 6343 | do { |
| 6344 | status = ops->get_locations(inode, locations, page, cred); |
| 6345 | if (status != -NFS4ERR_DELAY) |
| 6346 | break; |
| 6347 | nfs4_handle_exception(server, status, &exception); |
| 6348 | } while (exception.retry); |
| 6349 | return status; |
| 6350 | } |
| 6351 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6352 | /* |
| 6353 | * This operation also signals the server that this client is |
| 6354 | * performing "lease moved" recovery. The server can stop |
| 6355 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6356 | * is appended to this compound to identify the client ID which is |
| 6357 | * performing recovery. |
| 6358 | */ |
| 6359 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6360 | { |
| 6361 | struct nfs_server *server = NFS_SERVER(inode); |
| 6362 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6363 | struct rpc_clnt *clnt = server->client; |
| 6364 | struct nfs4_fsid_present_arg args = { |
| 6365 | .fh = NFS_FH(inode), |
| 6366 | .clientid = clp->cl_clientid, |
| 6367 | .renew = 1, /* append RENEW */ |
| 6368 | }; |
| 6369 | struct nfs4_fsid_present_res res = { |
| 6370 | .renew = 1, |
| 6371 | }; |
| 6372 | struct rpc_message msg = { |
| 6373 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6374 | .rpc_argp = &args, |
| 6375 | .rpc_resp = &res, |
| 6376 | .rpc_cred = cred, |
| 6377 | }; |
| 6378 | unsigned long now = jiffies; |
| 6379 | int status; |
| 6380 | |
| 6381 | res.fh = nfs_alloc_fhandle(); |
| 6382 | if (res.fh == NULL) |
| 6383 | return -ENOMEM; |
| 6384 | |
| 6385 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6386 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6387 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6388 | &args.seq_args, &res.seq_res); |
| 6389 | nfs_free_fhandle(res.fh); |
| 6390 | if (status) |
| 6391 | return status; |
| 6392 | |
| 6393 | do_renew_lease(clp, now); |
| 6394 | return 0; |
| 6395 | } |
| 6396 | |
| 6397 | #ifdef CONFIG_NFS_V4_1 |
| 6398 | |
| 6399 | /* |
| 6400 | * This operation also signals the server that this client is |
| 6401 | * performing "lease moved" recovery. The server can stop asserting |
| 6402 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6403 | * this operation is identified in the SEQUENCE operation in this |
| 6404 | * compound. |
| 6405 | */ |
| 6406 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6407 | { |
| 6408 | struct nfs_server *server = NFS_SERVER(inode); |
| 6409 | struct rpc_clnt *clnt = server->client; |
| 6410 | struct nfs4_fsid_present_arg args = { |
| 6411 | .fh = NFS_FH(inode), |
| 6412 | }; |
| 6413 | struct nfs4_fsid_present_res res = { |
| 6414 | }; |
| 6415 | struct rpc_message msg = { |
| 6416 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6417 | .rpc_argp = &args, |
| 6418 | .rpc_resp = &res, |
| 6419 | .rpc_cred = cred, |
| 6420 | }; |
| 6421 | int status; |
| 6422 | |
| 6423 | res.fh = nfs_alloc_fhandle(); |
| 6424 | if (res.fh == NULL) |
| 6425 | return -ENOMEM; |
| 6426 | |
| 6427 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6428 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6429 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6430 | &args.seq_args, &res.seq_res); |
| 6431 | nfs_free_fhandle(res.fh); |
| 6432 | if (status == NFS4_OK && |
| 6433 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6434 | status = -NFS4ERR_LEASE_MOVED; |
| 6435 | return status; |
| 6436 | } |
| 6437 | |
| 6438 | #endif /* CONFIG_NFS_V4_1 */ |
| 6439 | |
| 6440 | /** |
| 6441 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6442 | * @inode: inode on FSID to check |
| 6443 | * @cred: credential to use for this operation |
| 6444 | * |
| 6445 | * Server indicates whether the FSID is present, moved, or not |
| 6446 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6447 | * condition for this client ID. |
| 6448 | * |
| 6449 | * Returns NFS4_OK if the FSID is present on this server, |
| 6450 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6451 | * NFS4ERR code if some error occurred on the server, or a |
| 6452 | * negative errno if a local failure occurred. |
| 6453 | */ |
| 6454 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6455 | { |
| 6456 | struct nfs_server *server = NFS_SERVER(inode); |
| 6457 | struct nfs_client *clp = server->nfs_client; |
| 6458 | const struct nfs4_mig_recovery_ops *ops = |
| 6459 | clp->cl_mvops->mig_recovery_ops; |
| 6460 | struct nfs4_exception exception = { }; |
| 6461 | int status; |
| 6462 | |
| 6463 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6464 | (unsigned long long)server->fsid.major, |
| 6465 | (unsigned long long)server->fsid.minor, |
| 6466 | clp->cl_hostname); |
| 6467 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6468 | |
| 6469 | do { |
| 6470 | status = ops->fsid_present(inode, cred); |
| 6471 | if (status != -NFS4ERR_DELAY) |
| 6472 | break; |
| 6473 | nfs4_handle_exception(server, status, &exception); |
| 6474 | } while (exception.retry); |
| 6475 | return status; |
| 6476 | } |
| 6477 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6478 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6479 | * If 'use_integrity' is true and the state managment nfs_client |
| 6480 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6481 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6482 | * Considerations sections. Otherwise, just use the user cred with the |
| 6483 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6484 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6485 | 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] | 6486 | { |
| 6487 | int status; |
| 6488 | struct nfs4_secinfo_arg args = { |
| 6489 | .dir_fh = NFS_FH(dir), |
| 6490 | .name = name, |
| 6491 | }; |
| 6492 | struct nfs4_secinfo_res res = { |
| 6493 | .flavors = flavors, |
| 6494 | }; |
| 6495 | struct rpc_message msg = { |
| 6496 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6497 | .rpc_argp = &args, |
| 6498 | .rpc_resp = &res, |
| 6499 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6500 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6501 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6502 | |
| 6503 | if (use_integrity) { |
| 6504 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6505 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6506 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6507 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6508 | |
| 6509 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6510 | |
| 6511 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6512 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6513 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6514 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6515 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6516 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6517 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6518 | if (cred) |
| 6519 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6520 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6521 | return status; |
| 6522 | } |
| 6523 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6524 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6525 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6526 | { |
| 6527 | struct nfs4_exception exception = { }; |
| 6528 | int err; |
| 6529 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6530 | err = -NFS4ERR_WRONGSEC; |
| 6531 | |
| 6532 | /* try to use integrity protection with machine cred */ |
| 6533 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6534 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6535 | |
| 6536 | /* |
| 6537 | * if unable to use integrity protection, or SECINFO with |
| 6538 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6539 | * disallowed by spec, but exists in deployed servers) use |
| 6540 | * the current filesystem's rpc_client and the user cred. |
| 6541 | */ |
| 6542 | if (err == -NFS4ERR_WRONGSEC) |
| 6543 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6544 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6545 | trace_nfs4_secinfo(dir, name, err); |
| 6546 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6547 | &exception); |
| 6548 | } while (exception.retry); |
| 6549 | return err; |
| 6550 | } |
| 6551 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6552 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6553 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6554 | * Check the exchange flags returned by the server for invalid flags, having |
| 6555 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6556 | * DS flags set. |
| 6557 | */ |
| 6558 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6559 | { |
| 6560 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6561 | goto out_inval; |
| 6562 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6563 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6564 | goto out_inval; |
| 6565 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6566 | goto out_inval; |
| 6567 | return NFS_OK; |
| 6568 | out_inval: |
| 6569 | return -NFS4ERR_INVAL; |
| 6570 | } |
| 6571 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6572 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6573 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6574 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6575 | { |
| 6576 | if (a->server_scope_sz == b->server_scope_sz && |
| 6577 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6578 | return true; |
| 6579 | |
| 6580 | return false; |
| 6581 | } |
| 6582 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6583 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6584 | * nfs4_proc_bind_conn_to_session() |
| 6585 | * |
| 6586 | * The 4.1 client currently uses the same TCP connection for the |
| 6587 | * fore and backchannel. |
| 6588 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6589 | 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] | 6590 | { |
| 6591 | int status; |
| 6592 | struct nfs41_bind_conn_to_session_res res; |
| 6593 | struct rpc_message msg = { |
| 6594 | .rpc_proc = |
| 6595 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 6596 | .rpc_argp = clp, |
| 6597 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6598 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6599 | }; |
| 6600 | |
| 6601 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6602 | |
| 6603 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 6604 | if (unlikely(res.session == NULL)) { |
| 6605 | status = -ENOMEM; |
| 6606 | goto out; |
| 6607 | } |
| 6608 | |
| 6609 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6610 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6611 | if (status == 0) { |
| 6612 | if (memcmp(res.session->sess_id.data, |
| 6613 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6614 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6615 | status = -EIO; |
| 6616 | goto out_session; |
| 6617 | } |
| 6618 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 6619 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6620 | __func__); |
| 6621 | status = -EIO; |
| 6622 | goto out_session; |
| 6623 | } |
| 6624 | if (res.use_conn_in_rdma_mode) { |
| 6625 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6626 | __func__); |
| 6627 | status = -EIO; |
| 6628 | goto out_session; |
| 6629 | } |
| 6630 | } |
| 6631 | out_session: |
| 6632 | kfree(res.session); |
| 6633 | out: |
| 6634 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6635 | return status; |
| 6636 | } |
| 6637 | |
| 6638 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6639 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6640 | * 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] | 6641 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6642 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6643 | .how = SP4_MACH_CRED, |
| 6644 | .enforce.u.words = { |
| 6645 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6646 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6647 | 1 << (OP_CREATE_SESSION - 32) | |
| 6648 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6649 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6650 | }, |
| 6651 | .allow.u.words = { |
| 6652 | [0] = 1 << (OP_CLOSE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6653 | 1 << (OP_LOCKU) | |
| 6654 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6655 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6656 | 1 << (OP_SECINFO_NO_NAME - 32) | |
| 6657 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6658 | 1 << (OP_FREE_STATEID - 32) | |
| 6659 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6660 | } |
| 6661 | }; |
| 6662 | |
| 6663 | /* |
| 6664 | * Select the state protection mode for client `clp' given the server results |
| 6665 | * from exchange_id in `sp'. |
| 6666 | * |
| 6667 | * Returns 0 on success, negative errno otherwise. |
| 6668 | */ |
| 6669 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6670 | struct nfs41_state_protection *sp) |
| 6671 | { |
| 6672 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6673 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6674 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6675 | 1 << (OP_CREATE_SESSION - 32) | |
| 6676 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6677 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6678 | }; |
| 6679 | unsigned int i; |
| 6680 | |
| 6681 | if (sp->how == SP4_MACH_CRED) { |
| 6682 | /* Print state protect result */ |
| 6683 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6684 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6685 | if (test_bit(i, sp->enforce.u.longs)) |
| 6686 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6687 | if (test_bit(i, sp->allow.u.longs)) |
| 6688 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6689 | } |
| 6690 | |
| 6691 | /* make sure nothing is on enforce list that isn't supported */ |
| 6692 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6693 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6694 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6695 | return -EINVAL; |
| 6696 | } |
| 6697 | } |
| 6698 | |
| 6699 | /* |
| 6700 | * Minimal mode - state operations are allowed to use machine |
| 6701 | * credential. Note this already happens by default, so the |
| 6702 | * client doesn't have to do anything more than the negotiation. |
| 6703 | * |
| 6704 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6705 | * we're already using the machine cred for exchange_id |
| 6706 | * and will never use a different cred. |
| 6707 | */ |
| 6708 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6709 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6710 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6711 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6712 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6713 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6714 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 6715 | } else { |
| 6716 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6717 | return -EINVAL; |
| 6718 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6719 | |
| 6720 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
| 6721 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 6722 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 6723 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 6724 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6725 | |
| 6726 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 6727 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 6728 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 6729 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 6730 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6731 | |
| 6732 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 6733 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 6734 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 6735 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 6736 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6737 | |
| 6738 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 6739 | dfprintk(MOUNT, " write mode enabled\n"); |
| 6740 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 6741 | } |
| 6742 | |
| 6743 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 6744 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 6745 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 6746 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | return 0; |
| 6750 | } |
| 6751 | |
| 6752 | /* |
| 6753 | * _nfs4_proc_exchange_id() |
| 6754 | * |
| 6755 | * Wrapper for EXCHANGE_ID operation. |
| 6756 | */ |
| 6757 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 6758 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6759 | { |
| 6760 | nfs4_verifier verifier; |
| 6761 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6762 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6763 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6764 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6765 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6766 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 6767 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 6768 | #else |
| 6769 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 6770 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 6771 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6772 | }; |
| 6773 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6774 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6775 | }; |
| 6776 | int status; |
| 6777 | struct rpc_message msg = { |
| 6778 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 6779 | .rpc_argp = &args, |
| 6780 | .rpc_resp = &res, |
| 6781 | .rpc_cred = cred, |
| 6782 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6783 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6784 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6785 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 6786 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6787 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 6788 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6789 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6790 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6791 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6792 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6793 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6794 | status = -ENOMEM; |
| 6795 | goto out; |
| 6796 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6797 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6798 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6799 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6800 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6801 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6802 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6803 | } |
| 6804 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6805 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6806 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6807 | status = -ENOMEM; |
| 6808 | goto out_server_scope; |
| 6809 | } |
| 6810 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6811 | switch (sp4_how) { |
| 6812 | case SP4_NONE: |
| 6813 | args.state_protect.how = SP4_NONE; |
| 6814 | break; |
| 6815 | |
| 6816 | case SP4_MACH_CRED: |
| 6817 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 6818 | break; |
| 6819 | |
| 6820 | default: |
| 6821 | /* unsupported! */ |
| 6822 | WARN_ON_ONCE(1); |
| 6823 | status = -EINVAL; |
| 6824 | goto out_server_scope; |
| 6825 | } |
| 6826 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6827 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6828 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6829 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6830 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6831 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6832 | if (status == 0) |
| 6833 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 6834 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6835 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6836 | clp->cl_clientid = res.clientid; |
| 6837 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 6838 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 6839 | clp->cl_seqid = res.seqid; |
| 6840 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6841 | kfree(clp->cl_serverowner); |
| 6842 | clp->cl_serverowner = res.server_owner; |
| 6843 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6844 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6845 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6846 | kfree(clp->cl_implid); |
| 6847 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6848 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6849 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6850 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6851 | res.server_scope)) { |
| 6852 | dprintk("%s: server_scope mismatch detected\n", |
| 6853 | __func__); |
| 6854 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6855 | kfree(clp->cl_serverscope); |
| 6856 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6857 | } |
| 6858 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6859 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6860 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6861 | goto out; |
| 6862 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6863 | } else |
| 6864 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6865 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6866 | out_server_owner: |
| 6867 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6868 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6869 | kfree(res.server_scope); |
| 6870 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6871 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6872 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6873 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6874 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6875 | clp->cl_implid->date.seconds, |
| 6876 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6877 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6878 | return status; |
| 6879 | } |
| 6880 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6881 | /* |
| 6882 | * nfs4_proc_exchange_id() |
| 6883 | * |
| 6884 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6885 | * |
| 6886 | * Since the clientid has expired, all compounds using sessions |
| 6887 | * associated with the stale clientid will be returning |
| 6888 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 6889 | * be in some phase of session reset. |
| 6890 | * |
| 6891 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 6892 | */ |
| 6893 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 6894 | { |
| 6895 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 6896 | int status; |
| 6897 | |
| 6898 | /* try SP4_MACH_CRED if krb5i/p */ |
| 6899 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 6900 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 6901 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 6902 | if (!status) |
| 6903 | return 0; |
| 6904 | } |
| 6905 | |
| 6906 | /* try SP4_NONE */ |
| 6907 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 6908 | } |
| 6909 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6910 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6911 | struct rpc_cred *cred) |
| 6912 | { |
| 6913 | struct rpc_message msg = { |
| 6914 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6915 | .rpc_argp = clp, |
| 6916 | .rpc_cred = cred, |
| 6917 | }; |
| 6918 | int status; |
| 6919 | |
| 6920 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6921 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6922 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6923 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6924 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6925 | return status; |
| 6926 | } |
| 6927 | |
| 6928 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6929 | struct rpc_cred *cred) |
| 6930 | { |
| 6931 | unsigned int loop; |
| 6932 | int ret; |
| 6933 | |
| 6934 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6935 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6936 | switch (ret) { |
| 6937 | case -NFS4ERR_DELAY: |
| 6938 | case -NFS4ERR_CLIENTID_BUSY: |
| 6939 | ssleep(1); |
| 6940 | break; |
| 6941 | default: |
| 6942 | return ret; |
| 6943 | } |
| 6944 | } |
| 6945 | return 0; |
| 6946 | } |
| 6947 | |
| 6948 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6949 | { |
| 6950 | struct rpc_cred *cred; |
| 6951 | int ret = 0; |
| 6952 | |
| 6953 | if (clp->cl_mvops->minor_version < 1) |
| 6954 | goto out; |
| 6955 | if (clp->cl_exchange_flags == 0) |
| 6956 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6957 | if (clp->cl_preserve_clid) |
| 6958 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6959 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6960 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6961 | if (cred) |
| 6962 | put_rpccred(cred); |
| 6963 | switch (ret) { |
| 6964 | case 0: |
| 6965 | case -NFS4ERR_STALE_CLIENTID: |
| 6966 | clp->cl_exchange_flags = 0; |
| 6967 | } |
| 6968 | out: |
| 6969 | return ret; |
| 6970 | } |
| 6971 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6972 | struct nfs4_get_lease_time_data { |
| 6973 | struct nfs4_get_lease_time_args *args; |
| 6974 | struct nfs4_get_lease_time_res *res; |
| 6975 | struct nfs_client *clp; |
| 6976 | }; |
| 6977 | |
| 6978 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6979 | void *calldata) |
| 6980 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6981 | struct nfs4_get_lease_time_data *data = |
| 6982 | (struct nfs4_get_lease_time_data *)calldata; |
| 6983 | |
| 6984 | dprintk("--> %s\n", __func__); |
| 6985 | /* just setup sequence, do not trigger session recovery |
| 6986 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6987 | nfs41_setup_sequence(data->clp->cl_session, |
| 6988 | &data->args->la_seq_args, |
| 6989 | &data->res->lr_seq_res, |
| 6990 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6991 | dprintk("<-- %s\n", __func__); |
| 6992 | } |
| 6993 | |
| 6994 | /* |
| 6995 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6996 | * from sequence operation or clientid errors. |
| 6997 | */ |
| 6998 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6999 | { |
| 7000 | struct nfs4_get_lease_time_data *data = |
| 7001 | (struct nfs4_get_lease_time_data *)calldata; |
| 7002 | |
| 7003 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7004 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7005 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7006 | switch (task->tk_status) { |
| 7007 | case -NFS4ERR_DELAY: |
| 7008 | case -NFS4ERR_GRACE: |
| 7009 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7010 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7011 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7012 | /* fall through */ |
| 7013 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7014 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7015 | return; |
| 7016 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7017 | dprintk("<-- %s\n", __func__); |
| 7018 | } |
| 7019 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7020 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7021 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7022 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7023 | }; |
| 7024 | |
| 7025 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7026 | { |
| 7027 | struct rpc_task *task; |
| 7028 | struct nfs4_get_lease_time_args args; |
| 7029 | struct nfs4_get_lease_time_res res = { |
| 7030 | .lr_fsinfo = fsinfo, |
| 7031 | }; |
| 7032 | struct nfs4_get_lease_time_data data = { |
| 7033 | .args = &args, |
| 7034 | .res = &res, |
| 7035 | .clp = clp, |
| 7036 | }; |
| 7037 | struct rpc_message msg = { |
| 7038 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7039 | .rpc_argp = &args, |
| 7040 | .rpc_resp = &res, |
| 7041 | }; |
| 7042 | struct rpc_task_setup task_setup = { |
| 7043 | .rpc_client = clp->cl_rpcclient, |
| 7044 | .rpc_message = &msg, |
| 7045 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7046 | .callback_data = &data, |
| 7047 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7048 | }; |
| 7049 | int status; |
| 7050 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7051 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7052 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7053 | dprintk("--> %s\n", __func__); |
| 7054 | task = rpc_run_task(&task_setup); |
| 7055 | |
| 7056 | if (IS_ERR(task)) |
| 7057 | status = PTR_ERR(task); |
| 7058 | else { |
| 7059 | status = task->tk_status; |
| 7060 | rpc_put_task(task); |
| 7061 | } |
| 7062 | dprintk("<-- %s return %d\n", __func__, status); |
| 7063 | |
| 7064 | return status; |
| 7065 | } |
| 7066 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7067 | /* |
| 7068 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7069 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7070 | * use them. |
| 7071 | * |
| 7072 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7073 | * always set csa_cachethis to FALSE because the current implementation |
| 7074 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7075 | */ |
| 7076 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 7077 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7078 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7079 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7080 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7081 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7082 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7083 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7084 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7085 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7086 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7087 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7088 | |
| 7089 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7090 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7091 | __func__, |
| 7092 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7093 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7094 | |
| 7095 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7096 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 7097 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 7098 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7099 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 7100 | args->bc_attrs.max_reqs = 1; |
| 7101 | |
| 7102 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7103 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7104 | __func__, |
| 7105 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7106 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7107 | args->bc_attrs.max_reqs); |
| 7108 | } |
| 7109 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7110 | 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] | 7111 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7112 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 7113 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 7114 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7115 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7116 | return -EINVAL; |
| 7117 | /* |
| 7118 | * Our requested max_ops is the minimum we need; we're not |
| 7119 | * prepared to break up compounds into smaller pieces than that. |
| 7120 | * So, no point even trying to continue if the server won't |
| 7121 | * cooperate: |
| 7122 | */ |
| 7123 | if (rcvd->max_ops < sent->max_ops) |
| 7124 | return -EINVAL; |
| 7125 | if (rcvd->max_reqs == 0) |
| 7126 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7127 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7128 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7129 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7130 | } |
| 7131 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7132 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 7133 | { |
| 7134 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 7135 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7136 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7137 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7138 | return -EINVAL; |
| 7139 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7140 | return -EINVAL; |
| 7141 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7142 | return -EINVAL; |
| 7143 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7144 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7145 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7146 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7147 | return -EINVAL; |
| 7148 | return 0; |
| 7149 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7150 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7151 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 7152 | struct nfs4_session *session) |
| 7153 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7154 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7155 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7156 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 7157 | if (ret) |
| 7158 | return ret; |
| 7159 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7160 | } |
| 7161 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7162 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7163 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7164 | { |
| 7165 | struct nfs4_session *session = clp->cl_session; |
| 7166 | struct nfs41_create_session_args args = { |
| 7167 | .client = clp, |
| 7168 | .cb_program = NFS4_CALLBACK, |
| 7169 | }; |
| 7170 | struct nfs41_create_session_res res = { |
| 7171 | .client = clp, |
| 7172 | }; |
| 7173 | struct rpc_message msg = { |
| 7174 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7175 | .rpc_argp = &args, |
| 7176 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7177 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7178 | }; |
| 7179 | int status; |
| 7180 | |
| 7181 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7182 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7183 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7184 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7185 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7186 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7187 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7188 | /* Verify the session's negotiated channel_attrs values */ |
| 7189 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7190 | /* Increment the clientid slot sequence id */ |
| 7191 | clp->cl_seqid++; |
| 7192 | } |
| 7193 | |
| 7194 | return status; |
| 7195 | } |
| 7196 | |
| 7197 | /* |
| 7198 | * Issues a CREATE_SESSION operation to the server. |
| 7199 | * It is the responsibility of the caller to verify the session is |
| 7200 | * expired before calling this routine. |
| 7201 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7202 | 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] | 7203 | { |
| 7204 | int status; |
| 7205 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7206 | struct nfs4_session *session = clp->cl_session; |
| 7207 | |
| 7208 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7209 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7210 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7211 | if (status) |
| 7212 | goto out; |
| 7213 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7214 | /* Init or reset the session slot tables */ |
| 7215 | status = nfs4_setup_session_slot_tables(session); |
| 7216 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7217 | if (status) |
| 7218 | goto out; |
| 7219 | |
| 7220 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7221 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7222 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7223 | out: |
| 7224 | dprintk("<-- %s\n", __func__); |
| 7225 | return status; |
| 7226 | } |
| 7227 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7228 | /* |
| 7229 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7230 | * The caller must serialize access to this routine. |
| 7231 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7232 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7233 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7234 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7235 | struct rpc_message msg = { |
| 7236 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7237 | .rpc_argp = session, |
| 7238 | .rpc_cred = cred, |
| 7239 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7240 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7241 | |
| 7242 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7243 | |
| 7244 | /* session is still being setup */ |
| 7245 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 7246 | return status; |
| 7247 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7248 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7249 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7250 | |
| 7251 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7252 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7253 | "Session has been destroyed regardless...\n", status); |
| 7254 | |
| 7255 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7256 | return status; |
| 7257 | } |
| 7258 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7259 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7260 | * Renew the cl_session lease. |
| 7261 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7262 | struct nfs4_sequence_data { |
| 7263 | struct nfs_client *clp; |
| 7264 | struct nfs4_sequence_args args; |
| 7265 | struct nfs4_sequence_res res; |
| 7266 | }; |
| 7267 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7268 | static void nfs41_sequence_release(void *data) |
| 7269 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7270 | struct nfs4_sequence_data *calldata = data; |
| 7271 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7272 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7273 | if (atomic_read(&clp->cl_count) > 1) |
| 7274 | nfs4_schedule_state_renewal(clp); |
| 7275 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7276 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7277 | } |
| 7278 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7279 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7280 | { |
| 7281 | switch(task->tk_status) { |
| 7282 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7283 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7284 | return -EAGAIN; |
| 7285 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7286 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7287 | } |
| 7288 | return 0; |
| 7289 | } |
| 7290 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7291 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7292 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7293 | struct nfs4_sequence_data *calldata = data; |
| 7294 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7295 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7296 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7297 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7298 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7299 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7300 | if (task->tk_status < 0) { |
| 7301 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7302 | if (atomic_read(&clp->cl_count) == 1) |
| 7303 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7304 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7305 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7306 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7307 | return; |
| 7308 | } |
| 7309 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7310 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7311 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7312 | dprintk("<-- %s\n", __func__); |
| 7313 | } |
| 7314 | |
| 7315 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7316 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7317 | struct nfs4_sequence_data *calldata = data; |
| 7318 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7319 | struct nfs4_sequence_args *args; |
| 7320 | struct nfs4_sequence_res *res; |
| 7321 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7322 | args = task->tk_msg.rpc_argp; |
| 7323 | res = task->tk_msg.rpc_resp; |
| 7324 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7325 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7326 | } |
| 7327 | |
| 7328 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7329 | .rpc_call_done = nfs41_sequence_call_done, |
| 7330 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7331 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7332 | }; |
| 7333 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7334 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7335 | struct rpc_cred *cred, |
| 7336 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7337 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7338 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7339 | struct rpc_message msg = { |
| 7340 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7341 | .rpc_cred = cred, |
| 7342 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7343 | struct rpc_task_setup task_setup_data = { |
| 7344 | .rpc_client = clp->cl_rpcclient, |
| 7345 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7346 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7347 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7348 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7349 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7350 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7351 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7352 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7353 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7354 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7355 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7356 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7357 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7358 | if (is_privileged) |
| 7359 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7360 | msg.rpc_argp = &calldata->args; |
| 7361 | msg.rpc_resp = &calldata->res; |
| 7362 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7363 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7364 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7365 | return rpc_run_task(&task_setup_data); |
| 7366 | } |
| 7367 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7368 | 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] | 7369 | { |
| 7370 | struct rpc_task *task; |
| 7371 | int ret = 0; |
| 7372 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7373 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7374 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7375 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7376 | if (IS_ERR(task)) |
| 7377 | ret = PTR_ERR(task); |
| 7378 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7379 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7380 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7381 | return ret; |
| 7382 | } |
| 7383 | |
| 7384 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7385 | { |
| 7386 | struct rpc_task *task; |
| 7387 | int ret; |
| 7388 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7389 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7390 | if (IS_ERR(task)) { |
| 7391 | ret = PTR_ERR(task); |
| 7392 | goto out; |
| 7393 | } |
| 7394 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7395 | if (!ret) { |
| 7396 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 7397 | |
| 7398 | if (task->tk_status == 0) |
| 7399 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7400 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7401 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7402 | rpc_put_task(task); |
| 7403 | out: |
| 7404 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7405 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7406 | } |
| 7407 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7408 | struct nfs4_reclaim_complete_data { |
| 7409 | struct nfs_client *clp; |
| 7410 | struct nfs41_reclaim_complete_args arg; |
| 7411 | struct nfs41_reclaim_complete_res res; |
| 7412 | }; |
| 7413 | |
| 7414 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7415 | { |
| 7416 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7417 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7418 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7419 | &calldata->arg.seq_args, |
| 7420 | &calldata->res.seq_res, |
| 7421 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7422 | } |
| 7423 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7424 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7425 | { |
| 7426 | switch(task->tk_status) { |
| 7427 | case 0: |
| 7428 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7429 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7430 | break; |
| 7431 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7432 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7433 | /* fall through */ |
| 7434 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7435 | return -EAGAIN; |
| 7436 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7437 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7438 | } |
| 7439 | return 0; |
| 7440 | } |
| 7441 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7442 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7443 | { |
| 7444 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7445 | struct nfs_client *clp = calldata->clp; |
| 7446 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7447 | |
| 7448 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7449 | if (!nfs41_sequence_done(task, res)) |
| 7450 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7451 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7452 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7453 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7454 | rpc_restart_call_prepare(task); |
| 7455 | return; |
| 7456 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7457 | dprintk("<-- %s\n", __func__); |
| 7458 | } |
| 7459 | |
| 7460 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7461 | { |
| 7462 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7463 | |
| 7464 | kfree(calldata); |
| 7465 | } |
| 7466 | |
| 7467 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7468 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7469 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7470 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7471 | }; |
| 7472 | |
| 7473 | /* |
| 7474 | * Issue a global reclaim complete. |
| 7475 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7476 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7477 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7478 | { |
| 7479 | struct nfs4_reclaim_complete_data *calldata; |
| 7480 | struct rpc_task *task; |
| 7481 | struct rpc_message msg = { |
| 7482 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7483 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7484 | }; |
| 7485 | struct rpc_task_setup task_setup_data = { |
| 7486 | .rpc_client = clp->cl_rpcclient, |
| 7487 | .rpc_message = &msg, |
| 7488 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7489 | .flags = RPC_TASK_ASYNC, |
| 7490 | }; |
| 7491 | int status = -ENOMEM; |
| 7492 | |
| 7493 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7494 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7495 | if (calldata == NULL) |
| 7496 | goto out; |
| 7497 | calldata->clp = clp; |
| 7498 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7499 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7500 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7501 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7502 | msg.rpc_argp = &calldata->arg; |
| 7503 | msg.rpc_resp = &calldata->res; |
| 7504 | task_setup_data.callback_data = calldata; |
| 7505 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7506 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7507 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7508 | goto out; |
| 7509 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7510 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7511 | if (status == 0) |
| 7512 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7513 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7514 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7515 | out: |
| 7516 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7517 | return status; |
| 7518 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7519 | |
| 7520 | static void |
| 7521 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7522 | { |
| 7523 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7524 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7525 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7526 | |
| 7527 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7528 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 7529 | * right now covering the LAYOUTGET we are about to send. |
| 7530 | * However, that is not so catastrophic, and there seems |
| 7531 | * to be no way to prevent it completely. |
| 7532 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7533 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7534 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7535 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7536 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7537 | NFS_I(lgp->args.inode)->layout, |
| 7538 | lgp->args.ctx->state)) { |
| 7539 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7540 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7541 | } |
| 7542 | |
| 7543 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7544 | { |
| 7545 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7546 | struct inode *inode = lgp->args.inode; |
| 7547 | struct nfs_server *server = NFS_SERVER(inode); |
| 7548 | struct pnfs_layout_hdr *lo; |
| 7549 | struct nfs4_state *state = NULL; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7550 | unsigned long timeo, now, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7551 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7552 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7553 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7554 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7555 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7556 | |
| 7557 | switch (task->tk_status) { |
| 7558 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7559 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7560 | /* |
| 7561 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
| 7562 | * (or clients) writing to the same RAID stripe |
| 7563 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7564 | case -NFS4ERR_LAYOUTTRYLATER: |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7565 | /* |
| 7566 | * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall |
| 7567 | * existing layout before getting a new one). |
| 7568 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7569 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7570 | timeo = rpc_get_timeout(task->tk_client); |
| 7571 | giveup = lgp->args.timestamp + timeo; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7572 | now = jiffies; |
| 7573 | if (time_after(giveup, now)) { |
| 7574 | unsigned long delay; |
| 7575 | |
| 7576 | /* Delay for: |
| 7577 | * - Not less then NFS4_POLL_RETRY_MIN. |
| 7578 | * - One last time a jiffie before we give up |
| 7579 | * - exponential backoff (time_now minus start_attempt) |
| 7580 | */ |
| 7581 | delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN, |
| 7582 | min((giveup - now - 1), |
| 7583 | now - lgp->args.timestamp)); |
| 7584 | |
| 7585 | dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n", |
| 7586 | __func__, delay); |
| 7587 | rpc_delay(task, delay); |
| 7588 | task->tk_status = 0; |
| 7589 | rpc_restart_call_prepare(task); |
| 7590 | goto out; /* Do not call nfs4_async_handle_error() */ |
| 7591 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7592 | break; |
| 7593 | case -NFS4ERR_EXPIRED: |
| 7594 | case -NFS4ERR_BAD_STATEID: |
| 7595 | spin_lock(&inode->i_lock); |
| 7596 | lo = NFS_I(inode)->layout; |
| 7597 | if (!lo || list_empty(&lo->plh_segs)) { |
| 7598 | spin_unlock(&inode->i_lock); |
| 7599 | /* If the open stateid was bad, then recover it. */ |
| 7600 | state = lgp->args.ctx->state; |
| 7601 | } else { |
| 7602 | LIST_HEAD(head); |
| 7603 | |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7604 | /* |
| 7605 | * Mark the bad layout state as invalid, then retry |
| 7606 | * with the current stateid. |
| 7607 | */ |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7608 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 7609 | spin_unlock(&inode->i_lock); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7610 | pnfs_free_lseg_list(&head); |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7611 | |
| 7612 | task->tk_status = 0; |
| 7613 | rpc_restart_call_prepare(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7614 | } |
| 7615 | } |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7616 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7617 | rpc_restart_call_prepare(task); |
| 7618 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7619 | dprintk("<-- %s\n", __func__); |
| 7620 | } |
| 7621 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7622 | static size_t max_response_pages(struct nfs_server *server) |
| 7623 | { |
| 7624 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7625 | return nfs_page_array_len(0, max_resp_sz); |
| 7626 | } |
| 7627 | |
| 7628 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7629 | { |
| 7630 | int i; |
| 7631 | |
| 7632 | if (!pages) |
| 7633 | return; |
| 7634 | |
| 7635 | for (i = 0; i < size; i++) { |
| 7636 | if (!pages[i]) |
| 7637 | break; |
| 7638 | __free_page(pages[i]); |
| 7639 | } |
| 7640 | kfree(pages); |
| 7641 | } |
| 7642 | |
| 7643 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7644 | { |
| 7645 | struct page **pages; |
| 7646 | int i; |
| 7647 | |
| 7648 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7649 | if (!pages) { |
| 7650 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7651 | return NULL; |
| 7652 | } |
| 7653 | |
| 7654 | for (i = 0; i < size; i++) { |
| 7655 | pages[i] = alloc_page(gfp_flags); |
| 7656 | if (!pages[i]) { |
| 7657 | dprintk("%s: failed to allocate page\n", __func__); |
| 7658 | nfs4_free_pages(pages, size); |
| 7659 | return NULL; |
| 7660 | } |
| 7661 | } |
| 7662 | |
| 7663 | return pages; |
| 7664 | } |
| 7665 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7666 | static void nfs4_layoutget_release(void *calldata) |
| 7667 | { |
| 7668 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7669 | struct inode *inode = lgp->args.inode; |
| 7670 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7671 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7672 | |
| 7673 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7674 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7675 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7676 | put_nfs_open_context(lgp->args.ctx); |
| 7677 | kfree(calldata); |
| 7678 | dprintk("<-- %s\n", __func__); |
| 7679 | } |
| 7680 | |
| 7681 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 7682 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 7683 | .rpc_call_done = nfs4_layoutget_done, |
| 7684 | .rpc_release = nfs4_layoutget_release, |
| 7685 | }; |
| 7686 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7687 | struct pnfs_layout_segment * |
| 7688 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7689 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7690 | struct inode *inode = lgp->args.inode; |
| 7691 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7692 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7693 | struct rpc_task *task; |
| 7694 | struct rpc_message msg = { |
| 7695 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 7696 | .rpc_argp = &lgp->args, |
| 7697 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7698 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7699 | }; |
| 7700 | struct rpc_task_setup task_setup_data = { |
| 7701 | .rpc_client = server->client, |
| 7702 | .rpc_message = &msg, |
| 7703 | .callback_ops = &nfs4_layoutget_call_ops, |
| 7704 | .callback_data = lgp, |
| 7705 | .flags = RPC_TASK_ASYNC, |
| 7706 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7707 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7708 | int status = 0; |
| 7709 | |
| 7710 | dprintk("--> %s\n", __func__); |
| 7711 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7712 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 7713 | if (!lgp->args.layout.pages) { |
| 7714 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7715 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7716 | } |
| 7717 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7718 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7719 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 7720 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7721 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7722 | 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] | 7723 | |
| 7724 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 7725 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 7726 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7727 | task = rpc_run_task(&task_setup_data); |
| 7728 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7729 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7730 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7731 | if (status == 0) |
| 7732 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7733 | trace_nfs4_layoutget(lgp->args.ctx, |
| 7734 | &lgp->args.range, |
| 7735 | &lgp->res.range, |
| 7736 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 7737 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 7738 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7739 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7740 | rpc_put_task(task); |
| 7741 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7742 | if (status) |
| 7743 | return ERR_PTR(status); |
| 7744 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7745 | } |
| 7746 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7747 | static void |
| 7748 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 7749 | { |
| 7750 | struct nfs4_layoutreturn *lrp = calldata; |
| 7751 | |
| 7752 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7753 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 7754 | &lrp->args.seq_args, |
| 7755 | &lrp->res.seq_res, |
| 7756 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7757 | } |
| 7758 | |
| 7759 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 7760 | { |
| 7761 | struct nfs4_layoutreturn *lrp = calldata; |
| 7762 | struct nfs_server *server; |
| 7763 | |
| 7764 | dprintk("--> %s\n", __func__); |
| 7765 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7766 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7767 | return; |
| 7768 | |
| 7769 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7770 | switch (task->tk_status) { |
| 7771 | default: |
| 7772 | task->tk_status = 0; |
| 7773 | case 0: |
| 7774 | break; |
| 7775 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7776 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7777 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7778 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7779 | return; |
| 7780 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7781 | dprintk("<-- %s\n", __func__); |
| 7782 | } |
| 7783 | |
| 7784 | static void nfs4_layoutreturn_release(void *calldata) |
| 7785 | { |
| 7786 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7787 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7788 | |
| 7789 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7790 | spin_lock(&lo->plh_inode->i_lock); |
| 7791 | if (lrp->res.lrs_present) |
| 7792 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 7793 | lo->plh_block_lgets--; |
| 7794 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 7795 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7796 | kfree(calldata); |
| 7797 | dprintk("<-- %s\n", __func__); |
| 7798 | } |
| 7799 | |
| 7800 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 7801 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 7802 | .rpc_call_done = nfs4_layoutreturn_done, |
| 7803 | .rpc_release = nfs4_layoutreturn_release, |
| 7804 | }; |
| 7805 | |
| 7806 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 7807 | { |
| 7808 | struct rpc_task *task; |
| 7809 | struct rpc_message msg = { |
| 7810 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 7811 | .rpc_argp = &lrp->args, |
| 7812 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 7813 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7814 | }; |
| 7815 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 7816 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7817 | .rpc_message = &msg, |
| 7818 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 7819 | .callback_data = lrp, |
| 7820 | }; |
| 7821 | int status; |
| 7822 | |
| 7823 | dprintk("--> %s\n", __func__); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7824 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7825 | task = rpc_run_task(&task_setup_data); |
| 7826 | if (IS_ERR(task)) |
| 7827 | return PTR_ERR(task); |
| 7828 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7829 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7830 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7831 | rpc_put_task(task); |
| 7832 | return status; |
| 7833 | } |
| 7834 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7835 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7836 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7837 | struct pnfs_device *pdev, |
| 7838 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7839 | { |
| 7840 | struct nfs4_getdeviceinfo_args args = { |
| 7841 | .pdev = pdev, |
| 7842 | }; |
| 7843 | struct nfs4_getdeviceinfo_res res = { |
| 7844 | .pdev = pdev, |
| 7845 | }; |
| 7846 | struct rpc_message msg = { |
| 7847 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7848 | .rpc_argp = &args, |
| 7849 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7850 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7851 | }; |
| 7852 | int status; |
| 7853 | |
| 7854 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7855 | 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] | 7856 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7857 | |
| 7858 | return status; |
| 7859 | } |
| 7860 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7861 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7862 | struct pnfs_device *pdev, |
| 7863 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7864 | { |
| 7865 | struct nfs4_exception exception = { }; |
| 7866 | int err; |
| 7867 | |
| 7868 | do { |
| 7869 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7870 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7871 | &exception); |
| 7872 | } while (exception.retry); |
| 7873 | return err; |
| 7874 | } |
| 7875 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7876 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7877 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7878 | { |
| 7879 | struct nfs4_layoutcommit_data *data = calldata; |
| 7880 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7881 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7882 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7883 | nfs41_setup_sequence(session, |
| 7884 | &data->args.seq_args, |
| 7885 | &data->res.seq_res, |
| 7886 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7887 | } |
| 7888 | |
| 7889 | static void |
| 7890 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7891 | { |
| 7892 | struct nfs4_layoutcommit_data *data = calldata; |
| 7893 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7894 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7895 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7896 | return; |
| 7897 | |
| 7898 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7899 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7900 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7901 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7902 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7903 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7904 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7905 | break; |
| 7906 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7907 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7908 | rpc_restart_call_prepare(task); |
| 7909 | return; |
| 7910 | } |
| 7911 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | static void nfs4_layoutcommit_release(void *calldata) |
| 7915 | { |
| 7916 | struct nfs4_layoutcommit_data *data = calldata; |
| 7917 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7918 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 7919 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7920 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7921 | put_rpccred(data->cred); |
| 7922 | kfree(data); |
| 7923 | } |
| 7924 | |
| 7925 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7926 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7927 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7928 | .rpc_release = nfs4_layoutcommit_release, |
| 7929 | }; |
| 7930 | |
| 7931 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7932 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7933 | { |
| 7934 | struct rpc_message msg = { |
| 7935 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7936 | .rpc_argp = &data->args, |
| 7937 | .rpc_resp = &data->res, |
| 7938 | .rpc_cred = data->cred, |
| 7939 | }; |
| 7940 | struct rpc_task_setup task_setup_data = { |
| 7941 | .task = &data->task, |
| 7942 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7943 | .rpc_message = &msg, |
| 7944 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7945 | .callback_data = data, |
| 7946 | .flags = RPC_TASK_ASYNC, |
| 7947 | }; |
| 7948 | struct rpc_task *task; |
| 7949 | int status = 0; |
| 7950 | |
| 7951 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7952 | "lbw: %llu inode %lu\n", |
| 7953 | data->task.tk_pid, sync, |
| 7954 | data->args.lastbytewritten, |
| 7955 | data->args.inode->i_ino); |
| 7956 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7957 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7958 | task = rpc_run_task(&task_setup_data); |
| 7959 | if (IS_ERR(task)) |
| 7960 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7961 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7962 | goto out; |
| 7963 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7964 | if (status != 0) |
| 7965 | goto out; |
| 7966 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7967 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7968 | out: |
| 7969 | dprintk("%s: status %d\n", __func__, status); |
| 7970 | rpc_put_task(task); |
| 7971 | return status; |
| 7972 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7973 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7974 | /** |
| 7975 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7976 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7977 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7978 | static int |
| 7979 | _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] | 7980 | struct nfs_fsinfo *info, |
| 7981 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7982 | { |
| 7983 | struct nfs41_secinfo_no_name_args args = { |
| 7984 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7985 | }; |
| 7986 | struct nfs4_secinfo_res res = { |
| 7987 | .flavors = flavors, |
| 7988 | }; |
| 7989 | struct rpc_message msg = { |
| 7990 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7991 | .rpc_argp = &args, |
| 7992 | .rpc_resp = &res, |
| 7993 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7994 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7995 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7996 | int status; |
| 7997 | |
| 7998 | if (use_integrity) { |
| 7999 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8000 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8001 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8002 | } |
| 8003 | |
| 8004 | dprintk("--> %s\n", __func__); |
| 8005 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8006 | &res.seq_res, 0); |
| 8007 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8008 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8009 | if (cred) |
| 8010 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8011 | |
| 8012 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8013 | } |
| 8014 | |
| 8015 | static int |
| 8016 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8017 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8018 | { |
| 8019 | struct nfs4_exception exception = { }; |
| 8020 | int err; |
| 8021 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8022 | /* first try using integrity protection */ |
| 8023 | err = -NFS4ERR_WRONGSEC; |
| 8024 | |
| 8025 | /* try to use integrity protection with machine cred */ |
| 8026 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8027 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8028 | flavors, true); |
| 8029 | |
| 8030 | /* |
| 8031 | * if unable to use integrity protection, or SECINFO with |
| 8032 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8033 | * disallowed by spec, but exists in deployed servers) use |
| 8034 | * the current filesystem's rpc_client and the user cred. |
| 8035 | */ |
| 8036 | if (err == -NFS4ERR_WRONGSEC) |
| 8037 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8038 | flavors, false); |
| 8039 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8040 | switch (err) { |
| 8041 | case 0: |
| 8042 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8043 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8044 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8045 | default: |
| 8046 | err = nfs4_handle_exception(server, err, &exception); |
| 8047 | } |
| 8048 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8049 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8050 | return err; |
| 8051 | } |
| 8052 | |
| 8053 | static int |
| 8054 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8055 | struct nfs_fsinfo *info) |
| 8056 | { |
| 8057 | int err; |
| 8058 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8059 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8060 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8061 | struct nfs4_secinfo4 *secinfo; |
| 8062 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8063 | |
| 8064 | page = alloc_page(GFP_KERNEL); |
| 8065 | if (!page) { |
| 8066 | err = -ENOMEM; |
| 8067 | goto out; |
| 8068 | } |
| 8069 | |
| 8070 | flavors = page_address(page); |
| 8071 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8072 | |
| 8073 | /* |
| 8074 | * Fall back on "guess and check" method if |
| 8075 | * the server doesn't support SECINFO_NO_NAME |
| 8076 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8077 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8078 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8079 | goto out_freepage; |
| 8080 | } |
| 8081 | if (err) |
| 8082 | goto out_freepage; |
| 8083 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8084 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8085 | secinfo = &flavors->flavors[i]; |
| 8086 | |
| 8087 | switch (secinfo->flavor) { |
| 8088 | case RPC_AUTH_NULL: |
| 8089 | case RPC_AUTH_UNIX: |
| 8090 | case RPC_AUTH_GSS: |
| 8091 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8092 | &secinfo->flavor_info); |
| 8093 | break; |
| 8094 | default: |
| 8095 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8096 | break; |
| 8097 | } |
| 8098 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8099 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8100 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8101 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8102 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8103 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8104 | info, flavor); |
| 8105 | if (!err) |
| 8106 | break; |
| 8107 | } |
| 8108 | } |
| 8109 | |
| 8110 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8111 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8112 | |
| 8113 | out_freepage: |
| 8114 | put_page(page); |
| 8115 | if (err == -EACCES) |
| 8116 | return -EPERM; |
| 8117 | out: |
| 8118 | return err; |
| 8119 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8120 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8121 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8122 | nfs4_stateid *stateid, |
| 8123 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8124 | { |
| 8125 | int status; |
| 8126 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8127 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8128 | }; |
| 8129 | struct nfs41_test_stateid_res res; |
| 8130 | struct rpc_message msg = { |
| 8131 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8132 | .rpc_argp = &args, |
| 8133 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8134 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8135 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8136 | struct rpc_clnt *rpc_client = server->client; |
| 8137 | |
| 8138 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8139 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8140 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8141 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8142 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8143 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8144 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8145 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8146 | if (status != NFS_OK) { |
| 8147 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8148 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8149 | } |
| 8150 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8151 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8152 | } |
| 8153 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8154 | /** |
| 8155 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8156 | * |
| 8157 | * @server: server / transport on which to perform the operation |
| 8158 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8159 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8160 | * |
| 8161 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8162 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8163 | * failed or the state ID is not currently valid. |
| 8164 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8165 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8166 | nfs4_stateid *stateid, |
| 8167 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8168 | { |
| 8169 | struct nfs4_exception exception = { }; |
| 8170 | int err; |
| 8171 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8172 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8173 | if (err != -NFS4ERR_DELAY) |
| 8174 | break; |
| 8175 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8176 | } while (exception.retry); |
| 8177 | return err; |
| 8178 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8179 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8180 | struct nfs_free_stateid_data { |
| 8181 | struct nfs_server *server; |
| 8182 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8183 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8184 | }; |
| 8185 | |
| 8186 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8187 | { |
| 8188 | struct nfs_free_stateid_data *data = calldata; |
| 8189 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8190 | &data->args.seq_args, |
| 8191 | &data->res.seq_res, |
| 8192 | task); |
| 8193 | } |
| 8194 | |
| 8195 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8196 | { |
| 8197 | struct nfs_free_stateid_data *data = calldata; |
| 8198 | |
| 8199 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8200 | |
| 8201 | switch (task->tk_status) { |
| 8202 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8203 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8204 | rpc_restart_call_prepare(task); |
| 8205 | } |
| 8206 | } |
| 8207 | |
| 8208 | static void nfs41_free_stateid_release(void *calldata) |
| 8209 | { |
| 8210 | kfree(calldata); |
| 8211 | } |
| 8212 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8213 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8214 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8215 | .rpc_call_done = nfs41_free_stateid_done, |
| 8216 | .rpc_release = nfs41_free_stateid_release, |
| 8217 | }; |
| 8218 | |
| 8219 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8220 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8221 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8222 | bool privileged) |
| 8223 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8224 | struct rpc_message msg = { |
| 8225 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8226 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8227 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8228 | struct rpc_task_setup task_setup = { |
| 8229 | .rpc_client = server->client, |
| 8230 | .rpc_message = &msg, |
| 8231 | .callback_ops = &nfs41_free_stateid_ops, |
| 8232 | .flags = RPC_TASK_ASYNC, |
| 8233 | }; |
| 8234 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8235 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8236 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8237 | &task_setup.rpc_client, &msg); |
| 8238 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8239 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8240 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8241 | if (!data) |
| 8242 | return ERR_PTR(-ENOMEM); |
| 8243 | data->server = server; |
| 8244 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8245 | |
| 8246 | task_setup.callback_data = data; |
| 8247 | |
| 8248 | msg.rpc_argp = &data->args; |
| 8249 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8250 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8251 | if (privileged) |
| 8252 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8253 | |
| 8254 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8255 | } |
| 8256 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8257 | /** |
| 8258 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8259 | * |
| 8260 | * @server: server / transport on which to perform the operation |
| 8261 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8262 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8263 | * |
| 8264 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8265 | * negative NFS4ERR value is returned. |
| 8266 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8267 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8268 | nfs4_stateid *stateid, |
| 8269 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8270 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8271 | struct rpc_task *task; |
| 8272 | int ret; |
| 8273 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8274 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8275 | if (IS_ERR(task)) |
| 8276 | return PTR_ERR(task); |
| 8277 | ret = rpc_wait_for_completion_task(task); |
| 8278 | if (!ret) |
| 8279 | ret = task->tk_status; |
| 8280 | rpc_put_task(task); |
| 8281 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8282 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8283 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8284 | static void |
| 8285 | 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] | 8286 | { |
| 8287 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8288 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8289 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8290 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8291 | nfs4_free_lock_state(server, lsp); |
| 8292 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8293 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8294 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8295 | } |
| 8296 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8297 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8298 | const nfs4_stateid *s2) |
| 8299 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8300 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8301 | return false; |
| 8302 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8303 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8304 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8305 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8306 | return true; |
| 8307 | |
| 8308 | return false; |
| 8309 | } |
| 8310 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8311 | #endif /* CONFIG_NFS_V4_1 */ |
| 8312 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8313 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8314 | const nfs4_stateid *s2) |
| 8315 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8316 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8317 | } |
| 8318 | |
| 8319 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8320 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8321 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8322 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8323 | .recover_open = nfs4_open_reclaim, |
| 8324 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8325 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8326 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8327 | }; |
| 8328 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8329 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8330 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8331 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8332 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8333 | .recover_open = nfs4_open_reclaim, |
| 8334 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8335 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8336 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8337 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8338 | }; |
| 8339 | #endif /* CONFIG_NFS_V4_1 */ |
| 8340 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8341 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8342 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8343 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8344 | .recover_open = nfs4_open_expired, |
| 8345 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8346 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8347 | }; |
| 8348 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8349 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8350 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8351 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8352 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8353 | .recover_open = nfs41_open_expired, |
| 8354 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8355 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8356 | }; |
| 8357 | #endif /* CONFIG_NFS_V4_1 */ |
| 8358 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8359 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8360 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8361 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8362 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8363 | }; |
| 8364 | |
| 8365 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8366 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8367 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8368 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8369 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8370 | }; |
| 8371 | #endif |
| 8372 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8373 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8374 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8375 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8376 | }; |
| 8377 | |
| 8378 | #if defined(CONFIG_NFS_V4_1) |
| 8379 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8380 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8381 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8382 | }; |
| 8383 | #endif /* CONFIG_NFS_V4_1 */ |
| 8384 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8385 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8386 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8387 | .init_caps = NFS_CAP_READDIRPLUS |
| 8388 | | NFS_CAP_ATOMIC_OPEN |
| 8389 | | NFS_CAP_CHANGE_ATTR |
| 8390 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8391 | .init_client = nfs40_init_client, |
| 8392 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8393 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8394 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8395 | .free_lock_state = nfs4_release_lockowner, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8396 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8397 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8398 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8399 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8400 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8401 | }; |
| 8402 | |
| 8403 | #if defined(CONFIG_NFS_V4_1) |
| 8404 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8405 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8406 | .init_caps = NFS_CAP_READDIRPLUS |
| 8407 | | NFS_CAP_ATOMIC_OPEN |
| 8408 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8409 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8410 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 8411 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 8412 | | NFS_CAP_SEEK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8413 | .init_client = nfs41_init_client, |
| 8414 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8415 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8416 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8417 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8418 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8419 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8420 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8421 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8422 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8423 | }; |
| 8424 | #endif |
| 8425 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8426 | #if defined(CONFIG_NFS_V4_2) |
| 8427 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8428 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8429 | .init_caps = NFS_CAP_READDIRPLUS |
| 8430 | | NFS_CAP_ATOMIC_OPEN |
| 8431 | | NFS_CAP_CHANGE_ATTR |
| 8432 | | NFS_CAP_POSIX_LOCK |
| 8433 | | NFS_CAP_STATEID_NFSV41 |
| 8434 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8435 | .init_client = nfs41_init_client, |
| 8436 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8437 | .match_stateid = nfs41_match_stateid, |
| 8438 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8439 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8440 | .call_sync_ops = &nfs41_call_sync_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8441 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8442 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8443 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 8444 | }; |
| 8445 | #endif |
| 8446 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8447 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8448 | [0] = &nfs_v4_0_minor_ops, |
| 8449 | #if defined(CONFIG_NFS_V4_1) |
| 8450 | [1] = &nfs_v4_1_minor_ops, |
| 8451 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8452 | #if defined(CONFIG_NFS_V4_2) |
| 8453 | [2] = &nfs_v4_2_minor_ops, |
| 8454 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8455 | }; |
| 8456 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8457 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8458 | .create = nfs_create, |
| 8459 | .lookup = nfs_lookup, |
| 8460 | .atomic_open = nfs_atomic_open, |
| 8461 | .link = nfs_link, |
| 8462 | .unlink = nfs_unlink, |
| 8463 | .symlink = nfs_symlink, |
| 8464 | .mkdir = nfs_mkdir, |
| 8465 | .rmdir = nfs_rmdir, |
| 8466 | .mknod = nfs_mknod, |
| 8467 | .rename = nfs_rename, |
| 8468 | .permission = nfs_permission, |
| 8469 | .getattr = nfs_getattr, |
| 8470 | .setattr = nfs_setattr, |
| 8471 | .getxattr = generic_getxattr, |
| 8472 | .setxattr = generic_setxattr, |
| 8473 | .listxattr = generic_listxattr, |
| 8474 | .removexattr = generic_removexattr, |
| 8475 | }; |
| 8476 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8477 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8478 | .permission = nfs_permission, |
| 8479 | .getattr = nfs_getattr, |
| 8480 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8481 | .getxattr = generic_getxattr, |
| 8482 | .setxattr = generic_setxattr, |
| 8483 | .listxattr = generic_listxattr, |
| 8484 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8485 | }; |
| 8486 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8487 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8488 | .version = 4, /* protocol version */ |
| 8489 | .dentry_ops = &nfs4_dentry_operations, |
| 8490 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8491 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8492 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8493 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8494 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8495 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8496 | .getattr = nfs4_proc_getattr, |
| 8497 | .setattr = nfs4_proc_setattr, |
| 8498 | .lookup = nfs4_proc_lookup, |
| 8499 | .access = nfs4_proc_access, |
| 8500 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8501 | .create = nfs4_proc_create, |
| 8502 | .remove = nfs4_proc_remove, |
| 8503 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8504 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8505 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8506 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8507 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8508 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8509 | .link = nfs4_proc_link, |
| 8510 | .symlink = nfs4_proc_symlink, |
| 8511 | .mkdir = nfs4_proc_mkdir, |
| 8512 | .rmdir = nfs4_proc_remove, |
| 8513 | .readdir = nfs4_proc_readdir, |
| 8514 | .mknod = nfs4_proc_mknod, |
| 8515 | .statfs = nfs4_proc_statfs, |
| 8516 | .fsinfo = nfs4_proc_fsinfo, |
| 8517 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8518 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8519 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8520 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8521 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8522 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8523 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8524 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8525 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8526 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8527 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8528 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8529 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8530 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8531 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8532 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8533 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8534 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8535 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8536 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8537 | .create_server = nfs4_create_server, |
| 8538 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8539 | }; |
| 8540 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8541 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 8542 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 8543 | .list = nfs4_xattr_list_nfs4_acl, |
| 8544 | .get = nfs4_xattr_get_nfs4_acl, |
| 8545 | .set = nfs4_xattr_set_nfs4_acl, |
| 8546 | }; |
| 8547 | |
| 8548 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8549 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8550 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8551 | &nfs4_xattr_nfs4_label_handler, |
| 8552 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8553 | NULL |
| 8554 | }; |
| 8555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8556 | /* |
| 8557 | * Local variables: |
| 8558 | * c-basic-offset: 8 |
| 8559 | * End: |
| 8560 | */ |