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> |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 41 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 43 | #include <linux/ratelimit.h> |
| 44 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
| 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.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" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 76 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 77 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 78 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 79 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | 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] | 81 | 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] | 82 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 83 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 84 | 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] | 85 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 86 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 87 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 88 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 90 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 91 | struct rpc_cred *); |
| 92 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 93 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 94 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 97 | static inline struct nfs4_label * |
| 98 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 99 | struct iattr *sattr, struct nfs4_label *label) |
| 100 | { |
| 101 | int err; |
| 102 | |
| 103 | if (label == NULL) |
| 104 | return NULL; |
| 105 | |
| 106 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 107 | return NULL; |
| 108 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 109 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 110 | &dentry->d_name, (void **)&label->label, &label->len); |
| 111 | if (err == 0) |
| 112 | return label; |
| 113 | |
| 114 | return NULL; |
| 115 | } |
| 116 | static inline void |
| 117 | nfs4_label_release_security(struct nfs4_label *label) |
| 118 | { |
| 119 | if (label) |
| 120 | security_release_secctx(label->label, label->len); |
| 121 | } |
| 122 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 123 | { |
| 124 | if (label) |
| 125 | return server->attr_bitmask; |
| 126 | |
| 127 | return server->attr_bitmask_nl; |
| 128 | } |
| 129 | #else |
| 130 | static inline struct nfs4_label * |
| 131 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 132 | struct iattr *sattr, struct nfs4_label *l) |
| 133 | { return NULL; } |
| 134 | static inline void |
| 135 | nfs4_label_release_security(struct nfs4_label *label) |
| 136 | { return; } |
| 137 | static inline u32 * |
| 138 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 139 | { return server->attr_bitmask; } |
| 140 | #endif |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 143 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 145 | if (err >= -1000) |
| 146 | return err; |
| 147 | switch (err) { |
| 148 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 149 | case -NFS4ERR_LAYOUTTRYLATER: |
| 150 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 151 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 152 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 153 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 155 | case -NFS4ERR_BADOWNER: |
| 156 | case -NFS4ERR_BADNAME: |
| 157 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 158 | case -NFS4ERR_SHARE_DENIED: |
| 159 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 160 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 161 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 162 | case -NFS4ERR_FILE_OPEN: |
| 163 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 164 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 166 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 167 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 169 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /* |
| 173 | * This is our standard bitmap for GETATTR requests. |
| 174 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 175 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | FATTR4_WORD0_TYPE |
| 177 | | FATTR4_WORD0_CHANGE |
| 178 | | FATTR4_WORD0_SIZE |
| 179 | | FATTR4_WORD0_FSID |
| 180 | | FATTR4_WORD0_FILEID, |
| 181 | FATTR4_WORD1_MODE |
| 182 | | FATTR4_WORD1_NUMLINKS |
| 183 | | FATTR4_WORD1_OWNER |
| 184 | | FATTR4_WORD1_OWNER_GROUP |
| 185 | | FATTR4_WORD1_RAWDEV |
| 186 | | FATTR4_WORD1_SPACE_USED |
| 187 | | FATTR4_WORD1_TIME_ACCESS |
| 188 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 189 | | FATTR4_WORD1_TIME_MODIFY |
| 190 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 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 */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 298 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
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 */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
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 | */ |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 347 | 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 | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 373 | if (state == NULL) |
| 374 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 375 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 376 | if (ret < 0) |
| 377 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 378 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 379 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 380 | if (state != NULL) { |
| 381 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 382 | if (ret < 0) |
| 383 | break; |
| 384 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 385 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 386 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 387 | nfs4_schedule_lease_recovery(clp); |
| 388 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 389 | case -NFS4ERR_MOVED: |
| 390 | ret = nfs4_schedule_migration_recovery(server); |
| 391 | if (ret < 0) |
| 392 | break; |
| 393 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 394 | case -NFS4ERR_LEASE_MOVED: |
| 395 | nfs4_schedule_lease_moved_recovery(clp); |
| 396 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 397 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 398 | case -NFS4ERR_BADSESSION: |
| 399 | case -NFS4ERR_BADSLOT: |
| 400 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 401 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 402 | case -NFS4ERR_DEADSESSION: |
| 403 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 404 | case -NFS4ERR_SEQ_MISORDERED: |
| 405 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 406 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 407 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 408 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 409 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 410 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 411 | if (exception->timeout > HZ) { |
| 412 | /* We have retried a decent amount, time to |
| 413 | * fail |
| 414 | */ |
| 415 | ret = -EBUSY; |
| 416 | break; |
| 417 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 418 | case -NFS4ERR_GRACE: |
| 419 | case -NFS4ERR_DELAY: |
| 420 | ret = nfs4_delay(server->client, &exception->timeout); |
| 421 | if (ret != 0) |
| 422 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 423 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 424 | case -NFS4ERR_OLD_STATEID: |
| 425 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 426 | break; |
| 427 | case -NFS4ERR_BADOWNER: |
| 428 | /* The following works around a Linux server bug! */ |
| 429 | case -NFS4ERR_BADNAME: |
| 430 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 431 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 432 | exception->retry = 1; |
| 433 | printk(KERN_WARNING "NFS: v4 server %s " |
| 434 | "does not accept raw " |
| 435 | "uid/gids. " |
| 436 | "Reenabling the idmapper.\n", |
| 437 | server->nfs_client->cl_hostname); |
| 438 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 439 | } |
| 440 | /* We failed to handle the error */ |
| 441 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 442 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 443 | ret = nfs4_wait_clnt_recover(clp); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 444 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 445 | return -EIO; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 446 | if (ret == 0) |
| 447 | exception->retry = 1; |
| 448 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 449 | } |
| 450 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 451 | /* |
| 452 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 453 | * or 'false' otherwise. |
| 454 | */ |
| 455 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 456 | { |
| 457 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 458 | |
| 459 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 460 | flavor == RPC_AUTH_GSS_KRB5P) |
| 461 | return true; |
| 462 | |
| 463 | return false; |
| 464 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 465 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 466 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | spin_lock(&clp->cl_lock); |
| 469 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 470 | clp->cl_last_renewal = timestamp; |
| 471 | spin_unlock(&clp->cl_lock); |
| 472 | } |
| 473 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 474 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 475 | { |
| 476 | do_renew_lease(server->nfs_client, timestamp); |
| 477 | } |
| 478 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 479 | struct nfs4_call_sync_data { |
| 480 | const struct nfs_server *seq_server; |
| 481 | struct nfs4_sequence_args *seq_args; |
| 482 | struct nfs4_sequence_res *seq_res; |
| 483 | }; |
| 484 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 485 | static void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 486 | struct nfs4_sequence_res *res, int cache_reply) |
| 487 | { |
| 488 | args->sa_slot = NULL; |
| 489 | args->sa_cache_this = cache_reply; |
| 490 | args->sa_privileged = 0; |
| 491 | |
| 492 | res->sr_slot = NULL; |
| 493 | } |
| 494 | |
| 495 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 496 | { |
| 497 | args->sa_privileged = 1; |
| 498 | } |
| 499 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 500 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 501 | struct nfs4_sequence_args *args, |
| 502 | struct nfs4_sequence_res *res, |
| 503 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 504 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 505 | struct nfs4_slot *slot; |
| 506 | |
| 507 | /* slot already allocated? */ |
| 508 | if (res->sr_slot != NULL) |
| 509 | goto out_start; |
| 510 | |
| 511 | spin_lock(&tbl->slot_tbl_lock); |
| 512 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 513 | goto out_sleep; |
| 514 | |
| 515 | slot = nfs4_alloc_slot(tbl); |
| 516 | if (IS_ERR(slot)) { |
| 517 | if (slot == ERR_PTR(-ENOMEM)) |
| 518 | task->tk_timeout = HZ >> 2; |
| 519 | goto out_sleep; |
| 520 | } |
| 521 | spin_unlock(&tbl->slot_tbl_lock); |
| 522 | |
| 523 | args->sa_slot = slot; |
| 524 | res->sr_slot = slot; |
| 525 | |
| 526 | out_start: |
| 527 | rpc_call_start(task); |
| 528 | return 0; |
| 529 | |
| 530 | out_sleep: |
| 531 | if (args->sa_privileged) |
| 532 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 533 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 534 | else |
| 535 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 536 | spin_unlock(&tbl->slot_tbl_lock); |
| 537 | return -EAGAIN; |
| 538 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 539 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 540 | |
| 541 | static int nfs40_sequence_done(struct rpc_task *task, |
| 542 | struct nfs4_sequence_res *res) |
| 543 | { |
| 544 | struct nfs4_slot *slot = res->sr_slot; |
| 545 | struct nfs4_slot_table *tbl; |
| 546 | |
Trond Myklebust | cab92c1 | 2014-01-29 12:12:15 -0500 | [diff] [blame] | 547 | if (slot == NULL) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 548 | goto out; |
| 549 | |
| 550 | tbl = slot->table; |
| 551 | spin_lock(&tbl->slot_tbl_lock); |
| 552 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 553 | nfs4_free_slot(tbl, slot); |
| 554 | spin_unlock(&tbl->slot_tbl_lock); |
| 555 | |
| 556 | res->sr_slot = NULL; |
| 557 | out: |
| 558 | return 1; |
| 559 | } |
| 560 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 561 | #if defined(CONFIG_NFS_V4_1) |
| 562 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 563 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 564 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 565 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 566 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 567 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 568 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 569 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 570 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 571 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 572 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 573 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 574 | /* Be nice to the server: try to ensure that the last transmitted |
| 575 | * value for highest_user_slotid <= target_highest_slotid |
| 576 | */ |
| 577 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 578 | send_new_highest_used_slotid = true; |
| 579 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 580 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 581 | send_new_highest_used_slotid = false; |
| 582 | goto out_unlock; |
| 583 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 584 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 585 | |
| 586 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 587 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 588 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 589 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 590 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 591 | if (send_new_highest_used_slotid) |
| 592 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 595 | 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] | 596 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 597 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 598 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 599 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 600 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 601 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 602 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 603 | if (slot == NULL) |
| 604 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 605 | /* don't increment the sequence number if the task wasn't sent */ |
| 606 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 607 | goto out; |
| 608 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 609 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 610 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 611 | if (slot->interrupted) { |
| 612 | slot->interrupted = 0; |
| 613 | interrupted = true; |
| 614 | } |
| 615 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 616 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 617 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 618 | switch (res->sr_status) { |
| 619 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 620 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 621 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 622 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 623 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 624 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 625 | if (res->sr_status_flags != 0) |
| 626 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 627 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 628 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 629 | case 1: |
| 630 | /* |
| 631 | * sr_status remains 1 if an RPC level error occurred. |
| 632 | * The server may or may not have processed the sequence |
| 633 | * operation.. |
| 634 | * Mark the slot as having hosted an interrupted RPC call. |
| 635 | */ |
| 636 | slot->interrupted = 1; |
| 637 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 638 | case -NFS4ERR_DELAY: |
| 639 | /* The server detected a resend of the RPC call and |
| 640 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 641 | * of RFC5661. |
| 642 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 643 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 644 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 645 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 646 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 647 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 648 | case -NFS4ERR_BADSLOT: |
| 649 | /* |
| 650 | * The slot id we used was probably retired. Try again |
| 651 | * using a different slot id. |
| 652 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 653 | goto retry_nowait; |
| 654 | case -NFS4ERR_SEQ_MISORDERED: |
| 655 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 656 | * Was the last operation on this sequence interrupted? |
| 657 | * If so, retry after bumping the sequence number. |
| 658 | */ |
| 659 | if (interrupted) { |
| 660 | ++slot->seq_nr; |
| 661 | goto retry_nowait; |
| 662 | } |
| 663 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 664 | * Could this slot have been previously retired? |
| 665 | * If so, then the server may be expecting seq_nr = 1! |
| 666 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 667 | if (slot->seq_nr != 1) { |
| 668 | slot->seq_nr = 1; |
| 669 | goto retry_nowait; |
| 670 | } |
| 671 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 672 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 673 | ++slot->seq_nr; |
| 674 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 675 | default: |
| 676 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 677 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 678 | } |
| 679 | out: |
| 680 | /* The session may be reset by one of the error handlers. */ |
| 681 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 682 | nfs41_sequence_free_slot(res); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 683 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 684 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 685 | retry_nowait: |
| 686 | if (rpc_restart_call_prepare(task)) { |
| 687 | task->tk_status = 0; |
| 688 | ret = 0; |
| 689 | } |
| 690 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 691 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 692 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 693 | goto out; |
| 694 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 695 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 696 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 697 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 698 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 699 | int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 700 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 701 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 702 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 703 | if (!res->sr_slot->table->session) |
| 704 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 705 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 706 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 707 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 708 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 709 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 710 | struct nfs4_sequence_args *args, |
| 711 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 712 | struct rpc_task *task) |
| 713 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 714 | struct nfs4_slot *slot; |
| 715 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 716 | |
| 717 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 718 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 719 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 720 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 721 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 722 | tbl = &session->fc_slot_table; |
| 723 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 724 | task->tk_timeout = 0; |
| 725 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 726 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 727 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 728 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 729 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 730 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 731 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 732 | } |
| 733 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 734 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 735 | if (IS_ERR(slot)) { |
| 736 | /* If out of memory, try again in 1/4 second */ |
| 737 | if (slot == ERR_PTR(-ENOMEM)) |
| 738 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 739 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 740 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 741 | } |
| 742 | spin_unlock(&tbl->slot_tbl_lock); |
| 743 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 744 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 745 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 746 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 747 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 748 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 749 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 750 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 751 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 752 | /* |
| 753 | * sr_status is only set in decode_sequence, and so will remain |
| 754 | * set to 1 if an rpc level failure occurs. |
| 755 | */ |
| 756 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 757 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 758 | out_success: |
| 759 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 760 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 761 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 762 | /* Privileged tasks are queued with top priority */ |
| 763 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 764 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 765 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 766 | else |
| 767 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 768 | spin_unlock(&tbl->slot_tbl_lock); |
| 769 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 770 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 771 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 772 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 773 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 774 | struct nfs4_sequence_args *args, |
| 775 | struct nfs4_sequence_res *res, |
| 776 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 777 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 778 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 779 | int ret = 0; |
| 780 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 781 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 782 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 783 | args, res, task); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 784 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 785 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 786 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 787 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 788 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 789 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 790 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 791 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 792 | return ret; |
| 793 | } |
| 794 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 795 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 796 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 797 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 798 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 799 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 800 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 801 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 802 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 803 | } |
| 804 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 805 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 806 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 807 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 808 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 809 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 810 | } |
| 811 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 812 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 813 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 814 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 815 | }; |
| 816 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 817 | #else /* !CONFIG_NFS_V4_1 */ |
| 818 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 819 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 820 | struct nfs4_sequence_args *args, |
| 821 | struct nfs4_sequence_res *res, |
| 822 | struct rpc_task *task) |
| 823 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 824 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 825 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 826 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 827 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 828 | int nfs4_sequence_done(struct rpc_task *task, |
| 829 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 830 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 831 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 832 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 833 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 834 | |
| 835 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 836 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 837 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 838 | { |
| 839 | struct nfs4_call_sync_data *data = calldata; |
| 840 | nfs4_setup_sequence(data->seq_server, |
| 841 | data->seq_args, data->seq_res, task); |
| 842 | } |
| 843 | |
| 844 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 845 | { |
| 846 | struct nfs4_call_sync_data *data = calldata; |
| 847 | nfs4_sequence_done(task, data->seq_res); |
| 848 | } |
| 849 | |
| 850 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 851 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 852 | .rpc_call_done = nfs40_call_sync_done, |
| 853 | }; |
| 854 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 855 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 856 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 857 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 858 | struct nfs4_sequence_args *args, |
| 859 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 860 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 861 | int ret; |
| 862 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 863 | struct nfs_client *clp = server->nfs_client; |
| 864 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 865 | .seq_server = server, |
| 866 | .seq_args = args, |
| 867 | .seq_res = res, |
| 868 | }; |
| 869 | struct rpc_task_setup task_setup = { |
| 870 | .rpc_client = clnt, |
| 871 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 872 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 873 | .callback_data = &data |
| 874 | }; |
| 875 | |
| 876 | task = rpc_run_task(&task_setup); |
| 877 | if (IS_ERR(task)) |
| 878 | ret = PTR_ERR(task); |
| 879 | else { |
| 880 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 881 | rpc_put_task(task); |
| 882 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 883 | return ret; |
| 884 | } |
| 885 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 886 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 887 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 888 | struct rpc_message *msg, |
| 889 | struct nfs4_sequence_args *args, |
| 890 | struct nfs4_sequence_res *res, |
| 891 | int cache_reply) |
| 892 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 893 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 894 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 895 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 898 | { |
| 899 | struct nfs_inode *nfsi = NFS_I(dir); |
| 900 | |
| 901 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 902 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 903 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 905 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 906 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 907 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | spin_unlock(&dir->i_lock); |
| 909 | } |
| 910 | |
| 911 | struct nfs4_opendata { |
| 912 | struct kref kref; |
| 913 | struct nfs_openargs o_arg; |
| 914 | struct nfs_openres o_res; |
| 915 | struct nfs_open_confirmargs c_arg; |
| 916 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 917 | struct nfs4_string owner_name; |
| 918 | struct nfs4_string group_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 920 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 922 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | struct nfs4_state_owner *owner; |
| 924 | struct nfs4_state *state; |
| 925 | struct iattr attrs; |
| 926 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 927 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 928 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 929 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 930 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | int cancelled; |
| 932 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 933 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 934 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 935 | int err, struct nfs4_exception *exception) |
| 936 | { |
| 937 | if (err != -EINVAL) |
| 938 | return false; |
| 939 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 940 | return false; |
| 941 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 942 | exception->retry = 1; |
| 943 | return true; |
| 944 | } |
| 945 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 946 | static u32 |
| 947 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 948 | fmode_t fmode, int openflags) |
| 949 | { |
| 950 | u32 res = 0; |
| 951 | |
| 952 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 953 | case FMODE_READ: |
| 954 | res = NFS4_SHARE_ACCESS_READ; |
| 955 | break; |
| 956 | case FMODE_WRITE: |
| 957 | res = NFS4_SHARE_ACCESS_WRITE; |
| 958 | break; |
| 959 | case FMODE_READ|FMODE_WRITE: |
| 960 | res = NFS4_SHARE_ACCESS_BOTH; |
| 961 | } |
| 962 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 963 | goto out; |
| 964 | /* Want no delegation if we're using O_DIRECT */ |
| 965 | if (openflags & O_DIRECT) |
| 966 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 967 | out: |
| 968 | return res; |
| 969 | } |
| 970 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 971 | static enum open_claim_type4 |
| 972 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 973 | enum open_claim_type4 claim) |
| 974 | { |
| 975 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 976 | return claim; |
| 977 | switch (claim) { |
| 978 | default: |
| 979 | return claim; |
| 980 | case NFS4_OPEN_CLAIM_FH: |
| 981 | return NFS4_OPEN_CLAIM_NULL; |
| 982 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 983 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 984 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 985 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 986 | } |
| 987 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
| 989 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 990 | { |
| 991 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 992 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 993 | p->o_res.seqid = p->o_arg.seqid; |
| 994 | p->c_res.seqid = p->c_arg.seqid; |
| 995 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 996 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 997 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 998 | 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] | 999 | } |
| 1000 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1001 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1002 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1003 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1004 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1005 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1006 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1007 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1008 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1009 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1010 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1011 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1012 | struct nfs4_opendata *p; |
| 1013 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1014 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1015 | if (p == NULL) |
| 1016 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1017 | |
| 1018 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1019 | if (IS_ERR(p->f_label)) |
| 1020 | goto err_free_p; |
| 1021 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1022 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1023 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1024 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1025 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1026 | nfs_sb_active(dentry->d_sb); |
| 1027 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1028 | p->dir = parent; |
| 1029 | p->owner = sp; |
| 1030 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | p->o_arg.open_flags = flags; |
| 1032 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1033 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1034 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1035 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1036 | * will return permission denied for all bits until close */ |
| 1037 | if (!(flags & O_EXCL)) { |
| 1038 | /* ask server to check for all possible rights as results |
| 1039 | * are cached */ |
| 1040 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1041 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1042 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1043 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1044 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1045 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1046 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1047 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1048 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1049 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1050 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1051 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1052 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1053 | case NFS4_OPEN_CLAIM_NULL: |
| 1054 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1055 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1056 | p->o_arg.fh = NFS_FH(dir); |
| 1057 | break; |
| 1058 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1059 | case NFS4_OPEN_CLAIM_FH: |
| 1060 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1061 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1062 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1063 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1064 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1065 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1066 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1067 | p->o_arg.u.attrs = &p->attrs; |
| 1068 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1069 | |
| 1070 | verf[0] = jiffies; |
| 1071 | verf[1] = current->pid; |
| 1072 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1073 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1074 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1075 | p->c_arg.fh = &p->o_res.fh; |
| 1076 | p->c_arg.stateid = &p->o_res.stateid; |
| 1077 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1078 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1079 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1080 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1081 | |
| 1082 | err_free_label: |
| 1083 | nfs4_label_free(p->f_label); |
| 1084 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1085 | kfree(p); |
| 1086 | err: |
| 1087 | dput(parent); |
| 1088 | return NULL; |
| 1089 | } |
| 1090 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1091 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1092 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1093 | struct nfs4_opendata *p = container_of(kref, |
| 1094 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1095 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1096 | |
| 1097 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1098 | if (p->state != NULL) |
| 1099 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1100 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1101 | |
| 1102 | nfs4_label_free(p->f_label); |
| 1103 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1104 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1105 | dput(p->dentry); |
| 1106 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1107 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1108 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1109 | kfree(p); |
| 1110 | } |
| 1111 | |
| 1112 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1113 | { |
| 1114 | if (p != NULL) |
| 1115 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1118 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1119 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1120 | int ret; |
| 1121 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1122 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1123 | return ret; |
| 1124 | } |
| 1125 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1126 | 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] | 1127 | { |
| 1128 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1129 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1130 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1131 | goto out; |
| 1132 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1133 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1134 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1135 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1136 | break; |
| 1137 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1138 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1139 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1140 | break; |
| 1141 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1142 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1143 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1144 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1145 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1146 | return ret; |
| 1147 | } |
| 1148 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1149 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1150 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1151 | if (delegation == NULL) |
| 1152 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1153 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1154 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1155 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1156 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1157 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1158 | return 1; |
| 1159 | } |
| 1160 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1161 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1162 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1163 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1164 | case FMODE_WRITE: |
| 1165 | state->n_wronly++; |
| 1166 | break; |
| 1167 | case FMODE_READ: |
| 1168 | state->n_rdonly++; |
| 1169 | break; |
| 1170 | case FMODE_READ|FMODE_WRITE: |
| 1171 | state->n_rdwr++; |
| 1172 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1173 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1176 | 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] | 1177 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1178 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1179 | bool need_recover = false; |
| 1180 | |
| 1181 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1182 | need_recover = true; |
| 1183 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1184 | need_recover = true; |
| 1185 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1186 | need_recover = true; |
| 1187 | if (need_recover) |
| 1188 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1189 | } |
| 1190 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1191 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1192 | nfs4_stateid *stateid) |
| 1193 | { |
| 1194 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1195 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1196 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1197 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1198 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1199 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1200 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1201 | return true; |
| 1202 | return false; |
| 1203 | } |
| 1204 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1205 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1206 | { |
| 1207 | if (state->n_wronly) |
| 1208 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1209 | if (state->n_rdonly) |
| 1210 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1211 | if (state->n_rdwr) |
| 1212 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1213 | } |
| 1214 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1215 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1216 | nfs4_stateid *stateid, fmode_t fmode) |
| 1217 | { |
| 1218 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1219 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1220 | case FMODE_WRITE: |
| 1221 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1222 | break; |
| 1223 | case FMODE_READ: |
| 1224 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1225 | break; |
| 1226 | case 0: |
| 1227 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1228 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1229 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1230 | } |
| 1231 | if (stateid == NULL) |
| 1232 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1233 | /* Handle races with OPEN */ |
| 1234 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid) || |
| 1235 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1236 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1237 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1238 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1239 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1240 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1241 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | static void nfs_clear_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1245 | { |
| 1246 | write_seqlock(&state->seqlock); |
| 1247 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
| 1248 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1249 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1250 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1251 | } |
| 1252 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1253 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1254 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1255 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1256 | case FMODE_READ: |
| 1257 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1258 | break; |
| 1259 | case FMODE_WRITE: |
| 1260 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1261 | break; |
| 1262 | case FMODE_READ|FMODE_WRITE: |
| 1263 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1264 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1265 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1266 | return; |
| 1267 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1268 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1269 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1272 | 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] | 1273 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1274 | /* |
| 1275 | * Protect the call to nfs4_state_set_mode_locked and |
| 1276 | * serialise the stateid update |
| 1277 | */ |
| 1278 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1279 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1280 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1281 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1282 | } |
| 1283 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1284 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1285 | write_sequnlock(&state->seqlock); |
| 1286 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1287 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1288 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1291 | 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] | 1292 | { |
| 1293 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1294 | struct nfs_delegation *deleg_cur; |
| 1295 | int ret = 0; |
| 1296 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1297 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1298 | |
| 1299 | rcu_read_lock(); |
| 1300 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1301 | if (deleg_cur == NULL) |
| 1302 | goto no_delegation; |
| 1303 | |
| 1304 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1305 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1306 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1307 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1308 | goto no_delegation_unlock; |
| 1309 | |
| 1310 | if (delegation == NULL) |
| 1311 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1312 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1313 | goto no_delegation_unlock; |
| 1314 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1315 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1316 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1317 | ret = 1; |
| 1318 | no_delegation_unlock: |
| 1319 | spin_unlock(&deleg_cur->lock); |
| 1320 | no_delegation: |
| 1321 | rcu_read_unlock(); |
| 1322 | |
| 1323 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1324 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1325 | ret = 1; |
| 1326 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1327 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1328 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1329 | |
| 1330 | return ret; |
| 1331 | } |
| 1332 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1333 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1334 | const nfs4_stateid *stateid) |
| 1335 | { |
| 1336 | struct nfs4_state *state = lsp->ls_state; |
| 1337 | bool ret = false; |
| 1338 | |
| 1339 | spin_lock(&state->state_lock); |
| 1340 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1341 | goto out_noupdate; |
| 1342 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1343 | goto out_noupdate; |
| 1344 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1345 | ret = true; |
| 1346 | out_noupdate: |
| 1347 | spin_unlock(&state->state_lock); |
| 1348 | return ret; |
| 1349 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1350 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1351 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1352 | { |
| 1353 | struct nfs_delegation *delegation; |
| 1354 | |
| 1355 | rcu_read_lock(); |
| 1356 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1357 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1358 | rcu_read_unlock(); |
| 1359 | return; |
| 1360 | } |
| 1361 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1362 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1363 | } |
| 1364 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1365 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1366 | { |
| 1367 | struct nfs4_state *state = opendata->state; |
| 1368 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1369 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1370 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1371 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1372 | nfs4_stateid stateid; |
| 1373 | int ret = -EAGAIN; |
| 1374 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1375 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1376 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1377 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1378 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1379 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1380 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1381 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1382 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1383 | rcu_read_lock(); |
| 1384 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1385 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1386 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1387 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1388 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1389 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1390 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1391 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1392 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1393 | if (!opendata->is_recover) { |
| 1394 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1395 | if (ret != 0) |
| 1396 | goto out; |
| 1397 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1398 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1399 | |
| 1400 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1401 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1402 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1403 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1404 | out: |
| 1405 | return ERR_PTR(ret); |
| 1406 | out_return_state: |
| 1407 | atomic_inc(&state->count); |
| 1408 | return state; |
| 1409 | } |
| 1410 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1411 | static void |
| 1412 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1413 | { |
| 1414 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1415 | struct nfs_delegation *delegation; |
| 1416 | int delegation_flags = 0; |
| 1417 | |
| 1418 | rcu_read_lock(); |
| 1419 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1420 | if (delegation) |
| 1421 | delegation_flags = delegation->flags; |
| 1422 | rcu_read_unlock(); |
| 1423 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1424 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1425 | "returning a delegation for " |
| 1426 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1427 | clp->cl_hostname); |
| 1428 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1429 | nfs_inode_set_delegation(state->inode, |
| 1430 | data->owner->so_cred, |
| 1431 | &data->o_res); |
| 1432 | else |
| 1433 | nfs_inode_reclaim_delegation(state->inode, |
| 1434 | data->owner->so_cred, |
| 1435 | &data->o_res); |
| 1436 | } |
| 1437 | |
| 1438 | /* |
| 1439 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1440 | * and update the nfs4_state. |
| 1441 | */ |
| 1442 | static struct nfs4_state * |
| 1443 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1444 | { |
| 1445 | struct inode *inode = data->state->inode; |
| 1446 | struct nfs4_state *state = data->state; |
| 1447 | int ret; |
| 1448 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1449 | if (!data->rpc_done) { |
| 1450 | if (data->rpc_status) { |
| 1451 | ret = data->rpc_status; |
| 1452 | goto err; |
| 1453 | } |
| 1454 | /* cached opens have already been processed */ |
| 1455 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1458 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1459 | if (ret) |
| 1460 | goto err; |
| 1461 | |
| 1462 | if (data->o_res.delegation_type != 0) |
| 1463 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1464 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1465 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1466 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1467 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1468 | |
| 1469 | return state; |
| 1470 | err: |
| 1471 | return ERR_PTR(ret); |
| 1472 | |
| 1473 | } |
| 1474 | |
| 1475 | static struct nfs4_state * |
| 1476 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1477 | { |
| 1478 | struct inode *inode; |
| 1479 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1480 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1481 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1482 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1483 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1484 | goto out; |
| 1485 | } |
| 1486 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1487 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1488 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1489 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1490 | 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] | 1491 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1492 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1493 | goto err; |
| 1494 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1495 | state = nfs4_get_open_state(inode, data->owner); |
| 1496 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1497 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1498 | if (data->o_res.delegation_type != 0) |
| 1499 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1500 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1501 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1502 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1503 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1504 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1505 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1506 | err_put_inode: |
| 1507 | iput(inode); |
| 1508 | err: |
| 1509 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1510 | } |
| 1511 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1512 | static struct nfs4_state * |
| 1513 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1514 | { |
| 1515 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1516 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1517 | return _nfs4_opendata_to_nfs4_state(data); |
| 1518 | } |
| 1519 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1520 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1521 | { |
| 1522 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1523 | struct nfs_open_context *ctx; |
| 1524 | |
| 1525 | spin_lock(&state->inode->i_lock); |
| 1526 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1527 | if (ctx->state != state) |
| 1528 | continue; |
| 1529 | get_nfs_open_context(ctx); |
| 1530 | spin_unlock(&state->inode->i_lock); |
| 1531 | return ctx; |
| 1532 | } |
| 1533 | spin_unlock(&state->inode->i_lock); |
| 1534 | return ERR_PTR(-ENOENT); |
| 1535 | } |
| 1536 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1537 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1538 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1539 | { |
| 1540 | struct nfs4_opendata *opendata; |
| 1541 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1542 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1543 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1544 | if (opendata == NULL) |
| 1545 | return ERR_PTR(-ENOMEM); |
| 1546 | opendata->state = state; |
| 1547 | atomic_inc(&state->count); |
| 1548 | return opendata; |
| 1549 | } |
| 1550 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1551 | 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] | 1552 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1553 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1554 | int ret; |
| 1555 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1556 | opendata->o_arg.open_flags = 0; |
| 1557 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1558 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1559 | NFS_SB(opendata->dentry->d_sb), |
| 1560 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1561 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1562 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1563 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1564 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1565 | if (ret != 0) |
| 1566 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1567 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1568 | if (IS_ERR(newstate)) |
| 1569 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1570 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1571 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1572 | return 0; |
| 1573 | } |
| 1574 | |
| 1575 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1576 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1577 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1578 | int ret; |
| 1579 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1580 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1581 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1582 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1583 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1584 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1585 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1586 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1587 | smp_rmb(); |
| 1588 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1589 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1590 | if (ret != 0) |
| 1591 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1592 | if (newstate != state) |
| 1593 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1594 | } |
| 1595 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1596 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1597 | if (ret != 0) |
| 1598 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1599 | if (newstate != state) |
| 1600 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1601 | } |
| 1602 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1603 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1604 | if (ret != 0) |
| 1605 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1606 | if (newstate != state) |
| 1607 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1608 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1609 | /* |
| 1610 | * We may have performed cached opens for all three recoveries. |
| 1611 | * Check if we need to update the current stateid. |
| 1612 | */ |
| 1613 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1614 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1615 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1616 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1617 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1618 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1619 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1620 | return 0; |
| 1621 | } |
| 1622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | /* |
| 1624 | * OPEN_RECLAIM: |
| 1625 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1627 | 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] | 1628 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1629 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1630 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1631 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | int status; |
| 1633 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1634 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1635 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1636 | if (IS_ERR(opendata)) |
| 1637 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1638 | rcu_read_lock(); |
| 1639 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1640 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1641 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1642 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1643 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1644 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1645 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | return status; |
| 1647 | } |
| 1648 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1649 | 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] | 1650 | { |
| 1651 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1652 | struct nfs4_exception exception = { }; |
| 1653 | int err; |
| 1654 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1655 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1656 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1657 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1658 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1659 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1660 | break; |
| 1661 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | } while (exception.retry); |
| 1663 | return err; |
| 1664 | } |
| 1665 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1666 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1667 | { |
| 1668 | struct nfs_open_context *ctx; |
| 1669 | int ret; |
| 1670 | |
| 1671 | ctx = nfs4_state_find_open_context(state); |
| 1672 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1673 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1674 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1675 | put_nfs_open_context(ctx); |
| 1676 | return ret; |
| 1677 | } |
| 1678 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1679 | 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] | 1680 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1681 | switch (err) { |
| 1682 | default: |
| 1683 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1684 | "%d.\n", __func__, err); |
| 1685 | case 0: |
| 1686 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame^] | 1687 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1688 | case -ESTALE: |
| 1689 | break; |
| 1690 | case -NFS4ERR_BADSESSION: |
| 1691 | case -NFS4ERR_BADSLOT: |
| 1692 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1693 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1694 | case -NFS4ERR_DEADSESSION: |
| 1695 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1696 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1697 | return -EAGAIN; |
| 1698 | case -NFS4ERR_STALE_CLIENTID: |
| 1699 | case -NFS4ERR_STALE_STATEID: |
| 1700 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1701 | case -NFS4ERR_EXPIRED: |
| 1702 | /* Don't recall a delegation if it was lost */ |
| 1703 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1704 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1705 | case -NFS4ERR_MOVED: |
| 1706 | nfs4_schedule_migration_recovery(server); |
| 1707 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1708 | case -NFS4ERR_LEASE_MOVED: |
| 1709 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1710 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1711 | case -NFS4ERR_DELEG_REVOKED: |
| 1712 | case -NFS4ERR_ADMIN_REVOKED: |
| 1713 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1714 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1715 | nfs_inode_find_state_and_recover(state->inode, |
| 1716 | stateid); |
| 1717 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1718 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1719 | case -NFS4ERR_DELAY: |
| 1720 | case -NFS4ERR_GRACE: |
| 1721 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1722 | ssleep(1); |
| 1723 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1724 | case -ENOMEM: |
| 1725 | case -NFS4ERR_DENIED: |
| 1726 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1727 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | return err; |
| 1730 | } |
| 1731 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1732 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1733 | { |
| 1734 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1735 | struct nfs4_opendata *opendata; |
| 1736 | int err; |
| 1737 | |
| 1738 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1739 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1740 | if (IS_ERR(opendata)) |
| 1741 | return PTR_ERR(opendata); |
| 1742 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1743 | err = nfs4_open_recover(opendata, state); |
| 1744 | nfs4_opendata_put(opendata); |
| 1745 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1746 | } |
| 1747 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1748 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1749 | { |
| 1750 | struct nfs4_opendata *data = calldata; |
| 1751 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1752 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1753 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1754 | } |
| 1755 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1756 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1757 | { |
| 1758 | struct nfs4_opendata *data = calldata; |
| 1759 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1760 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1761 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1762 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1763 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1764 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1765 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1766 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1767 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1768 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | static void nfs4_open_confirm_release(void *calldata) |
| 1772 | { |
| 1773 | struct nfs4_opendata *data = calldata; |
| 1774 | struct nfs4_state *state = NULL; |
| 1775 | |
| 1776 | /* If this request hasn't been cancelled, do nothing */ |
| 1777 | if (data->cancelled == 0) |
| 1778 | goto out_free; |
| 1779 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1780 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1781 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1782 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1783 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1784 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1785 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1786 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1790 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1791 | .rpc_call_done = nfs4_open_confirm_done, |
| 1792 | .rpc_release = nfs4_open_confirm_release, |
| 1793 | }; |
| 1794 | |
| 1795 | /* |
| 1796 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1797 | */ |
| 1798 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1799 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1800 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1801 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1802 | struct rpc_message msg = { |
| 1803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1804 | .rpc_argp = &data->c_arg, |
| 1805 | .rpc_resp = &data->c_res, |
| 1806 | .rpc_cred = data->owner->so_cred, |
| 1807 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1808 | struct rpc_task_setup task_setup_data = { |
| 1809 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1810 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1811 | .callback_ops = &nfs4_open_confirm_ops, |
| 1812 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1813 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1814 | .flags = RPC_TASK_ASYNC, |
| 1815 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | int status; |
| 1817 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1818 | 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] | 1819 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1820 | data->rpc_done = 0; |
| 1821 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1822 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1823 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1824 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1825 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1826 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1827 | if (status != 0) { |
| 1828 | data->cancelled = 1; |
| 1829 | smp_wmb(); |
| 1830 | } else |
| 1831 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1832 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | return status; |
| 1834 | } |
| 1835 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1836 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1838 | struct nfs4_opendata *data = calldata; |
| 1839 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1840 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1841 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1842 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1843 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1844 | /* |
| 1845 | * Check if we still need to send an OPEN call, or if we can use |
| 1846 | * a delegation instead. |
| 1847 | */ |
| 1848 | if (data->state != NULL) { |
| 1849 | struct nfs_delegation *delegation; |
| 1850 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1851 | 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] | 1852 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1853 | rcu_read_lock(); |
| 1854 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1855 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1856 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1857 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1858 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1859 | rcu_read_unlock(); |
| 1860 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1861 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1862 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1863 | switch (data->o_arg.claim) { |
| 1864 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1865 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1866 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1867 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1868 | case NFS4_OPEN_CLAIM_FH: |
| 1869 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1870 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1871 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1872 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1873 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1874 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1875 | &data->o_res.seq_res, |
| 1876 | task) != 0) |
| 1877 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1878 | |
| 1879 | /* Set the create mode (note dependency on the session type) */ |
| 1880 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1881 | if (data->o_arg.open_flags & O_EXCL) { |
| 1882 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1883 | if (nfs4_has_persistent_session(clp)) |
| 1884 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1885 | else if (clp->cl_mvops->minor_version > 0) |
| 1886 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1887 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1888 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1889 | unlock_no_action: |
| 1890 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1891 | out_no_action: |
| 1892 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1893 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1894 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1895 | } |
| 1896 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1897 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1898 | { |
| 1899 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1901 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1902 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1903 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1904 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1905 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1906 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1907 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1908 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1909 | case S_IFREG: |
| 1910 | break; |
| 1911 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1912 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1913 | break; |
| 1914 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1915 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1916 | break; |
| 1917 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1918 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1919 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1920 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1921 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1922 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1923 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1924 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1925 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1926 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1927 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1928 | static void nfs4_open_release(void *calldata) |
| 1929 | { |
| 1930 | struct nfs4_opendata *data = calldata; |
| 1931 | struct nfs4_state *state = NULL; |
| 1932 | |
| 1933 | /* If this request hasn't been cancelled, do nothing */ |
| 1934 | if (data->cancelled == 0) |
| 1935 | goto out_free; |
| 1936 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1937 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1938 | goto out_free; |
| 1939 | /* In case we need an open_confirm, no cleanup! */ |
| 1940 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1941 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1942 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1943 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1944 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1945 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1946 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1950 | .rpc_call_prepare = nfs4_open_prepare, |
| 1951 | .rpc_call_done = nfs4_open_done, |
| 1952 | .rpc_release = nfs4_open_release, |
| 1953 | }; |
| 1954 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1955 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1956 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1957 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1958 | struct nfs_server *server = NFS_SERVER(dir); |
| 1959 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1960 | struct nfs_openres *o_res = &data->o_res; |
| 1961 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1962 | struct rpc_message msg = { |
| 1963 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1964 | .rpc_argp = o_arg, |
| 1965 | .rpc_resp = o_res, |
| 1966 | .rpc_cred = data->owner->so_cred, |
| 1967 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1968 | struct rpc_task_setup task_setup_data = { |
| 1969 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1970 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1971 | .callback_ops = &nfs4_open_ops, |
| 1972 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1973 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1974 | .flags = RPC_TASK_ASYNC, |
| 1975 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1976 | int status; |
| 1977 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1978 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1979 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1980 | data->rpc_done = 0; |
| 1981 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1982 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1983 | data->is_recover = 0; |
| 1984 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1985 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1986 | data->is_recover = 1; |
| 1987 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1988 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1989 | if (IS_ERR(task)) |
| 1990 | return PTR_ERR(task); |
| 1991 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1992 | if (status != 0) { |
| 1993 | data->cancelled = 1; |
| 1994 | smp_wmb(); |
| 1995 | } else |
| 1996 | status = data->rpc_status; |
| 1997 | rpc_put_task(task); |
| 1998 | |
| 1999 | return status; |
| 2000 | } |
| 2001 | |
| 2002 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2003 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2004 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2005 | struct nfs_openres *o_res = &data->o_res; |
| 2006 | int status; |
| 2007 | |
| 2008 | status = nfs4_run_open_task(data, 1); |
| 2009 | if (status != 0 || !data->rpc_done) |
| 2010 | return status; |
| 2011 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2012 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2013 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2014 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2015 | status = _nfs4_proc_open_confirm(data); |
| 2016 | if (status != 0) |
| 2017 | return status; |
| 2018 | } |
| 2019 | |
| 2020 | return status; |
| 2021 | } |
| 2022 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2023 | /* |
| 2024 | * Additional permission checks in order to distinguish between an |
| 2025 | * open for read, and an open for execute. This works around the |
| 2026 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2027 | * the same. |
| 2028 | * Note that in the non-execute case, we want to turn off permission |
| 2029 | * checking if we just created a new file (POSIX open() semantics). |
| 2030 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2031 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2032 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2033 | struct nfs4_state *state, fmode_t fmode, |
| 2034 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2035 | { |
| 2036 | struct nfs_access_entry cache; |
| 2037 | u32 mask; |
| 2038 | |
| 2039 | /* access call failed or for some reason the server doesn't |
| 2040 | * support any access modes -- defer access call until later */ |
| 2041 | if (opendata->o_res.access_supported == 0) |
| 2042 | return 0; |
| 2043 | |
| 2044 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2045 | /* |
| 2046 | * Use openflags to check for exec, because fmode won't |
| 2047 | * always have FMODE_EXEC set when file open for exec. |
| 2048 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2049 | if (openflags & __FMODE_EXEC) { |
| 2050 | /* ONLY check for exec rights */ |
| 2051 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2052 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2053 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2054 | |
| 2055 | cache.cred = cred; |
| 2056 | cache.jiffies = jiffies; |
| 2057 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2058 | nfs_access_add_cache(state->inode, &cache); |
| 2059 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2060 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2061 | return 0; |
| 2062 | |
| 2063 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2064 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2065 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2066 | } |
| 2067 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2068 | /* |
| 2069 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2070 | */ |
| 2071 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2072 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2073 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2074 | struct nfs_server *server = NFS_SERVER(dir); |
| 2075 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2076 | struct nfs_openres *o_res = &data->o_res; |
| 2077 | int status; |
| 2078 | |
| 2079 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2080 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2081 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2082 | if (status != 0) { |
| 2083 | if (status == -NFS4ERR_BADNAME && |
| 2084 | !(o_arg->open_flags & O_CREAT)) |
| 2085 | return -ENOENT; |
| 2086 | return status; |
| 2087 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2088 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2089 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2090 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2091 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2092 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2093 | if (o_arg->open_flags & O_EXCL) |
| 2094 | data->file_created = 1; |
| 2095 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2096 | data->file_created = 1; |
| 2097 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2098 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2099 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2101 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2103 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | } |
| 2105 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2106 | 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] | 2107 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2110 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2111 | { |
| 2112 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2113 | } |
| 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | /* |
| 2116 | * OPEN_EXPIRED: |
| 2117 | * reclaim state on the server after a network partition. |
| 2118 | * Assumes caller holds the appropriate lock |
| 2119 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2120 | 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] | 2121 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2122 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2123 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2125 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2126 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2127 | if (IS_ERR(opendata)) |
| 2128 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2129 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2130 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2131 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2132 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2133 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2136 | 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] | 2137 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2138 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2139 | struct nfs4_exception exception = { }; |
| 2140 | int err; |
| 2141 | |
| 2142 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2143 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2144 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2145 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2146 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2147 | switch (err) { |
| 2148 | default: |
| 2149 | goto out; |
| 2150 | case -NFS4ERR_GRACE: |
| 2151 | case -NFS4ERR_DELAY: |
| 2152 | nfs4_handle_exception(server, err, &exception); |
| 2153 | err = 0; |
| 2154 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2155 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2156 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2157 | return err; |
| 2158 | } |
| 2159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2161 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2163 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2165 | ctx = nfs4_state_find_open_context(state); |
| 2166 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2167 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2168 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2169 | put_nfs_open_context(ctx); |
| 2170 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2173 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2174 | { |
| 2175 | nfs_remove_bad_delegation(state->inode); |
| 2176 | write_seqlock(&state->seqlock); |
| 2177 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2178 | write_sequnlock(&state->seqlock); |
| 2179 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2180 | } |
| 2181 | |
| 2182 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2183 | { |
| 2184 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2185 | nfs_finish_clear_delegation_stateid(state); |
| 2186 | } |
| 2187 | |
| 2188 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2189 | { |
| 2190 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2191 | nfs40_clear_delegation_stateid(state); |
| 2192 | return nfs4_open_expired(sp, state); |
| 2193 | } |
| 2194 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2195 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2196 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2197 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2198 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2199 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2200 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2201 | struct rpc_cred *cred; |
| 2202 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2203 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2204 | /* Get the delegation credential for use by test/free_stateid */ |
| 2205 | rcu_read_lock(); |
| 2206 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2207 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2208 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2209 | return; |
| 2210 | } |
| 2211 | |
| 2212 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2213 | cred = get_rpccred(delegation->cred); |
| 2214 | rcu_read_unlock(); |
| 2215 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2216 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2217 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2218 | if (status != NFS_OK) { |
| 2219 | /* Free the stateid unless the server explicitly |
| 2220 | * informs us the stateid is unrecognized. */ |
| 2221 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2222 | nfs41_free_stateid(server, &stateid, cred); |
| 2223 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2224 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2225 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2226 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | /** |
| 2230 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2231 | * |
| 2232 | * @state: NFSv4 state for an inode |
| 2233 | * |
| 2234 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2235 | * Otherwise a negative NFS4ERR value is returned. |
| 2236 | */ |
| 2237 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2238 | { |
| 2239 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2240 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2241 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2242 | int status; |
| 2243 | |
| 2244 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2245 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2246 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2247 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2248 | return -NFS4ERR_BAD_STATEID; |
| 2249 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2250 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2251 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2252 | if (status != NFS_OK) { |
| 2253 | /* Free the stateid unless the server explicitly |
| 2254 | * informs us the stateid is unrecognized. */ |
| 2255 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2256 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2257 | |
| 2258 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2259 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2260 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2261 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2262 | } |
| 2263 | return status; |
| 2264 | } |
| 2265 | |
| 2266 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2267 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2268 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2269 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2270 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2271 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2272 | if (status != NFS_OK) |
| 2273 | status = nfs4_open_expired(sp, state); |
| 2274 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2275 | } |
| 2276 | #endif |
| 2277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2279 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2280 | * fields corresponding to attributes that were used to store the verifier. |
| 2281 | * Make sure we clobber those fields in the later setattr call |
| 2282 | */ |
| 2283 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2284 | { |
| 2285 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2286 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2287 | sattr->ia_valid |= ATTR_ATIME; |
| 2288 | |
| 2289 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2290 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2291 | sattr->ia_valid |= ATTR_MTIME; |
| 2292 | } |
| 2293 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2294 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2295 | fmode_t fmode, |
| 2296 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2297 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2298 | { |
| 2299 | struct nfs4_state_owner *sp = opendata->owner; |
| 2300 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2301 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2302 | struct nfs4_state *state; |
| 2303 | unsigned int seq; |
| 2304 | int ret; |
| 2305 | |
| 2306 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2307 | |
| 2308 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2309 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2310 | goto out; |
| 2311 | |
| 2312 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2313 | ret = PTR_ERR(state); |
| 2314 | if (IS_ERR(state)) |
| 2315 | goto out; |
| 2316 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2317 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2318 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2319 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2320 | if (d_really_is_negative(dentry)) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2321 | /* FIXME: Is this d_drop() ever needed? */ |
| 2322 | d_drop(dentry); |
| 2323 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2324 | if (dentry == NULL) { |
| 2325 | dentry = opendata->dentry; |
| 2326 | } else if (dentry != ctx->dentry) { |
| 2327 | dput(ctx->dentry); |
| 2328 | ctx->dentry = dget(dentry); |
| 2329 | } |
| 2330 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2331 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2332 | } |
| 2333 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2334 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2335 | if (ret != 0) |
| 2336 | goto out; |
| 2337 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2338 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2339 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2340 | nfs_inode_attach_open_context(ctx); |
| 2341 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2342 | nfs4_schedule_stateid_recovery(server, state); |
| 2343 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2344 | out: |
| 2345 | return ret; |
| 2346 | } |
| 2347 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2348 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2349 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2351 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2352 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2353 | int flags, |
| 2354 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2355 | struct nfs4_label *label, |
| 2356 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | { |
| 2358 | struct nfs4_state_owner *sp; |
| 2359 | struct nfs4_state *state = NULL; |
| 2360 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2361 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2362 | struct dentry *dentry = ctx->dentry; |
| 2363 | struct rpc_cred *cred = ctx->cred; |
| 2364 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2365 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2366 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2367 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2368 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | |
| 2370 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2372 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2373 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2375 | goto out_err; |
| 2376 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2377 | status = nfs4_recover_expired_lease(server); |
| 2378 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2379 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2380 | if (d_really_is_positive(dentry)) |
| 2381 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2382 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2383 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2384 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2385 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2386 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2387 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2388 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2390 | if (label) { |
| 2391 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2392 | if (IS_ERR(olabel)) { |
| 2393 | status = PTR_ERR(olabel); |
| 2394 | goto err_opendata_put; |
| 2395 | } |
| 2396 | } |
| 2397 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2398 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2399 | if (!opendata->f_attr.mdsthreshold) { |
| 2400 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2401 | if (!opendata->f_attr.mdsthreshold) |
| 2402 | goto err_free_label; |
| 2403 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2404 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2405 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2406 | if (d_really_is_positive(dentry)) |
| 2407 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2408 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2409 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2410 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2411 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2412 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2413 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2414 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2415 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2416 | nfs4_exclusive_attrset(opendata, sattr); |
| 2417 | |
| 2418 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2419 | status = nfs4_do_setattr(state->inode, cred, |
| 2420 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2421 | state, label, olabel); |
| 2422 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 2423 | nfs_setattr_update_inode(state->inode, sattr, |
| 2424 | opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2425 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2426 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2427 | } |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2428 | if (opendata->file_created) |
| 2429 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2430 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2431 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2432 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2433 | opendata->f_attr.mdsthreshold = NULL; |
| 2434 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2435 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2436 | nfs4_label_free(olabel); |
| 2437 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2438 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2441 | err_free_label: |
| 2442 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2443 | err_opendata_put: |
| 2444 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2445 | err_put_state_owner: |
| 2446 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | return status; |
| 2449 | } |
| 2450 | |
| 2451 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2452 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2453 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2454 | int flags, |
| 2455 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2456 | struct nfs4_label *label, |
| 2457 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2459 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | struct nfs4_exception exception = { }; |
| 2461 | struct nfs4_state *res; |
| 2462 | int status; |
| 2463 | |
| 2464 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2465 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2466 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2467 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | if (status == 0) |
| 2469 | break; |
| 2470 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2471 | * book-keeping w.r.t. state-changing operations |
| 2472 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2473 | * It is actually a sign of a bug on the client or on the server. |
| 2474 | * |
| 2475 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2476 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | * have unhashed the old state_owner for us, and that we can |
| 2478 | * therefore safely retry using a new one. We should still warn |
| 2479 | * the user though... |
| 2480 | */ |
| 2481 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2482 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2483 | " returned a bad sequence-id error!\n", |
| 2484 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | exception.retry = 1; |
| 2486 | continue; |
| 2487 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2488 | /* |
| 2489 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2490 | * state before it received the OPEN_CONFIRM. |
| 2491 | * Recover by retrying the request as per the discussion |
| 2492 | * on Page 181 of RFC3530. |
| 2493 | */ |
| 2494 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2495 | exception.retry = 1; |
| 2496 | continue; |
| 2497 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2498 | if (status == -EAGAIN) { |
| 2499 | /* We must have found a delegation */ |
| 2500 | exception.retry = 1; |
| 2501 | continue; |
| 2502 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2503 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2504 | continue; |
| 2505 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | status, &exception)); |
| 2507 | } while (exception.retry); |
| 2508 | return res; |
| 2509 | } |
| 2510 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2511 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2512 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2513 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2514 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2516 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2518 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | .iap = sattr, |
| 2520 | .server = server, |
| 2521 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2522 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | }; |
| 2524 | struct nfs_setattrres res = { |
| 2525 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2526 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | .server = server, |
| 2528 | }; |
| 2529 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2530 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2531 | .rpc_argp = &arg, |
| 2532 | .rpc_resp = &res, |
| 2533 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2535 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2536 | fmode_t fmode; |
| 2537 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2538 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2540 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2541 | if (ilabel) |
| 2542 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2543 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2544 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2546 | /* Servers should only apply open mode checks for file size changes */ |
| 2547 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2548 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2549 | |
| 2550 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2551 | /* Use that stateid */ |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2552 | } else if (truncate && state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2553 | struct nfs_lockowner lockowner = { |
| 2554 | .l_owner = current->files, |
| 2555 | .l_pid = current->tgid, |
| 2556 | }; |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2557 | if (!nfs4_valid_open_stateid(state)) |
| 2558 | return -EBADF; |
| 2559 | if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2560 | &lockowner) == -EIO) |
| 2561 | return -EBADF; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2562 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2563 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2565 | 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] | 2566 | if (status == 0 && state != NULL) |
| 2567 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2568 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2571 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2572 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2573 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2574 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2576 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2577 | struct nfs4_exception exception = { |
| 2578 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2579 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2580 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | int err; |
| 2582 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2583 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2584 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2585 | switch (err) { |
| 2586 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2587 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2588 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2589 | "applying open mode checks to " |
| 2590 | "a SETATTR that is not " |
| 2591 | "changing file size.\n", |
| 2592 | server->nfs_client->cl_hostname); |
| 2593 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2594 | if (state && !(state->state & FMODE_WRITE)) { |
| 2595 | err = -EBADF; |
| 2596 | if (sattr->ia_valid & ATTR_OPEN) |
| 2597 | err = -EACCES; |
| 2598 | goto out; |
| 2599 | } |
| 2600 | } |
| 2601 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2603 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | return err; |
| 2605 | } |
| 2606 | |
| 2607 | struct nfs4_closedata { |
| 2608 | struct inode *inode; |
| 2609 | struct nfs4_state *state; |
| 2610 | struct nfs_closeargs arg; |
| 2611 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2612 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2613 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2614 | bool roc; |
| 2615 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | }; |
| 2617 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2618 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2619 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2620 | struct nfs4_closedata *calldata = data; |
| 2621 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2622 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2623 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2624 | if (calldata->roc) |
| 2625 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2626 | nfs4_put_open_state(calldata->state); |
| 2627 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2628 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2629 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2630 | kfree(calldata); |
| 2631 | } |
| 2632 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2633 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2635 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2638 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2640 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2641 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2642 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2643 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | /* hmm. we are done with the inode, and in the process of freeing |
| 2645 | * the state_owner. we keep this around to process errors |
| 2646 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | switch (task->tk_status) { |
| 2648 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2649 | res_stateid = &calldata->res.stateid; |
| 2650 | if (calldata->arg.fmode == 0 && calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2651 | pnfs_roc_set_barrier(state->inode, |
| 2652 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2653 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2654 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2655 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2657 | case -NFS4ERR_OLD_STATEID: |
| 2658 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2660 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2661 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2662 | rpc_restart_call_prepare(task); |
| 2663 | goto out_release; |
| 2664 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2665 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2666 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2668 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2669 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2670 | goto out_release; |
| 2671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | } |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2673 | nfs_clear_open_stateid(state, res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2674 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2675 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2676 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2677 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2680 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2682 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2683 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2684 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2685 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2686 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2687 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2688 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2689 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2690 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2691 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2692 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2693 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2694 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2695 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2696 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2697 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2698 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2699 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2700 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2701 | if (state->n_rdonly == 0) |
| 2702 | call_close |= is_rdonly; |
| 2703 | else if (is_rdonly) |
| 2704 | calldata->arg.fmode |= FMODE_READ; |
| 2705 | if (state->n_wronly == 0) |
| 2706 | call_close |= is_wronly; |
| 2707 | else if (is_wronly) |
| 2708 | calldata->arg.fmode |= FMODE_WRITE; |
| 2709 | } else if (is_rdwr) |
| 2710 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2711 | |
| 2712 | if (calldata->arg.fmode == 0) |
| 2713 | call_close |= is_rdwr; |
| 2714 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2715 | if (!nfs4_valid_open_stateid(state)) |
| 2716 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2717 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2718 | |
| 2719 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2720 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2721 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2722 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2723 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2724 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2725 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2726 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2727 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2728 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2729 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2730 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2731 | } |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2732 | calldata->arg.share_access = |
| 2733 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 2734 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2735 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2736 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2737 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2738 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2739 | &calldata->arg.seq_args, |
| 2740 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2741 | task) != 0) |
| 2742 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2743 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2744 | return; |
| 2745 | out_no_action: |
| 2746 | task->tk_action = NULL; |
| 2747 | out_wait: |
| 2748 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2751 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2752 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2753 | .rpc_call_done = nfs4_close_done, |
| 2754 | .rpc_release = nfs4_free_closedata, |
| 2755 | }; |
| 2756 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2757 | static bool nfs4_roc(struct inode *inode) |
| 2758 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 2759 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2760 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2761 | return pnfs_roc(inode); |
| 2762 | } |
| 2763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | /* |
| 2765 | * It is possible for data to be read/written from a mem-mapped file |
| 2766 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2767 | * This means that we can't safely call nfsv4 close on a file until |
| 2768 | * the inode is cleared. This in turn means that we are not good |
| 2769 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2770 | * share state even when we are done with one of the three share |
| 2771 | * stateid's in the inode. |
| 2772 | * |
| 2773 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2774 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2775 | 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] | 2776 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2777 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2778 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2780 | struct nfs4_state_owner *sp = state->owner; |
| 2781 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2782 | struct rpc_message msg = { |
| 2783 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2784 | .rpc_cred = state->owner->so_cred, |
| 2785 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2786 | struct rpc_task_setup task_setup_data = { |
| 2787 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2788 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2789 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2790 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2791 | .flags = RPC_TASK_ASYNC, |
| 2792 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2793 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2795 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2796 | &task_setup_data.rpc_client, &msg); |
| 2797 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2798 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2800 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2801 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2802 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2804 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2806 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 2807 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 2808 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2809 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2810 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2811 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2812 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2813 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2814 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2815 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2816 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2817 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2818 | msg.rpc_argp = &calldata->arg; |
| 2819 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2820 | task_setup_data.callback_data = calldata; |
| 2821 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2822 | if (IS_ERR(task)) |
| 2823 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2824 | status = 0; |
| 2825 | if (wait) |
| 2826 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2827 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2828 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2829 | out_free_calldata: |
| 2830 | kfree(calldata); |
| 2831 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2832 | nfs4_put_open_state(state); |
| 2833 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2834 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2837 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2838 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 2839 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2842 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2843 | |
| 2844 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2846 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2847 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2848 | |
| 2849 | nfs4_label_release_security(label); |
| 2850 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2851 | if (IS_ERR(state)) |
| 2852 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2853 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2856 | 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] | 2857 | { |
| 2858 | if (ctx->state == NULL) |
| 2859 | return; |
| 2860 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2861 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2862 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2863 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2866 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 2867 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 2868 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2871 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2872 | struct nfs4_server_caps_arg args = { |
| 2873 | .fhandle = fhandle, |
| 2874 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | struct nfs4_server_caps_res res = {}; |
| 2876 | struct rpc_message msg = { |
| 2877 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2878 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | .rpc_resp = &res, |
| 2880 | }; |
| 2881 | int status; |
| 2882 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2883 | 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] | 2884 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2885 | /* Sanity check the server answers */ |
| 2886 | switch (server->nfs_client->cl_minorversion) { |
| 2887 | case 0: |
| 2888 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 2889 | res.attr_bitmask[2] = 0; |
| 2890 | break; |
| 2891 | case 1: |
| 2892 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 2893 | break; |
| 2894 | case 2: |
| 2895 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 2896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2898 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2899 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2900 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2901 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2902 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 2903 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 2904 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 2905 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | server->caps |= NFS_CAP_ACLS; |
| 2907 | if (res.has_links != 0) |
| 2908 | server->caps |= NFS_CAP_HARDLINKS; |
| 2909 | if (res.has_symlinks != 0) |
| 2910 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2911 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2912 | server->caps |= NFS_CAP_FILEID; |
| 2913 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2914 | server->caps |= NFS_CAP_MODE; |
| 2915 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2916 | server->caps |= NFS_CAP_NLINK; |
| 2917 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2918 | server->caps |= NFS_CAP_OWNER; |
| 2919 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2920 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2921 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2922 | server->caps |= NFS_CAP_ATIME; |
| 2923 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2924 | server->caps |= NFS_CAP_CTIME; |
| 2925 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2926 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2927 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2928 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2929 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2930 | #endif |
| 2931 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2932 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2933 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2934 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2935 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2936 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2937 | 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] | 2938 | server->cache_consistency_bitmask[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2940 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | return status; |
| 2944 | } |
| 2945 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2946 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | { |
| 2948 | struct nfs4_exception exception = { }; |
| 2949 | int err; |
| 2950 | do { |
| 2951 | err = nfs4_handle_exception(server, |
| 2952 | _nfs4_server_capabilities(server, fhandle), |
| 2953 | &exception); |
| 2954 | } while (exception.retry); |
| 2955 | return err; |
| 2956 | } |
| 2957 | |
| 2958 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2959 | struct nfs_fsinfo *info) |
| 2960 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2961 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2963 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | }; |
| 2965 | struct nfs4_lookup_res res = { |
| 2966 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2967 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | .fh = fhandle, |
| 2969 | }; |
| 2970 | struct rpc_message msg = { |
| 2971 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2972 | .rpc_argp = &args, |
| 2973 | .rpc_resp = &res, |
| 2974 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2975 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2976 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2977 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2978 | /* |
| 2979 | * Process the label in the upcoming getfattr |
| 2980 | */ |
| 2981 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2982 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2983 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2984 | 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] | 2985 | } |
| 2986 | |
| 2987 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2988 | struct nfs_fsinfo *info) |
| 2989 | { |
| 2990 | struct nfs4_exception exception = { }; |
| 2991 | int err; |
| 2992 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2993 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2994 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2995 | switch (err) { |
| 2996 | case 0: |
| 2997 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2998 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2999 | default: |
| 3000 | err = nfs4_handle_exception(server, err, &exception); |
| 3001 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3003 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | return err; |
| 3005 | } |
| 3006 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3007 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3008 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3009 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3010 | struct rpc_auth_create_args auth_args = { |
| 3011 | .pseudoflavor = flavor, |
| 3012 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3013 | struct rpc_auth *auth; |
| 3014 | int ret; |
| 3015 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3016 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3017 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3018 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3019 | goto out; |
| 3020 | } |
| 3021 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3022 | out: |
| 3023 | return ret; |
| 3024 | } |
| 3025 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3026 | /* |
| 3027 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3028 | * |
| 3029 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3030 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3031 | * |
| 3032 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3033 | * negative errno value. |
| 3034 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3035 | 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] | 3036 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3038 | /* Per 3530bis 15.33.5 */ |
| 3039 | static const rpc_authflavor_t flav_array[] = { |
| 3040 | RPC_AUTH_GSS_KRB5P, |
| 3041 | RPC_AUTH_GSS_KRB5I, |
| 3042 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3043 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3044 | RPC_AUTH_NULL, |
| 3045 | }; |
| 3046 | int status = -EPERM; |
| 3047 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3049 | if (server->auth_info.flavor_len > 0) { |
| 3050 | /* try each flavor specified by user */ |
| 3051 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3052 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3053 | server->auth_info.flavors[i]); |
| 3054 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3055 | continue; |
| 3056 | break; |
| 3057 | } |
| 3058 | } else { |
| 3059 | /* no flavors specified by user, try default list */ |
| 3060 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3061 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3062 | flav_array[i]); |
| 3063 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3064 | continue; |
| 3065 | break; |
| 3066 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3067 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3068 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3069 | /* |
| 3070 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3071 | * to access the mount. It could also mean that we tried to mount |
| 3072 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3073 | * existing mount programs don't handle -EACCES very well so it should |
| 3074 | * be mapped to -EPERM instead. |
| 3075 | */ |
| 3076 | if (status == -EACCES) |
| 3077 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3078 | return status; |
| 3079 | } |
| 3080 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3081 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 3082 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 3083 | { |
| 3084 | int mv = server->nfs_client->cl_minorversion; |
| 3085 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 3086 | } |
| 3087 | |
| 3088 | /** |
| 3089 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3090 | * @server: initialized nfs_server handle |
| 3091 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3092 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3093 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3094 | * |
| 3095 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3096 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3097 | 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] | 3098 | struct nfs_fsinfo *info, |
| 3099 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3100 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3101 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3102 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3103 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3104 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3105 | |
| 3106 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3107 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 3108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | if (status == 0) |
| 3110 | status = nfs4_server_capabilities(server, fhandle); |
| 3111 | if (status == 0) |
| 3112 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3113 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3114 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3117 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3118 | struct nfs_fsinfo *info) |
| 3119 | { |
| 3120 | int error; |
| 3121 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3122 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3123 | |
| 3124 | error = nfs4_server_capabilities(server, mntfh); |
| 3125 | if (error < 0) { |
| 3126 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3127 | return error; |
| 3128 | } |
| 3129 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3130 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3131 | if (IS_ERR(label)) |
| 3132 | return PTR_ERR(label); |
| 3133 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3134 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3135 | if (error < 0) { |
| 3136 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3137 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3141 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3142 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3143 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3144 | err_free_label: |
| 3145 | nfs4_label_free(label); |
| 3146 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3147 | return error; |
| 3148 | } |
| 3149 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3150 | /* |
| 3151 | * Get locations and (maybe) other attributes of a referral. |
| 3152 | * Note that we'll actually follow the referral later when |
| 3153 | * we detect fsid mismatch in inode revalidation |
| 3154 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3155 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3156 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3157 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3158 | { |
| 3159 | int status = -ENOMEM; |
| 3160 | struct page *page = NULL; |
| 3161 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3162 | |
| 3163 | page = alloc_page(GFP_KERNEL); |
| 3164 | if (page == NULL) |
| 3165 | goto out; |
| 3166 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3167 | if (locations == NULL) |
| 3168 | goto out; |
| 3169 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3170 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3171 | if (status != 0) |
| 3172 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3173 | |
| 3174 | /* |
| 3175 | * If the fsid didn't change, this is a migration event, not a |
| 3176 | * referral. Cause us to drop into the exception handler, which |
| 3177 | * will kick off migration recovery. |
| 3178 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3179 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3180 | dprintk("%s: server did not return a different fsid for" |
| 3181 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3182 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3183 | goto out; |
| 3184 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3185 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3186 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3187 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3188 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3189 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3190 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3191 | out: |
| 3192 | if (page) |
| 3193 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3194 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3195 | return status; |
| 3196 | } |
| 3197 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3198 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3199 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | { |
| 3201 | struct nfs4_getattr_arg args = { |
| 3202 | .fh = fhandle, |
| 3203 | .bitmask = server->attr_bitmask, |
| 3204 | }; |
| 3205 | struct nfs4_getattr_res res = { |
| 3206 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3207 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | .server = server, |
| 3209 | }; |
| 3210 | struct rpc_message msg = { |
| 3211 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3212 | .rpc_argp = &args, |
| 3213 | .rpc_resp = &res, |
| 3214 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3215 | |
| 3216 | args.bitmask = nfs4_bitmask(server, label); |
| 3217 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3218 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3219 | 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] | 3220 | } |
| 3221 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3222 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3223 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | { |
| 3225 | struct nfs4_exception exception = { }; |
| 3226 | int err; |
| 3227 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3228 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3229 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3230 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | &exception); |
| 3232 | } while (exception.retry); |
| 3233 | return err; |
| 3234 | } |
| 3235 | |
| 3236 | /* |
| 3237 | * The file is not closed if it is opened due to the a request to change |
| 3238 | * the size of the file. The open call will not be needed once the |
| 3239 | * VFS layer lookup-intents are implemented. |
| 3240 | * |
| 3241 | * Close is called when the inode is destroyed. |
| 3242 | * If we haven't opened the file for O_WRONLY, we |
| 3243 | * need to in the size_change case to obtain a stateid. |
| 3244 | * |
| 3245 | * Got race? |
| 3246 | * Because OPEN is always done by name in nfsv4, it is |
| 3247 | * possible that we opened a different file by the same |
| 3248 | * name. We can recognize this race condition, but we |
| 3249 | * can't do anything about it besides returning an error. |
| 3250 | * |
| 3251 | * This will be fixed with VFS changes (lookup-intent). |
| 3252 | */ |
| 3253 | static int |
| 3254 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3255 | struct iattr *sattr) |
| 3256 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3257 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3258 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3259 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3260 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | int status; |
| 3262 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3263 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3264 | sattr->ia_valid & ATTR_SIZE && |
| 3265 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3266 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3267 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3268 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3270 | /* Deal with open(O_TRUNC) */ |
| 3271 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3272 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3273 | |
| 3274 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3275 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3276 | return 0; |
| 3277 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3278 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3279 | if (sattr->ia_valid & ATTR_FILE) { |
| 3280 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3281 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3282 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3283 | if (ctx) { |
| 3284 | cred = ctx->cred; |
| 3285 | state = ctx->state; |
| 3286 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3287 | } |
| 3288 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3289 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3290 | if (IS_ERR(label)) |
| 3291 | return PTR_ERR(label); |
| 3292 | |
| 3293 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3294 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3295 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3296 | nfs_setsecurity(inode, fattr, label); |
| 3297 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3298 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | return status; |
| 3300 | } |
| 3301 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3302 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3303 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3304 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3305 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3306 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3307 | int status; |
| 3308 | struct nfs4_lookup_arg args = { |
| 3309 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3310 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3311 | .name = name, |
| 3312 | }; |
| 3313 | struct nfs4_lookup_res res = { |
| 3314 | .server = server, |
| 3315 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3316 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3317 | .fh = fhandle, |
| 3318 | }; |
| 3319 | struct rpc_message msg = { |
| 3320 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3321 | .rpc_argp = &args, |
| 3322 | .rpc_resp = &res, |
| 3323 | }; |
| 3324 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3325 | args.bitmask = nfs4_bitmask(server, label); |
| 3326 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3327 | nfs_fattr_init(fattr); |
| 3328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3330 | 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] | 3331 | dprintk("NFS reply lookup: %d\n", status); |
| 3332 | return status; |
| 3333 | } |
| 3334 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3335 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3336 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3337 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3338 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3339 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3340 | fattr->nlink = 2; |
| 3341 | } |
| 3342 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3343 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3344 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3345 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3346 | { |
| 3347 | struct nfs4_exception exception = { }; |
| 3348 | struct rpc_clnt *client = *clnt; |
| 3349 | int err; |
| 3350 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3351 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3352 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3353 | switch (err) { |
| 3354 | case -NFS4ERR_BADNAME: |
| 3355 | err = -ENOENT; |
| 3356 | goto out; |
| 3357 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3358 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3359 | goto out; |
| 3360 | case -NFS4ERR_WRONGSEC: |
| 3361 | err = -EPERM; |
| 3362 | if (client != *clnt) |
| 3363 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3364 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3365 | if (IS_ERR(client)) |
| 3366 | return PTR_ERR(client); |
| 3367 | |
| 3368 | exception.retry = 1; |
| 3369 | break; |
| 3370 | default: |
| 3371 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3372 | } |
| 3373 | } while (exception.retry); |
| 3374 | |
| 3375 | out: |
| 3376 | if (err == 0) |
| 3377 | *clnt = client; |
| 3378 | else if (client != *clnt) |
| 3379 | rpc_shutdown_client(client); |
| 3380 | |
| 3381 | return err; |
| 3382 | } |
| 3383 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3384 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3385 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3386 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3388 | int status; |
| 3389 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3390 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3391 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3392 | if (client != NFS_CLIENT(dir)) { |
| 3393 | rpc_shutdown_client(client); |
| 3394 | nfs_fixup_secinfo_attributes(fattr); |
| 3395 | } |
| 3396 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | } |
| 3398 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3399 | struct rpc_clnt * |
| 3400 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3401 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3402 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3403 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3404 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3405 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3406 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3407 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3408 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3409 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3410 | } |
| 3411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3413 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3414 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | struct nfs4_accessargs args = { |
| 3416 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3417 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3419 | struct nfs4_accessres res = { |
| 3420 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3421 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | struct rpc_message msg = { |
| 3423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3424 | .rpc_argp = &args, |
| 3425 | .rpc_resp = &res, |
| 3426 | .rpc_cred = entry->cred, |
| 3427 | }; |
| 3428 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3429 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | |
| 3431 | /* |
| 3432 | * Determine which access bits we want to ask for... |
| 3433 | */ |
| 3434 | if (mode & MAY_READ) |
| 3435 | args.access |= NFS4_ACCESS_READ; |
| 3436 | if (S_ISDIR(inode->i_mode)) { |
| 3437 | if (mode & MAY_WRITE) |
| 3438 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3439 | if (mode & MAY_EXEC) |
| 3440 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3441 | } else { |
| 3442 | if (mode & MAY_WRITE) |
| 3443 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3444 | if (mode & MAY_EXEC) |
| 3445 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3446 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3447 | |
| 3448 | res.fattr = nfs_alloc_fattr(); |
| 3449 | if (res.fattr == NULL) |
| 3450 | return -ENOMEM; |
| 3451 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3452 | 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] | 3453 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3454 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3455 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3457 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | return status; |
| 3459 | } |
| 3460 | |
| 3461 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3462 | { |
| 3463 | struct nfs4_exception exception = { }; |
| 3464 | int err; |
| 3465 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3466 | err = _nfs4_proc_access(inode, entry); |
| 3467 | trace_nfs4_access(inode, err); |
| 3468 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | &exception); |
| 3470 | } while (exception.retry); |
| 3471 | return err; |
| 3472 | } |
| 3473 | |
| 3474 | /* |
| 3475 | * TODO: For the time being, we don't try to get any attributes |
| 3476 | * along with any of the zero-copy operations READ, READDIR, |
| 3477 | * READLINK, WRITE. |
| 3478 | * |
| 3479 | * In the case of the first three, we want to put the GETATTR |
| 3480 | * after the read-type operation -- this is because it is hard |
| 3481 | * to predict the length of a GETATTR response in v4, and thus |
| 3482 | * align the READ data correctly. This means that the GETATTR |
| 3483 | * may end up partially falling into the page cache, and we should |
| 3484 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3485 | * To do this efficiently, we need to know the total length |
| 3486 | * of data received, which doesn't seem to be available outside |
| 3487 | * of the RPC layer. |
| 3488 | * |
| 3489 | * In the case of WRITE, we also want to put the GETATTR after |
| 3490 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3491 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | * |
| 3493 | * Both of these changes to the XDR layer would in fact be quite |
| 3494 | * minor, but I decided to leave them for a subsequent patch. |
| 3495 | */ |
| 3496 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3497 | unsigned int pgbase, unsigned int pglen) |
| 3498 | { |
| 3499 | struct nfs4_readlink args = { |
| 3500 | .fh = NFS_FH(inode), |
| 3501 | .pgbase = pgbase, |
| 3502 | .pglen = pglen, |
| 3503 | .pages = &page, |
| 3504 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3505 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | struct rpc_message msg = { |
| 3507 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3508 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3509 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | }; |
| 3511 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3512 | 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] | 3513 | } |
| 3514 | |
| 3515 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3516 | unsigned int pgbase, unsigned int pglen) |
| 3517 | { |
| 3518 | struct nfs4_exception exception = { }; |
| 3519 | int err; |
| 3520 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3521 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3522 | trace_nfs4_readlink(inode, err); |
| 3523 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | &exception); |
| 3525 | } while (exception.retry); |
| 3526 | return err; |
| 3527 | } |
| 3528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3530 | * 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] | 3531 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | static int |
| 3533 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3534 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3536 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3537 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | struct nfs4_state *state; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3539 | int opened = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | int status = 0; |
| 3541 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3542 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3543 | if (IS_ERR(ctx)) |
| 3544 | return PTR_ERR(ctx); |
| 3545 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3546 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3547 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3548 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3549 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, &opened); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | if (IS_ERR(state)) { |
| 3551 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3552 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3555 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3556 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | return status; |
| 3558 | } |
| 3559 | |
| 3560 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3561 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3562 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3563 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3565 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3567 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3568 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3569 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3571 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3572 | .rpc_argp = &args, |
| 3573 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3575 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3576 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3577 | 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] | 3578 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3579 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | return status; |
| 3581 | } |
| 3582 | |
| 3583 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3584 | { |
| 3585 | struct nfs4_exception exception = { }; |
| 3586 | int err; |
| 3587 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3588 | err = _nfs4_proc_remove(dir, name); |
| 3589 | trace_nfs4_remove(dir, name, err); |
| 3590 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | &exception); |
| 3592 | } while (exception.retry); |
| 3593 | return err; |
| 3594 | } |
| 3595 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3596 | 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] | 3597 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3598 | struct nfs_server *server = NFS_SERVER(dir); |
| 3599 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3600 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3602 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3604 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3605 | |
| 3606 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3609 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3610 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3611 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3612 | &data->args.seq_args, |
| 3613 | &data->res.seq_res, |
| 3614 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3617 | 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] | 3618 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3619 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3620 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3621 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3622 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3623 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3624 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3625 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3626 | return 0; |
| 3627 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3628 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3631 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3632 | { |
| 3633 | struct nfs_server *server = NFS_SERVER(dir); |
| 3634 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3635 | struct nfs_renameres *res = msg->rpc_resp; |
| 3636 | |
| 3637 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3638 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3639 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3640 | } |
| 3641 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3642 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3643 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3644 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3645 | &data->args.seq_args, |
| 3646 | &data->res.seq_res, |
| 3647 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3651 | struct inode *new_dir) |
| 3652 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3653 | struct nfs_renamedata *data = task->tk_calldata; |
| 3654 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3655 | |
| 3656 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3657 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3658 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3659 | return 0; |
| 3660 | |
| 3661 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3662 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3663 | return 1; |
| 3664 | } |
| 3665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3667 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3668 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | struct nfs4_link_arg arg = { |
| 3670 | .fh = NFS_FH(inode), |
| 3671 | .dir_fh = NFS_FH(dir), |
| 3672 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3673 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3675 | struct nfs4_link_res res = { |
| 3676 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3677 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3678 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | struct rpc_message msg = { |
| 3680 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3681 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3682 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3684 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3686 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3687 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3688 | goto out; |
| 3689 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3690 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3691 | if (IS_ERR(res.label)) { |
| 3692 | status = PTR_ERR(res.label); |
| 3693 | goto out; |
| 3694 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3695 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3696 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3697 | 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] | 3698 | if (!status) { |
| 3699 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3700 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3701 | if (!status) |
| 3702 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3703 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3704 | |
| 3705 | |
| 3706 | nfs4_label_free(res.label); |
| 3707 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3708 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3709 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | return status; |
| 3711 | } |
| 3712 | |
| 3713 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3714 | { |
| 3715 | struct nfs4_exception exception = { }; |
| 3716 | int err; |
| 3717 | do { |
| 3718 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3719 | _nfs4_proc_link(inode, dir, name), |
| 3720 | &exception); |
| 3721 | } while (exception.retry); |
| 3722 | return err; |
| 3723 | } |
| 3724 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3725 | struct nfs4_createdata { |
| 3726 | struct rpc_message msg; |
| 3727 | struct nfs4_create_arg arg; |
| 3728 | struct nfs4_create_res res; |
| 3729 | struct nfs_fh fh; |
| 3730 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3731 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3732 | }; |
| 3733 | |
| 3734 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3735 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3736 | { |
| 3737 | struct nfs4_createdata *data; |
| 3738 | |
| 3739 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3740 | if (data != NULL) { |
| 3741 | struct nfs_server *server = NFS_SERVER(dir); |
| 3742 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3743 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3744 | if (IS_ERR(data->label)) |
| 3745 | goto out_free; |
| 3746 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3747 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3748 | data->msg.rpc_argp = &data->arg; |
| 3749 | data->msg.rpc_resp = &data->res; |
| 3750 | data->arg.dir_fh = NFS_FH(dir); |
| 3751 | data->arg.server = server; |
| 3752 | data->arg.name = name; |
| 3753 | data->arg.attrs = sattr; |
| 3754 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3755 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3756 | data->res.server = server; |
| 3757 | data->res.fh = &data->fh; |
| 3758 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3759 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3760 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3761 | } |
| 3762 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3763 | out_free: |
| 3764 | kfree(data); |
| 3765 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3769 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3770 | 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] | 3771 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3772 | if (status == 0) { |
| 3773 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3774 | 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] | 3775 | } |
| 3776 | return status; |
| 3777 | } |
| 3778 | |
| 3779 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3780 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3781 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3782 | kfree(data); |
| 3783 | } |
| 3784 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3785 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3786 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3787 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3789 | struct nfs4_createdata *data; |
| 3790 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3792 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3793 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3794 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3795 | status = -ENOMEM; |
| 3796 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3797 | if (data == NULL) |
| 3798 | goto out; |
| 3799 | |
| 3800 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3801 | data->arg.u.symlink.pages = &page; |
| 3802 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3803 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3805 | status = nfs4_do_create(dir, dentry, data); |
| 3806 | |
| 3807 | nfs4_free_createdata(data); |
| 3808 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | return status; |
| 3810 | } |
| 3811 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3812 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3813 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | { |
| 3815 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3816 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3818 | |
| 3819 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3822 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3823 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3824 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | &exception); |
| 3826 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3827 | |
| 3828 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | return err; |
| 3830 | } |
| 3831 | |
| 3832 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3833 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3835 | struct nfs4_createdata *data; |
| 3836 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3838 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3839 | if (data == NULL) |
| 3840 | goto out; |
| 3841 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3842 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3843 | status = nfs4_do_create(dir, dentry, data); |
| 3844 | |
| 3845 | nfs4_free_createdata(data); |
| 3846 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | return status; |
| 3848 | } |
| 3849 | |
| 3850 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3851 | struct iattr *sattr) |
| 3852 | { |
| 3853 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3854 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3856 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3857 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3858 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3859 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3861 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3862 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3863 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | &exception); |
| 3865 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3866 | nfs4_label_release_security(label); |
| 3867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | return err; |
| 3869 | } |
| 3870 | |
| 3871 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3872 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3874 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | struct nfs4_readdir_arg args = { |
| 3876 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3877 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | .pgbase = 0, |
| 3879 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3880 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3881 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | }; |
| 3883 | struct nfs4_readdir_res res; |
| 3884 | struct rpc_message msg = { |
| 3885 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3886 | .rpc_argp = &args, |
| 3887 | .rpc_resp = &res, |
| 3888 | .rpc_cred = cred, |
| 3889 | }; |
| 3890 | int status; |
| 3891 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 3892 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 3893 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3894 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3895 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3897 | 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] | 3898 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3899 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3900 | status += args.pgbase; |
| 3901 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3902 | |
| 3903 | nfs_invalidate_atime(dir); |
| 3904 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3905 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | return status; |
| 3907 | } |
| 3908 | |
| 3909 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3910 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | { |
| 3912 | struct nfs4_exception exception = { }; |
| 3913 | int err; |
| 3914 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3915 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3916 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3917 | trace_nfs4_readdir(d_inode(dentry), err); |
| 3918 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | &exception); |
| 3920 | } while (exception.retry); |
| 3921 | return err; |
| 3922 | } |
| 3923 | |
| 3924 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3925 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3927 | struct nfs4_createdata *data; |
| 3928 | int mode = sattr->ia_mode; |
| 3929 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3931 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3932 | if (data == NULL) |
| 3933 | goto out; |
| 3934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3936 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3938 | data->arg.ftype = NF4BLK; |
| 3939 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3940 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | } |
| 3942 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3943 | data->arg.ftype = NF4CHR; |
| 3944 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3945 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3946 | } else if (!S_ISSOCK(mode)) { |
| 3947 | status = -EINVAL; |
| 3948 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3950 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3951 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3952 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3953 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3954 | nfs4_free_createdata(data); |
| 3955 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | return status; |
| 3957 | } |
| 3958 | |
| 3959 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3960 | struct iattr *sattr, dev_t rdev) |
| 3961 | { |
| 3962 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3963 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3965 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3966 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3967 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3968 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3970 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3971 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3972 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | &exception); |
| 3974 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3975 | |
| 3976 | nfs4_label_release_security(label); |
| 3977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | return err; |
| 3979 | } |
| 3980 | |
| 3981 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3982 | struct nfs_fsstat *fsstat) |
| 3983 | { |
| 3984 | struct nfs4_statfs_arg args = { |
| 3985 | .fh = fhandle, |
| 3986 | .bitmask = server->attr_bitmask, |
| 3987 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3988 | struct nfs4_statfs_res res = { |
| 3989 | .fsstat = fsstat, |
| 3990 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | struct rpc_message msg = { |
| 3992 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3993 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3994 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | }; |
| 3996 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3997 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3998 | 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] | 3999 | } |
| 4000 | |
| 4001 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4002 | { |
| 4003 | struct nfs4_exception exception = { }; |
| 4004 | int err; |
| 4005 | do { |
| 4006 | err = nfs4_handle_exception(server, |
| 4007 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4008 | &exception); |
| 4009 | } while (exception.retry); |
| 4010 | return err; |
| 4011 | } |
| 4012 | |
| 4013 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4014 | struct nfs_fsinfo *fsinfo) |
| 4015 | { |
| 4016 | struct nfs4_fsinfo_arg args = { |
| 4017 | .fh = fhandle, |
| 4018 | .bitmask = server->attr_bitmask, |
| 4019 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4020 | struct nfs4_fsinfo_res res = { |
| 4021 | .fsinfo = fsinfo, |
| 4022 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | struct rpc_message msg = { |
| 4024 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4025 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4026 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | }; |
| 4028 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4029 | 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] | 4030 | } |
| 4031 | |
| 4032 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4033 | { |
| 4034 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4035 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | int err; |
| 4037 | |
| 4038 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4039 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4040 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4041 | if (err == 0) { |
| 4042 | struct nfs_client *clp = server->nfs_client; |
| 4043 | |
| 4044 | spin_lock(&clp->cl_lock); |
| 4045 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 4046 | clp->cl_last_renewal = now; |
| 4047 | spin_unlock(&clp->cl_lock); |
| 4048 | break; |
| 4049 | } |
| 4050 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | } while (exception.retry); |
| 4052 | return err; |
| 4053 | } |
| 4054 | |
| 4055 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4056 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4057 | int error; |
| 4058 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4059 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4060 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4061 | if (error == 0) { |
| 4062 | /* block layout checks this! */ |
| 4063 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4064 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4065 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4066 | |
| 4067 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4071 | struct nfs_pathconf *pathconf) |
| 4072 | { |
| 4073 | struct nfs4_pathconf_arg args = { |
| 4074 | .fh = fhandle, |
| 4075 | .bitmask = server->attr_bitmask, |
| 4076 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4077 | struct nfs4_pathconf_res res = { |
| 4078 | .pathconf = pathconf, |
| 4079 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | struct rpc_message msg = { |
| 4081 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4082 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4083 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | }; |
| 4085 | |
| 4086 | /* None of the pathconf attributes are mandatory to implement */ |
| 4087 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4088 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4089 | return 0; |
| 4090 | } |
| 4091 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4092 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4093 | 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] | 4094 | } |
| 4095 | |
| 4096 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4097 | struct nfs_pathconf *pathconf) |
| 4098 | { |
| 4099 | struct nfs4_exception exception = { }; |
| 4100 | int err; |
| 4101 | |
| 4102 | do { |
| 4103 | err = nfs4_handle_exception(server, |
| 4104 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4105 | &exception); |
| 4106 | } while (exception.retry); |
| 4107 | return err; |
| 4108 | } |
| 4109 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4110 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4111 | const struct nfs_open_context *ctx, |
| 4112 | const struct nfs_lock_context *l_ctx, |
| 4113 | fmode_t fmode) |
| 4114 | { |
| 4115 | const struct nfs_lockowner *lockowner = NULL; |
| 4116 | |
| 4117 | if (l_ctx != NULL) |
| 4118 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4119 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4120 | } |
| 4121 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4122 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4123 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4124 | const struct nfs_open_context *ctx, |
| 4125 | const struct nfs_lock_context *l_ctx, |
| 4126 | fmode_t fmode) |
| 4127 | { |
| 4128 | nfs4_stateid current_stateid; |
| 4129 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4130 | /* If the current stateid represents a lost lock, then exit */ |
| 4131 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4132 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4133 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4134 | } |
| 4135 | |
| 4136 | static bool nfs4_error_stateid_expired(int err) |
| 4137 | { |
| 4138 | switch (err) { |
| 4139 | case -NFS4ERR_DELEG_REVOKED: |
| 4140 | case -NFS4ERR_ADMIN_REVOKED: |
| 4141 | case -NFS4ERR_BAD_STATEID: |
| 4142 | case -NFS4ERR_STALE_STATEID: |
| 4143 | case -NFS4ERR_OLD_STATEID: |
| 4144 | case -NFS4ERR_OPENMODE: |
| 4145 | case -NFS4ERR_EXPIRED: |
| 4146 | return true; |
| 4147 | } |
| 4148 | return false; |
| 4149 | } |
| 4150 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4151 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4152 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4153 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4154 | } |
| 4155 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4156 | 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] | 4157 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4158 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4160 | trace_nfs4_read(hdr, task->tk_status); |
| 4161 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4162 | hdr->args.context->state, |
| 4163 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4164 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4165 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4167 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4168 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4170 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4171 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | } |
| 4173 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4174 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4175 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4176 | { |
| 4177 | |
| 4178 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4179 | nfs4_stateid_is_current(&args->stateid, |
| 4180 | args->context, |
| 4181 | args->lock_context, |
| 4182 | FMODE_READ)) |
| 4183 | return false; |
| 4184 | rpc_restart_call_prepare(task); |
| 4185 | return true; |
| 4186 | } |
| 4187 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4188 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4189 | { |
| 4190 | |
| 4191 | dprintk("--> %s\n", __func__); |
| 4192 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4193 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4194 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4195 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4196 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4197 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4198 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4201 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4202 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4204 | hdr->timestamp = jiffies; |
| 4205 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4206 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4207 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4210 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4211 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4212 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4213 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4214 | &hdr->args.seq_args, |
| 4215 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4216 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4217 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4218 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4219 | hdr->args.lock_context, |
| 4220 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4221 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4222 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4223 | return -EIO; |
| 4224 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4227 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4228 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4230 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4231 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4232 | trace_nfs4_write(hdr, task->tk_status); |
| 4233 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4234 | hdr->args.context->state, |
| 4235 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4236 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4237 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4239 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4240 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4241 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4242 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4243 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | } |
| 4245 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4246 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4247 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4248 | { |
| 4249 | |
| 4250 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4251 | nfs4_stateid_is_current(&args->stateid, |
| 4252 | args->context, |
| 4253 | args->lock_context, |
| 4254 | FMODE_WRITE)) |
| 4255 | return false; |
| 4256 | rpc_restart_call_prepare(task); |
| 4257 | return true; |
| 4258 | } |
| 4259 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4260 | 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] | 4261 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4262 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4263 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4264 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4265 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4266 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4267 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4268 | } |
| 4269 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4270 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4271 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4272 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4273 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4274 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4275 | return false; |
| 4276 | /* Otherwise, request attributes if and only if we don't hold |
| 4277 | * a delegation |
| 4278 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4279 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4280 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4281 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4282 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4283 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4285 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4286 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4287 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4288 | hdr->args.bitmask = NULL; |
| 4289 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4290 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4291 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4292 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4293 | if (!hdr->pgio_done_cb) |
| 4294 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4295 | hdr->res.server = server; |
| 4296 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4298 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4299 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4302 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4303 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4304 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4305 | &data->args.seq_args, |
| 4306 | &data->res.seq_res, |
| 4307 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4310 | 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] | 4311 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4313 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4314 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4315 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4316 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4317 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4318 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4320 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4323 | 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] | 4324 | { |
| 4325 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4326 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4327 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4330 | 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] | 4331 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4332 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4333 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4334 | if (data->commit_done_cb == NULL) |
| 4335 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4336 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4337 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4338 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4341 | struct nfs4_renewdata { |
| 4342 | struct nfs_client *client; |
| 4343 | unsigned long timestamp; |
| 4344 | }; |
| 4345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | /* |
| 4347 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4348 | * standalone procedure for queueing an asynchronous RENEW. |
| 4349 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4350 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4351 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4352 | struct nfs4_renewdata *data = calldata; |
| 4353 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4354 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4355 | if (atomic_read(&clp->cl_count) > 1) |
| 4356 | nfs4_schedule_state_renewal(clp); |
| 4357 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4358 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4359 | } |
| 4360 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4361 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
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 = calldata; |
| 4364 | struct nfs_client *clp = data->client; |
| 4365 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4367 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4368 | switch (task->tk_status) { |
| 4369 | case 0: |
| 4370 | break; |
| 4371 | case -NFS4ERR_LEASE_MOVED: |
| 4372 | nfs4_schedule_lease_moved_recovery(clp); |
| 4373 | break; |
| 4374 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4375 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4376 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4377 | return; |
| 4378 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4379 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4380 | return; |
| 4381 | } |
| 4382 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4384 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | } |
| 4386 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4387 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4388 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4389 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4390 | }; |
| 4391 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4392 | 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] | 4393 | { |
| 4394 | struct rpc_message msg = { |
| 4395 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4396 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4397 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4399 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4401 | if (renew_flags == 0) |
| 4402 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4403 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4404 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4405 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4406 | if (data == NULL) |
| 4407 | return -ENOMEM; |
| 4408 | data->client = clp; |
| 4409 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4410 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4411 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | } |
| 4413 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4414 | 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] | 4415 | { |
| 4416 | struct rpc_message msg = { |
| 4417 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4418 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4419 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | }; |
| 4421 | unsigned long now = jiffies; |
| 4422 | int status; |
| 4423 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4424 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | if (status < 0) |
| 4426 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4427 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | return 0; |
| 4429 | } |
| 4430 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4431 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4432 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4433 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4434 | } |
| 4435 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4436 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4437 | * 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] | 4438 | * the stack. |
| 4439 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4440 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4441 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4442 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4443 | struct page **pages, unsigned int *pgbase) |
| 4444 | { |
| 4445 | struct page *newpage, **spages; |
| 4446 | int rc = 0; |
| 4447 | size_t len; |
| 4448 | spages = pages; |
| 4449 | |
| 4450 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4451 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4452 | newpage = alloc_page(GFP_KERNEL); |
| 4453 | |
| 4454 | if (newpage == NULL) |
| 4455 | goto unwind; |
| 4456 | memcpy(page_address(newpage), buf, len); |
| 4457 | buf += len; |
| 4458 | buflen -= len; |
| 4459 | *pages++ = newpage; |
| 4460 | rc++; |
| 4461 | } while (buflen != 0); |
| 4462 | |
| 4463 | return rc; |
| 4464 | |
| 4465 | unwind: |
| 4466 | for(; rc > 0; rc--) |
| 4467 | __free_page(spages[rc-1]); |
| 4468 | return -ENOMEM; |
| 4469 | } |
| 4470 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4471 | struct nfs4_cached_acl { |
| 4472 | int cached; |
| 4473 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4474 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4475 | }; |
| 4476 | |
| 4477 | 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] | 4478 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4479 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4480 | |
| 4481 | spin_lock(&inode->i_lock); |
| 4482 | kfree(nfsi->nfs4_acl); |
| 4483 | nfsi->nfs4_acl = acl; |
| 4484 | spin_unlock(&inode->i_lock); |
| 4485 | } |
| 4486 | |
| 4487 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4488 | { |
| 4489 | nfs4_set_cached_acl(inode, NULL); |
| 4490 | } |
| 4491 | |
| 4492 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4493 | { |
| 4494 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4495 | struct nfs4_cached_acl *acl; |
| 4496 | int ret = -ENOENT; |
| 4497 | |
| 4498 | spin_lock(&inode->i_lock); |
| 4499 | acl = nfsi->nfs4_acl; |
| 4500 | if (acl == NULL) |
| 4501 | goto out; |
| 4502 | if (buf == NULL) /* user is just asking for length */ |
| 4503 | goto out_len; |
| 4504 | if (acl->cached == 0) |
| 4505 | goto out; |
| 4506 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4507 | if (acl->len > buflen) |
| 4508 | goto out; |
| 4509 | memcpy(buf, acl->data, acl->len); |
| 4510 | out_len: |
| 4511 | ret = acl->len; |
| 4512 | out: |
| 4513 | spin_unlock(&inode->i_lock); |
| 4514 | return ret; |
| 4515 | } |
| 4516 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4517 | 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] | 4518 | { |
| 4519 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4520 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4521 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4522 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4523 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4524 | if (acl == NULL) |
| 4525 | goto out; |
| 4526 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4527 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4528 | } else { |
| 4529 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4530 | if (acl == NULL) |
| 4531 | goto out; |
| 4532 | acl->cached = 0; |
| 4533 | } |
| 4534 | acl->len = acl_len; |
| 4535 | out: |
| 4536 | nfs4_set_cached_acl(inode, acl); |
| 4537 | } |
| 4538 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4539 | /* |
| 4540 | * The getxattr API returns the required buffer length when called with a |
| 4541 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4542 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4543 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4544 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4545 | * the cache. If not so, we throw away the page, and cache the required |
| 4546 | * length. The next getxattr call will then produce another round trip to |
| 4547 | * the server, this time with the input buf of the required size. |
| 4548 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4549 | 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] | 4550 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4551 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4552 | struct nfs_getaclargs args = { |
| 4553 | .fh = NFS_FH(inode), |
| 4554 | .acl_pages = pages, |
| 4555 | .acl_len = buflen, |
| 4556 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4557 | struct nfs_getaclres res = { |
| 4558 | .acl_len = buflen, |
| 4559 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4560 | struct rpc_message msg = { |
| 4561 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4562 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4563 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4564 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4565 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4566 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4567 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4568 | /* As long as we're doing a round trip to the server anyway, |
| 4569 | * let's be prepared for a page of acl data. */ |
| 4570 | if (npages == 0) |
| 4571 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4572 | if (npages > ARRAY_SIZE(pages)) |
| 4573 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4574 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4575 | for (i = 0; i < npages; i++) { |
| 4576 | pages[i] = alloc_page(GFP_KERNEL); |
| 4577 | if (!pages[i]) |
| 4578 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4579 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4580 | |
| 4581 | /* for decoding across pages */ |
| 4582 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4583 | if (!res.acl_scratch) |
| 4584 | goto out_free; |
| 4585 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4586 | args.acl_len = npages * PAGE_SIZE; |
| 4587 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4588 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4589 | 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] | 4590 | __func__, buf, buflen, npages, args.acl_len); |
| 4591 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4592 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4593 | if (ret) |
| 4594 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4595 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4596 | /* Handle the case where the passed-in buffer is too short */ |
| 4597 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4598 | /* Did the user only issue a request for the acl length? */ |
| 4599 | if (buf == NULL) |
| 4600 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4601 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4602 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4603 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4604 | 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] | 4605 | if (buf) { |
| 4606 | if (res.acl_len > buflen) { |
| 4607 | ret = -ERANGE; |
| 4608 | goto out_free; |
| 4609 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4610 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4611 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4612 | out_ok: |
| 4613 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4614 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4615 | for (i = 0; i < npages; i++) |
| 4616 | if (pages[i]) |
| 4617 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4618 | if (res.acl_scratch) |
| 4619 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4620 | return ret; |
| 4621 | } |
| 4622 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4623 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4624 | { |
| 4625 | struct nfs4_exception exception = { }; |
| 4626 | ssize_t ret; |
| 4627 | do { |
| 4628 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4629 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4630 | if (ret >= 0) |
| 4631 | break; |
| 4632 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4633 | } while (exception.retry); |
| 4634 | return ret; |
| 4635 | } |
| 4636 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4637 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4638 | { |
| 4639 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4640 | int ret; |
| 4641 | |
| 4642 | if (!nfs4_server_supports_acls(server)) |
| 4643 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4644 | ret = nfs_revalidate_inode(server, inode); |
| 4645 | if (ret < 0) |
| 4646 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4647 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4648 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4649 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4650 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4651 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4652 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4653 | return ret; |
| 4654 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4657 | 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] | 4658 | { |
| 4659 | struct nfs_server *server = NFS_SERVER(inode); |
| 4660 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4661 | struct nfs_setaclargs arg = { |
| 4662 | .fh = NFS_FH(inode), |
| 4663 | .acl_pages = pages, |
| 4664 | .acl_len = buflen, |
| 4665 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4666 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4667 | struct rpc_message msg = { |
| 4668 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4669 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4670 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4671 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4672 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4673 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4674 | |
| 4675 | if (!nfs4_server_supports_acls(server)) |
| 4676 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4677 | if (npages > ARRAY_SIZE(pages)) |
| 4678 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4679 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4680 | if (i < 0) |
| 4681 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4682 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4683 | 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] | 4684 | |
| 4685 | /* |
| 4686 | * Free each page after tx, so the only ref left is |
| 4687 | * held by the network stack |
| 4688 | */ |
| 4689 | for (; i > 0; i--) |
| 4690 | put_page(pages[i-1]); |
| 4691 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4692 | /* |
| 4693 | * Acl update can result in inode attribute update. |
| 4694 | * so mark the attribute cache invalid. |
| 4695 | */ |
| 4696 | spin_lock(&inode->i_lock); |
| 4697 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4698 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4699 | nfs_access_zap_cache(inode); |
| 4700 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4701 | return ret; |
| 4702 | } |
| 4703 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4704 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4705 | { |
| 4706 | struct nfs4_exception exception = { }; |
| 4707 | int err; |
| 4708 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4709 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4710 | trace_nfs4_set_acl(inode, err); |
| 4711 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4712 | &exception); |
| 4713 | } while (exception.retry); |
| 4714 | return err; |
| 4715 | } |
| 4716 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4717 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4718 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4719 | size_t buflen) |
| 4720 | { |
| 4721 | struct nfs_server *server = NFS_SERVER(inode); |
| 4722 | struct nfs_fattr fattr; |
| 4723 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4724 | |
| 4725 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4726 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4727 | .fh = NFS_FH(inode), |
| 4728 | .bitmask = bitmask, |
| 4729 | }; |
| 4730 | struct nfs4_getattr_res res = { |
| 4731 | .fattr = &fattr, |
| 4732 | .label = &label, |
| 4733 | .server = server, |
| 4734 | }; |
| 4735 | struct rpc_message msg = { |
| 4736 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4737 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4738 | .rpc_resp = &res, |
| 4739 | }; |
| 4740 | int ret; |
| 4741 | |
| 4742 | nfs_fattr_init(&fattr); |
| 4743 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4744 | 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] | 4745 | if (ret) |
| 4746 | return ret; |
| 4747 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4748 | return -ENOENT; |
| 4749 | if (buflen < label.len) |
| 4750 | return -ERANGE; |
| 4751 | return 0; |
| 4752 | } |
| 4753 | |
| 4754 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4755 | size_t buflen) |
| 4756 | { |
| 4757 | struct nfs4_exception exception = { }; |
| 4758 | int err; |
| 4759 | |
| 4760 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4761 | return -EOPNOTSUPP; |
| 4762 | |
| 4763 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4764 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4765 | trace_nfs4_get_security_label(inode, err); |
| 4766 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4767 | &exception); |
| 4768 | } while (exception.retry); |
| 4769 | return err; |
| 4770 | } |
| 4771 | |
| 4772 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4773 | struct nfs4_label *ilabel, |
| 4774 | struct nfs_fattr *fattr, |
| 4775 | struct nfs4_label *olabel) |
| 4776 | { |
| 4777 | |
| 4778 | struct iattr sattr = {0}; |
| 4779 | struct nfs_server *server = NFS_SERVER(inode); |
| 4780 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4781 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4782 | .fh = NFS_FH(inode), |
| 4783 | .iap = &sattr, |
| 4784 | .server = server, |
| 4785 | .bitmask = bitmask, |
| 4786 | .label = ilabel, |
| 4787 | }; |
| 4788 | struct nfs_setattrres res = { |
| 4789 | .fattr = fattr, |
| 4790 | .label = olabel, |
| 4791 | .server = server, |
| 4792 | }; |
| 4793 | struct rpc_message msg = { |
| 4794 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4795 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4796 | .rpc_resp = &res, |
| 4797 | }; |
| 4798 | int status; |
| 4799 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4800 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4801 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4802 | 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] | 4803 | if (status) |
| 4804 | dprintk("%s failed: %d\n", __func__, status); |
| 4805 | |
| 4806 | return status; |
| 4807 | } |
| 4808 | |
| 4809 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4810 | struct nfs4_label *ilabel, |
| 4811 | struct nfs_fattr *fattr, |
| 4812 | struct nfs4_label *olabel) |
| 4813 | { |
| 4814 | struct nfs4_exception exception = { }; |
| 4815 | int err; |
| 4816 | |
| 4817 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4818 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4819 | fattr, olabel); |
| 4820 | trace_nfs4_set_security_label(inode, err); |
| 4821 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4822 | &exception); |
| 4823 | } while (exception.retry); |
| 4824 | return err; |
| 4825 | } |
| 4826 | |
| 4827 | static int |
| 4828 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4829 | { |
| 4830 | struct nfs4_label ilabel, *olabel = NULL; |
| 4831 | struct nfs_fattr fattr; |
| 4832 | struct rpc_cred *cred; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4833 | struct inode *inode = d_inode(dentry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4834 | int status; |
| 4835 | |
| 4836 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4837 | return -EOPNOTSUPP; |
| 4838 | |
| 4839 | nfs_fattr_init(&fattr); |
| 4840 | |
| 4841 | ilabel.pi = 0; |
| 4842 | ilabel.lfs = 0; |
| 4843 | ilabel.label = (char *)buf; |
| 4844 | ilabel.len = buflen; |
| 4845 | |
| 4846 | cred = rpc_lookup_cred(); |
| 4847 | if (IS_ERR(cred)) |
| 4848 | return PTR_ERR(cred); |
| 4849 | |
| 4850 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4851 | if (IS_ERR(olabel)) { |
| 4852 | status = -PTR_ERR(olabel); |
| 4853 | goto out; |
| 4854 | } |
| 4855 | |
| 4856 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4857 | if (status == 0) |
| 4858 | nfs_setsecurity(inode, &fattr, olabel); |
| 4859 | |
| 4860 | nfs4_label_free(olabel); |
| 4861 | out: |
| 4862 | put_rpccred(cred); |
| 4863 | return status; |
| 4864 | } |
| 4865 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4866 | |
| 4867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | static int |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4869 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, |
| 4870 | struct nfs4_state *state, long *timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4872 | struct nfs_client *clp = server->nfs_client; |
| 4873 | |
| 4874 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | return 0; |
| 4876 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4877 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4878 | case -NFS4ERR_ADMIN_REVOKED: |
| 4879 | case -NFS4ERR_BAD_STATEID: |
| 4880 | case -NFS4ERR_OPENMODE: |
| 4881 | if (state == NULL) |
| 4882 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4883 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4884 | goto recovery_failed; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4885 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4886 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4887 | if (state != NULL) { |
| 4888 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4889 | goto recovery_failed; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4892 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4893 | nfs4_schedule_lease_recovery(clp); |
| 4894 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4895 | case -NFS4ERR_MOVED: |
| 4896 | if (nfs4_schedule_migration_recovery(server) < 0) |
| 4897 | goto recovery_failed; |
| 4898 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 4899 | case -NFS4ERR_LEASE_MOVED: |
| 4900 | nfs4_schedule_lease_moved_recovery(clp); |
| 4901 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4902 | #if defined(CONFIG_NFS_V4_1) |
| 4903 | case -NFS4ERR_BADSESSION: |
| 4904 | case -NFS4ERR_BADSLOT: |
| 4905 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4906 | case -NFS4ERR_DEADSESSION: |
| 4907 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4908 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4909 | case -NFS4ERR_SEQ_MISORDERED: |
| 4910 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4911 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4912 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4a82fd7 | 2013-11-15 16:36:16 -0500 | [diff] [blame] | 4913 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4914 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4916 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4917 | rpc_delay(task, nfs4_update_delay(timeout)); |
| 4918 | goto restart_call; |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4919 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4921 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | case -NFS4ERR_OLD_STATEID: |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4923 | goto restart_call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | } |
| 4925 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4926 | return 0; |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4927 | recovery_failed: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4928 | task->tk_status = -EIO; |
| 4929 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4930 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4931 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4932 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4933 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4934 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 4935 | goto recovery_failed; |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4936 | restart_call: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4937 | task->tk_status = 0; |
| 4938 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | } |
| 4940 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4941 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4942 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4943 | { |
| 4944 | __be32 verf[2]; |
| 4945 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4946 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4947 | /* An impossible timestamp guarantees this value |
| 4948 | * will never match a generated boot time. */ |
| 4949 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4950 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4951 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4952 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4953 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4954 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4955 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4956 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4957 | } |
| 4958 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4959 | static unsigned int |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4960 | nfs4_init_nonuniform_client_string(struct nfs_client *clp, |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4961 | char *buf, size_t len) |
| 4962 | { |
| 4963 | unsigned int result; |
| 4964 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4965 | if (clp->cl_owner_id != NULL) |
| 4966 | return strlcpy(buf, clp->cl_owner_id, len); |
| 4967 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4968 | rcu_read_lock(); |
| 4969 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4970 | clp->cl_ipaddr, |
| 4971 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4972 | RPC_DISPLAY_ADDR), |
| 4973 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4974 | RPC_DISPLAY_PROTO)); |
| 4975 | rcu_read_unlock(); |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4976 | clp->cl_owner_id = kstrdup(buf, GFP_KERNEL); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4977 | return result; |
| 4978 | } |
| 4979 | |
| 4980 | static unsigned int |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4981 | nfs4_init_uniform_client_string(struct nfs_client *clp, |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4982 | char *buf, size_t len) |
| 4983 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4984 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4985 | unsigned int result; |
| 4986 | |
| 4987 | if (clp->cl_owner_id != NULL) |
| 4988 | return strlcpy(buf, clp->cl_owner_id, len); |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4989 | |
| 4990 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4991 | result = scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4992 | clp->rpc_ops->version, |
| 4993 | clp->cl_minorversion, |
| 4994 | nfs4_client_id_uniquifier, |
| 4995 | nodename); |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4996 | else |
| 4997 | result = scnprintf(buf, len, "Linux NFSv%u.%u %s", |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4998 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4999 | nodename); |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5000 | clp->cl_owner_id = kstrdup(buf, GFP_KERNEL); |
| 5001 | return result; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5002 | } |
| 5003 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5004 | /* |
| 5005 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5006 | * services. Advertise one based on the address family of the |
| 5007 | * clientaddr. |
| 5008 | */ |
| 5009 | static unsigned int |
| 5010 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5011 | { |
| 5012 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5013 | return scnprintf(buf, len, "tcp6"); |
| 5014 | else |
| 5015 | return scnprintf(buf, len, "tcp"); |
| 5016 | } |
| 5017 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5018 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5019 | { |
| 5020 | struct nfs4_setclientid *sc = calldata; |
| 5021 | |
| 5022 | if (task->tk_status == 0) |
| 5023 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5024 | } |
| 5025 | |
| 5026 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5027 | .rpc_call_done = nfs4_setclientid_done, |
| 5028 | }; |
| 5029 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5030 | /** |
| 5031 | * nfs4_proc_setclientid - Negotiate client ID |
| 5032 | * @clp: state data structure |
| 5033 | * @program: RPC program for NFSv4 callback service |
| 5034 | * @port: IP port number for NFS4 callback service |
| 5035 | * @cred: RPC credential to use for this call |
| 5036 | * @res: where to place the result |
| 5037 | * |
| 5038 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5039 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5040 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5041 | unsigned short port, struct rpc_cred *cred, |
| 5042 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | { |
| 5044 | nfs4_verifier sc_verifier; |
| 5045 | struct nfs4_setclientid setclientid = { |
| 5046 | .sc_verifier = &sc_verifier, |
| 5047 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 5048 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5049 | }; |
| 5050 | struct rpc_message msg = { |
| 5051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5052 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5053 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5054 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5056 | struct rpc_task *task; |
| 5057 | struct rpc_task_setup task_setup_data = { |
| 5058 | .rpc_client = clp->cl_rpcclient, |
| 5059 | .rpc_message = &msg, |
| 5060 | .callback_ops = &nfs4_setclientid_ops, |
| 5061 | .callback_data = &setclientid, |
| 5062 | .flags = RPC_TASK_TIMEOUT, |
| 5063 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5064 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5066 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5067 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5068 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5069 | setclientid.sc_name_len = |
| 5070 | nfs4_init_uniform_client_string(clp, |
| 5071 | setclientid.sc_name, |
| 5072 | sizeof(setclientid.sc_name)); |
| 5073 | else |
| 5074 | setclientid.sc_name_len = |
| 5075 | nfs4_init_nonuniform_client_string(clp, |
| 5076 | setclientid.sc_name, |
| 5077 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5078 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5079 | setclientid.sc_netid_len = |
| 5080 | nfs4_init_callback_netid(clp, |
| 5081 | setclientid.sc_netid, |
| 5082 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5083 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5084 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5086 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5087 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 5088 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5089 | setclientid.sc_name_len, setclientid.sc_name); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5090 | task = rpc_run_task(&task_setup_data); |
| 5091 | if (IS_ERR(task)) { |
| 5092 | status = PTR_ERR(task); |
| 5093 | goto out; |
| 5094 | } |
| 5095 | status = task->tk_status; |
| 5096 | if (setclientid.sc_cred) { |
| 5097 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5098 | put_rpccred(setclientid.sc_cred); |
| 5099 | } |
| 5100 | rpc_put_task(task); |
| 5101 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5102 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5103 | dprintk("NFS reply setclientid: %d\n", status); |
| 5104 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5107 | /** |
| 5108 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5109 | * @clp: state data structure |
| 5110 | * @res: result of a previous SETCLIENTID |
| 5111 | * @cred: RPC credential to use for this call |
| 5112 | * |
| 5113 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5114 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5115 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5116 | struct nfs4_setclientid_res *arg, |
| 5117 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | struct rpc_message msg = { |
| 5120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5121 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5122 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5124 | int status; |
| 5125 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5126 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5127 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5128 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5129 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5130 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5131 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | return status; |
| 5133 | } |
| 5134 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5135 | struct nfs4_delegreturndata { |
| 5136 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5137 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5138 | struct nfs_fh fh; |
| 5139 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5140 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5141 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5142 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5143 | struct inode *inode; |
| 5144 | bool roc; |
| 5145 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5146 | }; |
| 5147 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5148 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5149 | { |
| 5150 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5151 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5152 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5153 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5154 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5155 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5156 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5157 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5158 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5159 | case -NFS4ERR_ADMIN_REVOKED: |
| 5160 | case -NFS4ERR_DELEG_REVOKED: |
| 5161 | case -NFS4ERR_BAD_STATEID: |
| 5162 | case -NFS4ERR_OLD_STATEID: |
| 5163 | case -NFS4ERR_STALE_STATEID: |
| 5164 | case -NFS4ERR_EXPIRED: |
| 5165 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5166 | if (data->roc) |
| 5167 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5168 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5169 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5170 | if (nfs4_async_handle_error(task, data->res.server, |
| 5171 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5172 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5173 | return; |
| 5174 | } |
| 5175 | } |
| 5176 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | static void nfs4_delegreturn_release(void *calldata) |
| 5180 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5181 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5182 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5183 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5184 | if (inode) { |
| 5185 | if (data->roc) |
| 5186 | pnfs_roc_release(inode); |
| 5187 | nfs_iput_and_deactive(inode); |
| 5188 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5189 | kfree(calldata); |
| 5190 | } |
| 5191 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5192 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5193 | { |
| 5194 | struct nfs4_delegreturndata *d_data; |
| 5195 | |
| 5196 | d_data = (struct nfs4_delegreturndata *)data; |
| 5197 | |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5198 | if (d_data->roc && |
| 5199 | pnfs_roc_drain(d_data->inode, &d_data->roc_barrier, task)) |
| 5200 | return; |
| 5201 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5202 | nfs4_setup_sequence(d_data->res.server, |
| 5203 | &d_data->args.seq_args, |
| 5204 | &d_data->res.seq_res, |
| 5205 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5206 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5207 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5208 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5209 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5210 | .rpc_call_done = nfs4_delegreturn_done, |
| 5211 | .rpc_release = nfs4_delegreturn_release, |
| 5212 | }; |
| 5213 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5214 | 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] | 5215 | { |
| 5216 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5217 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5218 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5219 | struct rpc_message msg = { |
| 5220 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5221 | .rpc_cred = cred, |
| 5222 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5223 | struct rpc_task_setup task_setup_data = { |
| 5224 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5225 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5226 | .callback_ops = &nfs4_delegreturn_ops, |
| 5227 | .flags = RPC_TASK_ASYNC, |
| 5228 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5229 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5230 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5231 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5232 | if (data == NULL) |
| 5233 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5234 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5235 | data->args.fhandle = &data->fh; |
| 5236 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5237 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5238 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5239 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5240 | data->res.fattr = &data->fattr; |
| 5241 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5242 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5243 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5244 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5245 | data->inode = nfs_igrab_and_active(inode); |
| 5246 | if (data->inode) |
| 5247 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5248 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5249 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5250 | msg.rpc_argp = &data->args; |
| 5251 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5252 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5253 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5254 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5255 | if (!issync) |
| 5256 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5257 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5258 | if (status != 0) |
| 5259 | goto out; |
| 5260 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5261 | if (status == 0) |
| 5262 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5263 | else |
| 5264 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5265 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5266 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5267 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5268 | } |
| 5269 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5270 | 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] | 5271 | { |
| 5272 | struct nfs_server *server = NFS_SERVER(inode); |
| 5273 | struct nfs4_exception exception = { }; |
| 5274 | int err; |
| 5275 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5276 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5277 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5278 | switch (err) { |
| 5279 | case -NFS4ERR_STALE_STATEID: |
| 5280 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | case 0: |
| 5282 | return 0; |
| 5283 | } |
| 5284 | err = nfs4_handle_exception(server, err, &exception); |
| 5285 | } while (exception.retry); |
| 5286 | return err; |
| 5287 | } |
| 5288 | |
| 5289 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5290 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5291 | |
| 5292 | /* |
| 5293 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5294 | */ |
| 5295 | static unsigned long |
| 5296 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5297 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5298 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | timeout <<= 1; |
| 5300 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5301 | return NFS4_LOCK_MAXTIMEOUT; |
| 5302 | return timeout; |
| 5303 | } |
| 5304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5306 | { |
| 5307 | struct inode *inode = state->inode; |
| 5308 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5309 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5310 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5311 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5312 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5314 | struct nfs_lockt_res res = { |
| 5315 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | }; |
| 5317 | struct rpc_message msg = { |
| 5318 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5319 | .rpc_argp = &arg, |
| 5320 | .rpc_resp = &res, |
| 5321 | .rpc_cred = state->owner->so_cred, |
| 5322 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5323 | struct nfs4_lock_state *lsp; |
| 5324 | int status; |
| 5325 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5326 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5327 | status = nfs4_set_lock_state(state, request); |
| 5328 | if (status != 0) |
| 5329 | goto out; |
| 5330 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5331 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5332 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5333 | 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] | 5334 | switch (status) { |
| 5335 | case 0: |
| 5336 | request->fl_type = F_UNLCK; |
| 5337 | break; |
| 5338 | case -NFS4ERR_DENIED: |
| 5339 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5340 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5341 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5342 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5343 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | return status; |
| 5345 | } |
| 5346 | |
| 5347 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5348 | { |
| 5349 | struct nfs4_exception exception = { }; |
| 5350 | int err; |
| 5351 | |
| 5352 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5353 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5354 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5355 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | &exception); |
| 5357 | } while (exception.retry); |
| 5358 | return err; |
| 5359 | } |
| 5360 | |
| 5361 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5362 | { |
| 5363 | int res = 0; |
| 5364 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5365 | case FL_POSIX: |
| 5366 | res = posix_lock_file_wait(file, fl); |
| 5367 | break; |
| 5368 | case FL_FLOCK: |
| 5369 | res = flock_lock_file_wait(file, fl); |
| 5370 | break; |
| 5371 | default: |
| 5372 | BUG(); |
| 5373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 | return res; |
| 5375 | } |
| 5376 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5377 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5378 | struct nfs_locku_args arg; |
| 5379 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5380 | struct nfs4_lock_state *lsp; |
| 5381 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5382 | struct file_lock fl; |
| 5383 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5384 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5385 | }; |
| 5386 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5387 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5388 | struct nfs_open_context *ctx, |
| 5389 | struct nfs4_lock_state *lsp, |
| 5390 | struct nfs_seqid *seqid) |
| 5391 | { |
| 5392 | struct nfs4_unlockdata *p; |
| 5393 | struct inode *inode = lsp->ls_state->inode; |
| 5394 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5395 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5396 | if (p == NULL) |
| 5397 | return NULL; |
| 5398 | p->arg.fh = NFS_FH(inode); |
| 5399 | p->arg.fl = &p->fl; |
| 5400 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5401 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5402 | p->lsp = lsp; |
| 5403 | atomic_inc(&lsp->ls_count); |
| 5404 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5405 | p->ctx = get_nfs_open_context(ctx); |
| 5406 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5407 | p->server = NFS_SERVER(inode); |
| 5408 | return p; |
| 5409 | } |
| 5410 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5411 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5412 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5413 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5414 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5415 | nfs4_put_lock_state(calldata->lsp); |
| 5416 | put_nfs_open_context(calldata->ctx); |
| 5417 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5418 | } |
| 5419 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5420 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5421 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5422 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5423 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5424 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5425 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5426 | switch (task->tk_status) { |
| 5427 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5428 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5429 | do_vfs_lock(calldata->fl.fl_file, &calldata->fl); |
| 5430 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5431 | &calldata->res.stateid)) |
| 5432 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5433 | case -NFS4ERR_BAD_STATEID: |
| 5434 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5435 | case -NFS4ERR_STALE_STATEID: |
| 5436 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5437 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5438 | &calldata->lsp->ls_stateid)) |
| 5439 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5440 | break; |
| 5441 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5442 | if (nfs4_async_handle_error(task, calldata->server, |
| 5443 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5444 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5445 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5446 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5447 | } |
| 5448 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5449 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5450 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5451 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5453 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5454 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5455 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5456 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5457 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5458 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5459 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5460 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5461 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5462 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5463 | &calldata->res.seq_res, |
| 5464 | task) != 0) |
| 5465 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5466 | return; |
| 5467 | out_no_action: |
| 5468 | task->tk_action = NULL; |
| 5469 | out_wait: |
| 5470 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5473 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5474 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5475 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5476 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5477 | }; |
| 5478 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5479 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5480 | struct nfs_open_context *ctx, |
| 5481 | struct nfs4_lock_state *lsp, |
| 5482 | struct nfs_seqid *seqid) |
| 5483 | { |
| 5484 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5485 | struct rpc_message msg = { |
| 5486 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5487 | .rpc_cred = ctx->cred, |
| 5488 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5489 | struct rpc_task_setup task_setup_data = { |
| 5490 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5491 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5492 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5493 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5494 | .flags = RPC_TASK_ASYNC, |
| 5495 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5496 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5497 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5498 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5499 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5500 | /* Ensure this is an unlock - when canceling a lock, the |
| 5501 | * canceled lock is passed in, and it won't be an unlock. |
| 5502 | */ |
| 5503 | fl->fl_type = F_UNLCK; |
| 5504 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5505 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5506 | if (data == NULL) { |
| 5507 | nfs_free_seqid(seqid); |
| 5508 | return ERR_PTR(-ENOMEM); |
| 5509 | } |
| 5510 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5511 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5512 | msg.rpc_argp = &data->arg; |
| 5513 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5514 | task_setup_data.callback_data = data; |
| 5515 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5516 | } |
| 5517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5519 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5520 | struct inode *inode = state->inode; |
| 5521 | struct nfs4_state_owner *sp = state->owner; |
| 5522 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5523 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5524 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5525 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5526 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5527 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5528 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5529 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5530 | status = nfs4_set_lock_state(state, request); |
| 5531 | /* Unlock _before_ we do the RPC call */ |
| 5532 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5533 | /* Exclude nfs_delegation_claim_locks() */ |
| 5534 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5535 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5536 | down_read(&nfsi->rwsem); |
| 5537 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5538 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5539 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5540 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5541 | } |
| 5542 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5543 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5544 | if (status != 0) |
| 5545 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5546 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5547 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5548 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5549 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5550 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5551 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5552 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5553 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5554 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5555 | 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] | 5556 | status = PTR_ERR(task); |
| 5557 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5558 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5559 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5560 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5561 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5562 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5563 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5564 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | } |
| 5566 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5567 | struct nfs4_lockdata { |
| 5568 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5569 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5570 | struct nfs4_lock_state *lsp; |
| 5571 | struct nfs_open_context *ctx; |
| 5572 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5573 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5574 | int rpc_status; |
| 5575 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5576 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5577 | }; |
| 5578 | |
| 5579 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5580 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5581 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5582 | { |
| 5583 | struct nfs4_lockdata *p; |
| 5584 | struct inode *inode = lsp->ls_state->inode; |
| 5585 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5586 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5587 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5588 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5589 | if (p == NULL) |
| 5590 | return NULL; |
| 5591 | |
| 5592 | p->arg.fh = NFS_FH(inode); |
| 5593 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5594 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5595 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5596 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5597 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5598 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5599 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5600 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5601 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5602 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5603 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5604 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5605 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5606 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5607 | atomic_inc(&lsp->ls_count); |
| 5608 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5609 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5610 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5611 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5612 | out_free_seqid: |
| 5613 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5614 | out_free: |
| 5615 | kfree(p); |
| 5616 | return NULL; |
| 5617 | } |
| 5618 | |
| 5619 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5620 | { |
| 5621 | struct nfs4_lockdata *data = calldata; |
| 5622 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5624 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5625 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5626 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5627 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5628 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5629 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5630 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5631 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5632 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5633 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5634 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5635 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5636 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5637 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5638 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5639 | &data->lsp->ls_stateid); |
| 5640 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5641 | if (!nfs4_valid_open_stateid(state)) { |
| 5642 | data->rpc_status = -EBADF; |
| 5643 | task->tk_action = NULL; |
| 5644 | goto out_release_open_seqid; |
| 5645 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5646 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5647 | if (nfs4_setup_sequence(data->server, |
| 5648 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5649 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5650 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5651 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5652 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5653 | nfs_release_seqid(data->arg.open_seqid); |
| 5654 | out_release_lock_seqid: |
| 5655 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5656 | out_wait: |
| 5657 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5658 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5659 | } |
| 5660 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5661 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5662 | { |
| 5663 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5664 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5665 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5666 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5667 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5668 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5669 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5670 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5671 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5672 | switch (task->tk_status) { |
| 5673 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5674 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5675 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5676 | if (data->arg.new_lock) { |
| 5677 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
| 5678 | if (do_vfs_lock(data->fl.fl_file, &data->fl) < 0) { |
| 5679 | rpc_restart_call_prepare(task); |
| 5680 | break; |
| 5681 | } |
| 5682 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5683 | if (data->arg.new_lock_owner != 0) { |
| 5684 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5685 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5686 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5687 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5688 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5689 | break; |
| 5690 | case -NFS4ERR_BAD_STATEID: |
| 5691 | case -NFS4ERR_OLD_STATEID: |
| 5692 | case -NFS4ERR_STALE_STATEID: |
| 5693 | case -NFS4ERR_EXPIRED: |
| 5694 | if (data->arg.new_lock_owner != 0) { |
| 5695 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5696 | &lsp->ls_state->open_stateid)) |
| 5697 | rpc_restart_call_prepare(task); |
| 5698 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5699 | &lsp->ls_stateid)) |
| 5700 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5701 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5702 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | static void nfs4_lock_release(void *calldata) |
| 5706 | { |
| 5707 | struct nfs4_lockdata *data = calldata; |
| 5708 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5709 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5710 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5711 | if (data->cancelled != 0) { |
| 5712 | struct rpc_task *task; |
| 5713 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5714 | data->arg.lock_seqid); |
| 5715 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5716 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5717 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5718 | } else |
| 5719 | nfs_free_seqid(data->arg.lock_seqid); |
| 5720 | nfs4_put_lock_state(data->lsp); |
| 5721 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5722 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5723 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5724 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5728 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5729 | .rpc_call_done = nfs4_lock_done, |
| 5730 | .rpc_release = nfs4_lock_release, |
| 5731 | }; |
| 5732 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5733 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5734 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5735 | switch (error) { |
| 5736 | case -NFS4ERR_ADMIN_REVOKED: |
| 5737 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5738 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5739 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5740 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5741 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5742 | break; |
| 5743 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5744 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5745 | case -NFS4ERR_EXPIRED: |
| 5746 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5747 | }; |
| 5748 | } |
| 5749 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5750 | 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] | 5751 | { |
| 5752 | struct nfs4_lockdata *data; |
| 5753 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5754 | struct rpc_message msg = { |
| 5755 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5756 | .rpc_cred = state->owner->so_cred, |
| 5757 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5758 | struct rpc_task_setup task_setup_data = { |
| 5759 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5760 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5761 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5762 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5763 | .flags = RPC_TASK_ASYNC, |
| 5764 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5765 | int ret; |
| 5766 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5767 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5768 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5769 | fl->fl_u.nfs4_fl.owner, |
| 5770 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5771 | if (data == NULL) |
| 5772 | return -ENOMEM; |
| 5773 | if (IS_SETLKW(cmd)) |
| 5774 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5775 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5776 | msg.rpc_argp = &data->arg; |
| 5777 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5778 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5779 | if (recovery_type > NFS_LOCK_NEW) { |
| 5780 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5781 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5782 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5783 | } else |
| 5784 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5785 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5786 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5787 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5788 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5789 | if (ret == 0) { |
| 5790 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5791 | if (ret) |
| 5792 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5793 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5794 | } else |
| 5795 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5796 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5797 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5798 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | } |
| 5800 | |
| 5801 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5802 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5803 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5804 | struct nfs4_exception exception = { |
| 5805 | .inode = state->inode, |
| 5806 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5807 | int err; |
| 5808 | |
| 5809 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5810 | /* Cache the lock if possible... */ |
| 5811 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5812 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5813 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5814 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5815 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5816 | break; |
| 5817 | nfs4_handle_exception(server, err, &exception); |
| 5818 | } while (exception.retry); |
| 5819 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | } |
| 5821 | |
| 5822 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5823 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5824 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5825 | struct nfs4_exception exception = { |
| 5826 | .inode = state->inode, |
| 5827 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5828 | int err; |
| 5829 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5830 | err = nfs4_set_lock_state(state, request); |
| 5831 | if (err != 0) |
| 5832 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 5833 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5834 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 5835 | return 0; |
| 5836 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5837 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5838 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5839 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5840 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5841 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5842 | switch (err) { |
| 5843 | default: |
| 5844 | goto out; |
| 5845 | case -NFS4ERR_GRACE: |
| 5846 | case -NFS4ERR_DELAY: |
| 5847 | nfs4_handle_exception(server, err, &exception); |
| 5848 | err = 0; |
| 5849 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5850 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5851 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5852 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | } |
| 5854 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5855 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5856 | /** |
| 5857 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5858 | * |
| 5859 | * @state: NFSv4 state for an inode |
| 5860 | * |
| 5861 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5862 | * Otherwise a negative NFS4ERR value is returned. |
| 5863 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5864 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5865 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5866 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5867 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5868 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5869 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5870 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5871 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5872 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5873 | |
| 5874 | status = nfs41_test_stateid(server, |
| 5875 | &lsp->ls_stateid, |
| 5876 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5877 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5878 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5879 | /* Free the stateid unless the server |
| 5880 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5881 | if (status != -NFS4ERR_BAD_STATEID) |
| 5882 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5883 | &lsp->ls_stateid, |
| 5884 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5885 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5886 | ret = status; |
| 5887 | } |
| 5888 | } |
| 5889 | }; |
| 5890 | |
| 5891 | return ret; |
| 5892 | } |
| 5893 | |
| 5894 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5895 | { |
| 5896 | int status = NFS_OK; |
| 5897 | |
| 5898 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5899 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5900 | if (status != NFS_OK) |
| 5901 | status = nfs4_lock_expired(state, request); |
| 5902 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5903 | } |
| 5904 | #endif |
| 5905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5906 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5907 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5908 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5909 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5910 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5911 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5912 | if ((fl_flags & FL_POSIX) && |
| 5913 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5914 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5915 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5916 | status = nfs4_set_lock_state(state, request); |
| 5917 | if (status != 0) |
| 5918 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5919 | request->fl_flags |= FL_ACCESS; |
| 5920 | status = do_vfs_lock(request->fl_file, request); |
| 5921 | if (status < 0) |
| 5922 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5923 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5924 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5925 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5926 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5927 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5928 | status = do_vfs_lock(request->fl_file, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5929 | up_read(&nfsi->rwsem); |
| 5930 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5931 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5932 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5933 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5934 | out: |
| 5935 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | return status; |
| 5937 | } |
| 5938 | |
| 5939 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5940 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5941 | struct nfs4_exception exception = { |
| 5942 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5943 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5944 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5945 | int err; |
| 5946 | |
| 5947 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5948 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5949 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5950 | if (err == -NFS4ERR_DENIED) |
| 5951 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5952 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5953 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5954 | } while (exception.retry); |
| 5955 | return err; |
| 5956 | } |
| 5957 | |
| 5958 | static int |
| 5959 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5960 | { |
| 5961 | struct nfs_open_context *ctx; |
| 5962 | struct nfs4_state *state; |
| 5963 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5964 | int status; |
| 5965 | |
| 5966 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5967 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | state = ctx->state; |
| 5969 | |
| 5970 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5971 | return -EINVAL; |
| 5972 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5973 | if (IS_GETLK(cmd)) { |
| 5974 | if (state != NULL) |
| 5975 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5976 | return 0; |
| 5977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5978 | |
| 5979 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5980 | return -EINVAL; |
| 5981 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5982 | if (request->fl_type == F_UNLCK) { |
| 5983 | if (state != NULL) |
| 5984 | return nfs4_proc_unlck(state, cmd, request); |
| 5985 | return 0; |
| 5986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5988 | if (state == NULL) |
| 5989 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5990 | /* |
| 5991 | * Don't rely on the VFS having checked the file open mode, |
| 5992 | * since it won't do this for flock() locks. |
| 5993 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5994 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5995 | case F_RDLCK: |
| 5996 | if (!(filp->f_mode & FMODE_READ)) |
| 5997 | return -EBADF; |
| 5998 | break; |
| 5999 | case F_WRLCK: |
| 6000 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6001 | return -EBADF; |
| 6002 | } |
| 6003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6004 | do { |
| 6005 | status = nfs4_proc_setlk(state, cmd, request); |
| 6006 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6007 | break; |
| 6008 | timeout = nfs4_set_lock_task_retry(timeout); |
| 6009 | status = -ERESTARTSYS; |
| 6010 | if (signalled()) |
| 6011 | break; |
| 6012 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | return status; |
| 6014 | } |
| 6015 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6016 | 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] | 6017 | { |
| 6018 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6019 | int err; |
| 6020 | |
| 6021 | err = nfs4_set_lock_state(state, fl); |
| 6022 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6023 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6024 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6025 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6026 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6027 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6028 | struct nfs_release_lockowner_data { |
| 6029 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6030 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6031 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6032 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6033 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6034 | }; |
| 6035 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6036 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6037 | { |
| 6038 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6039 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6040 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6041 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6042 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6043 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6047 | { |
| 6048 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6049 | struct nfs_server *server = data->server; |
| 6050 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6051 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6052 | |
| 6053 | switch (task->tk_status) { |
| 6054 | case 0: |
| 6055 | renew_lease(server, data->timestamp); |
| 6056 | break; |
| 6057 | case -NFS4ERR_STALE_CLIENTID: |
| 6058 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6059 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6060 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6061 | case -NFS4ERR_LEASE_MOVED: |
| 6062 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6063 | if (nfs4_async_handle_error(task, server, |
| 6064 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6065 | rpc_restart_call_prepare(task); |
| 6066 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6067 | } |
| 6068 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6069 | static void nfs4_release_lockowner_release(void *calldata) |
| 6070 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6071 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6072 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6073 | kfree(calldata); |
| 6074 | } |
| 6075 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6076 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6077 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6078 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6079 | .rpc_release = nfs4_release_lockowner_release, |
| 6080 | }; |
| 6081 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6082 | static void |
| 6083 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6084 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6085 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6086 | struct rpc_message msg = { |
| 6087 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6088 | }; |
| 6089 | |
| 6090 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6091 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6092 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6093 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6094 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6095 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6096 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6097 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6098 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6099 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6100 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6101 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6102 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6103 | msg.rpc_resp = &data->res; |
| 6104 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6105 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6106 | } |
| 6107 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6108 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6109 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6110 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 6111 | const void *buf, size_t buflen, |
| 6112 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6113 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6114 | if (strcmp(key, "") != 0) |
| 6115 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6116 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6117 | return nfs4_proc_set_acl(d_inode(dentry), buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6118 | } |
| 6119 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6120 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 6121 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6122 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6123 | if (strcmp(key, "") != 0) |
| 6124 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6125 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6126 | return nfs4_proc_get_acl(d_inode(dentry), buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6129 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 6130 | size_t list_len, const char *name, |
| 6131 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6132 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6133 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6134 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6135 | if (!nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry)))) |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 6136 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6137 | |
| 6138 | if (list && len <= list_len) |
| 6139 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6140 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6143 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 6144 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 6145 | { |
| 6146 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 6147 | } |
| 6148 | |
| 6149 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 6150 | const void *buf, size_t buflen, |
| 6151 | int flags, int type) |
| 6152 | { |
| 6153 | if (security_ismaclabel(key)) |
| 6154 | return nfs4_set_security_label(dentry, buf, buflen); |
| 6155 | |
| 6156 | return -EOPNOTSUPP; |
| 6157 | } |
| 6158 | |
| 6159 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 6160 | void *buf, size_t buflen, int type) |
| 6161 | { |
| 6162 | if (security_ismaclabel(key)) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6163 | return nfs4_get_security_label(d_inode(dentry), buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6164 | return -EOPNOTSUPP; |
| 6165 | } |
| 6166 | |
| 6167 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 6168 | size_t list_len, const char *name, |
| 6169 | size_t name_len, int type) |
| 6170 | { |
| 6171 | size_t len = 0; |
| 6172 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6173 | if (nfs_server_capable(d_inode(dentry), NFS_CAP_SECURITY_LABEL)) { |
| 6174 | len = security_inode_listsecurity(d_inode(dentry), NULL, 0); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6175 | if (list && len <= list_len) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6176 | security_inode_listsecurity(d_inode(dentry), list, len); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6177 | } |
| 6178 | return len; |
| 6179 | } |
| 6180 | |
| 6181 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6182 | .prefix = XATTR_SECURITY_PREFIX, |
| 6183 | .list = nfs4_xattr_list_nfs4_label, |
| 6184 | .get = nfs4_xattr_get_nfs4_label, |
| 6185 | .set = nfs4_xattr_set_nfs4_label, |
| 6186 | }; |
| 6187 | #endif |
| 6188 | |
| 6189 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6190 | /* |
| 6191 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6192 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6193 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6194 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6195 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6196 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6197 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6198 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6199 | return; |
| 6200 | |
| 6201 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6202 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6203 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6204 | fattr->nlink = 2; |
| 6205 | } |
| 6206 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6207 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6208 | const struct qstr *name, |
| 6209 | struct nfs4_fs_locations *fs_locations, |
| 6210 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6211 | { |
| 6212 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6213 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6214 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6215 | }; |
| 6216 | struct nfs4_fs_locations_arg args = { |
| 6217 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6218 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6219 | .page = page, |
| 6220 | .bitmask = bitmask, |
| 6221 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6222 | struct nfs4_fs_locations_res res = { |
| 6223 | .fs_locations = fs_locations, |
| 6224 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6225 | struct rpc_message msg = { |
| 6226 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6227 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6228 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6229 | }; |
| 6230 | int status; |
| 6231 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6232 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6233 | |
| 6234 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6235 | * is not supported */ |
| 6236 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6237 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6238 | else |
| 6239 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6240 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6241 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6242 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6243 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6244 | 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] | 6245 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6246 | return status; |
| 6247 | } |
| 6248 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6249 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6250 | const struct qstr *name, |
| 6251 | struct nfs4_fs_locations *fs_locations, |
| 6252 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6253 | { |
| 6254 | struct nfs4_exception exception = { }; |
| 6255 | int err; |
| 6256 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6257 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6258 | fs_locations, page); |
| 6259 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6260 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6261 | &exception); |
| 6262 | } while (exception.retry); |
| 6263 | return err; |
| 6264 | } |
| 6265 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6266 | /* |
| 6267 | * This operation also signals the server that this client is |
| 6268 | * performing migration recovery. The server can stop returning |
| 6269 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6270 | * appended to this compound to identify the client ID which is |
| 6271 | * performing recovery. |
| 6272 | */ |
| 6273 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6274 | struct nfs4_fs_locations *locations, |
| 6275 | struct page *page, struct rpc_cred *cred) |
| 6276 | { |
| 6277 | struct nfs_server *server = NFS_SERVER(inode); |
| 6278 | struct rpc_clnt *clnt = server->client; |
| 6279 | u32 bitmask[2] = { |
| 6280 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6281 | }; |
| 6282 | struct nfs4_fs_locations_arg args = { |
| 6283 | .clientid = server->nfs_client->cl_clientid, |
| 6284 | .fh = NFS_FH(inode), |
| 6285 | .page = page, |
| 6286 | .bitmask = bitmask, |
| 6287 | .migration = 1, /* skip LOOKUP */ |
| 6288 | .renew = 1, /* append RENEW */ |
| 6289 | }; |
| 6290 | struct nfs4_fs_locations_res res = { |
| 6291 | .fs_locations = locations, |
| 6292 | .migration = 1, |
| 6293 | .renew = 1, |
| 6294 | }; |
| 6295 | struct rpc_message msg = { |
| 6296 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6297 | .rpc_argp = &args, |
| 6298 | .rpc_resp = &res, |
| 6299 | .rpc_cred = cred, |
| 6300 | }; |
| 6301 | unsigned long now = jiffies; |
| 6302 | int status; |
| 6303 | |
| 6304 | nfs_fattr_init(&locations->fattr); |
| 6305 | locations->server = server; |
| 6306 | locations->nlocations = 0; |
| 6307 | |
| 6308 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6309 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6310 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6311 | &args.seq_args, &res.seq_res); |
| 6312 | if (status) |
| 6313 | return status; |
| 6314 | |
| 6315 | renew_lease(server, now); |
| 6316 | return 0; |
| 6317 | } |
| 6318 | |
| 6319 | #ifdef CONFIG_NFS_V4_1 |
| 6320 | |
| 6321 | /* |
| 6322 | * This operation also signals the server that this client is |
| 6323 | * performing migration recovery. The server can stop asserting |
| 6324 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6325 | * performing this operation is identified in the SEQUENCE |
| 6326 | * operation in this compound. |
| 6327 | * |
| 6328 | * When the client supports GETATTR(fs_locations_info), it can |
| 6329 | * be plumbed in here. |
| 6330 | */ |
| 6331 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6332 | struct nfs4_fs_locations *locations, |
| 6333 | struct page *page, struct rpc_cred *cred) |
| 6334 | { |
| 6335 | struct nfs_server *server = NFS_SERVER(inode); |
| 6336 | struct rpc_clnt *clnt = server->client; |
| 6337 | u32 bitmask[2] = { |
| 6338 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6339 | }; |
| 6340 | struct nfs4_fs_locations_arg args = { |
| 6341 | .fh = NFS_FH(inode), |
| 6342 | .page = page, |
| 6343 | .bitmask = bitmask, |
| 6344 | .migration = 1, /* skip LOOKUP */ |
| 6345 | }; |
| 6346 | struct nfs4_fs_locations_res res = { |
| 6347 | .fs_locations = locations, |
| 6348 | .migration = 1, |
| 6349 | }; |
| 6350 | struct rpc_message msg = { |
| 6351 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6352 | .rpc_argp = &args, |
| 6353 | .rpc_resp = &res, |
| 6354 | .rpc_cred = cred, |
| 6355 | }; |
| 6356 | int status; |
| 6357 | |
| 6358 | nfs_fattr_init(&locations->fattr); |
| 6359 | locations->server = server; |
| 6360 | locations->nlocations = 0; |
| 6361 | |
| 6362 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6363 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6364 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6365 | &args.seq_args, &res.seq_res); |
| 6366 | if (status == NFS4_OK && |
| 6367 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6368 | status = -NFS4ERR_LEASE_MOVED; |
| 6369 | return status; |
| 6370 | } |
| 6371 | |
| 6372 | #endif /* CONFIG_NFS_V4_1 */ |
| 6373 | |
| 6374 | /** |
| 6375 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6376 | * @inode: inode on FSID that is migrating |
| 6377 | * @locations: result of query |
| 6378 | * @page: buffer |
| 6379 | * @cred: credential to use for this operation |
| 6380 | * |
| 6381 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6382 | * operation failed, or a negative errno if a local error occurred. |
| 6383 | * |
| 6384 | * On success, "locations" is filled in, but if the server has |
| 6385 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6386 | * asserted. |
| 6387 | * |
| 6388 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6389 | * from this client that require migration recovery. |
| 6390 | */ |
| 6391 | int nfs4_proc_get_locations(struct inode *inode, |
| 6392 | struct nfs4_fs_locations *locations, |
| 6393 | struct page *page, struct rpc_cred *cred) |
| 6394 | { |
| 6395 | struct nfs_server *server = NFS_SERVER(inode); |
| 6396 | struct nfs_client *clp = server->nfs_client; |
| 6397 | const struct nfs4_mig_recovery_ops *ops = |
| 6398 | clp->cl_mvops->mig_recovery_ops; |
| 6399 | struct nfs4_exception exception = { }; |
| 6400 | int status; |
| 6401 | |
| 6402 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6403 | (unsigned long long)server->fsid.major, |
| 6404 | (unsigned long long)server->fsid.minor, |
| 6405 | clp->cl_hostname); |
| 6406 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6407 | |
| 6408 | do { |
| 6409 | status = ops->get_locations(inode, locations, page, cred); |
| 6410 | if (status != -NFS4ERR_DELAY) |
| 6411 | break; |
| 6412 | nfs4_handle_exception(server, status, &exception); |
| 6413 | } while (exception.retry); |
| 6414 | return status; |
| 6415 | } |
| 6416 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6417 | /* |
| 6418 | * This operation also signals the server that this client is |
| 6419 | * performing "lease moved" recovery. The server can stop |
| 6420 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6421 | * is appended to this compound to identify the client ID which is |
| 6422 | * performing recovery. |
| 6423 | */ |
| 6424 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6425 | { |
| 6426 | struct nfs_server *server = NFS_SERVER(inode); |
| 6427 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6428 | struct rpc_clnt *clnt = server->client; |
| 6429 | struct nfs4_fsid_present_arg args = { |
| 6430 | .fh = NFS_FH(inode), |
| 6431 | .clientid = clp->cl_clientid, |
| 6432 | .renew = 1, /* append RENEW */ |
| 6433 | }; |
| 6434 | struct nfs4_fsid_present_res res = { |
| 6435 | .renew = 1, |
| 6436 | }; |
| 6437 | struct rpc_message msg = { |
| 6438 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6439 | .rpc_argp = &args, |
| 6440 | .rpc_resp = &res, |
| 6441 | .rpc_cred = cred, |
| 6442 | }; |
| 6443 | unsigned long now = jiffies; |
| 6444 | int status; |
| 6445 | |
| 6446 | res.fh = nfs_alloc_fhandle(); |
| 6447 | if (res.fh == NULL) |
| 6448 | return -ENOMEM; |
| 6449 | |
| 6450 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6451 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6452 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6453 | &args.seq_args, &res.seq_res); |
| 6454 | nfs_free_fhandle(res.fh); |
| 6455 | if (status) |
| 6456 | return status; |
| 6457 | |
| 6458 | do_renew_lease(clp, now); |
| 6459 | return 0; |
| 6460 | } |
| 6461 | |
| 6462 | #ifdef CONFIG_NFS_V4_1 |
| 6463 | |
| 6464 | /* |
| 6465 | * This operation also signals the server that this client is |
| 6466 | * performing "lease moved" recovery. The server can stop asserting |
| 6467 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6468 | * this operation is identified in the SEQUENCE operation in this |
| 6469 | * compound. |
| 6470 | */ |
| 6471 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6472 | { |
| 6473 | struct nfs_server *server = NFS_SERVER(inode); |
| 6474 | struct rpc_clnt *clnt = server->client; |
| 6475 | struct nfs4_fsid_present_arg args = { |
| 6476 | .fh = NFS_FH(inode), |
| 6477 | }; |
| 6478 | struct nfs4_fsid_present_res res = { |
| 6479 | }; |
| 6480 | struct rpc_message msg = { |
| 6481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6482 | .rpc_argp = &args, |
| 6483 | .rpc_resp = &res, |
| 6484 | .rpc_cred = cred, |
| 6485 | }; |
| 6486 | int status; |
| 6487 | |
| 6488 | res.fh = nfs_alloc_fhandle(); |
| 6489 | if (res.fh == NULL) |
| 6490 | return -ENOMEM; |
| 6491 | |
| 6492 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6493 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6494 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6495 | &args.seq_args, &res.seq_res); |
| 6496 | nfs_free_fhandle(res.fh); |
| 6497 | if (status == NFS4_OK && |
| 6498 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6499 | status = -NFS4ERR_LEASE_MOVED; |
| 6500 | return status; |
| 6501 | } |
| 6502 | |
| 6503 | #endif /* CONFIG_NFS_V4_1 */ |
| 6504 | |
| 6505 | /** |
| 6506 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6507 | * @inode: inode on FSID to check |
| 6508 | * @cred: credential to use for this operation |
| 6509 | * |
| 6510 | * Server indicates whether the FSID is present, moved, or not |
| 6511 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6512 | * condition for this client ID. |
| 6513 | * |
| 6514 | * Returns NFS4_OK if the FSID is present on this server, |
| 6515 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6516 | * NFS4ERR code if some error occurred on the server, or a |
| 6517 | * negative errno if a local failure occurred. |
| 6518 | */ |
| 6519 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6520 | { |
| 6521 | struct nfs_server *server = NFS_SERVER(inode); |
| 6522 | struct nfs_client *clp = server->nfs_client; |
| 6523 | const struct nfs4_mig_recovery_ops *ops = |
| 6524 | clp->cl_mvops->mig_recovery_ops; |
| 6525 | struct nfs4_exception exception = { }; |
| 6526 | int status; |
| 6527 | |
| 6528 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6529 | (unsigned long long)server->fsid.major, |
| 6530 | (unsigned long long)server->fsid.minor, |
| 6531 | clp->cl_hostname); |
| 6532 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6533 | |
| 6534 | do { |
| 6535 | status = ops->fsid_present(inode, cred); |
| 6536 | if (status != -NFS4ERR_DELAY) |
| 6537 | break; |
| 6538 | nfs4_handle_exception(server, status, &exception); |
| 6539 | } while (exception.retry); |
| 6540 | return status; |
| 6541 | } |
| 6542 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6543 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6544 | * If 'use_integrity' is true and the state managment nfs_client |
| 6545 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6546 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6547 | * Considerations sections. Otherwise, just use the user cred with the |
| 6548 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6549 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6550 | 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] | 6551 | { |
| 6552 | int status; |
| 6553 | struct nfs4_secinfo_arg args = { |
| 6554 | .dir_fh = NFS_FH(dir), |
| 6555 | .name = name, |
| 6556 | }; |
| 6557 | struct nfs4_secinfo_res res = { |
| 6558 | .flavors = flavors, |
| 6559 | }; |
| 6560 | struct rpc_message msg = { |
| 6561 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6562 | .rpc_argp = &args, |
| 6563 | .rpc_resp = &res, |
| 6564 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6565 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6566 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6567 | |
| 6568 | if (use_integrity) { |
| 6569 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6570 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6571 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6572 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6573 | |
| 6574 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6575 | |
| 6576 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6577 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6578 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6579 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6580 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6581 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6582 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6583 | if (cred) |
| 6584 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6585 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6586 | return status; |
| 6587 | } |
| 6588 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6589 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6590 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6591 | { |
| 6592 | struct nfs4_exception exception = { }; |
| 6593 | int err; |
| 6594 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6595 | err = -NFS4ERR_WRONGSEC; |
| 6596 | |
| 6597 | /* try to use integrity protection with machine cred */ |
| 6598 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6599 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6600 | |
| 6601 | /* |
| 6602 | * if unable to use integrity protection, or SECINFO with |
| 6603 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6604 | * disallowed by spec, but exists in deployed servers) use |
| 6605 | * the current filesystem's rpc_client and the user cred. |
| 6606 | */ |
| 6607 | if (err == -NFS4ERR_WRONGSEC) |
| 6608 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6609 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6610 | trace_nfs4_secinfo(dir, name, err); |
| 6611 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6612 | &exception); |
| 6613 | } while (exception.retry); |
| 6614 | return err; |
| 6615 | } |
| 6616 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6617 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6618 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6619 | * Check the exchange flags returned by the server for invalid flags, having |
| 6620 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6621 | * DS flags set. |
| 6622 | */ |
| 6623 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6624 | { |
| 6625 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6626 | goto out_inval; |
| 6627 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6628 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6629 | goto out_inval; |
| 6630 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6631 | goto out_inval; |
| 6632 | return NFS_OK; |
| 6633 | out_inval: |
| 6634 | return -NFS4ERR_INVAL; |
| 6635 | } |
| 6636 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6637 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6638 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6639 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6640 | { |
| 6641 | if (a->server_scope_sz == b->server_scope_sz && |
| 6642 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6643 | return true; |
| 6644 | |
| 6645 | return false; |
| 6646 | } |
| 6647 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6648 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6649 | * nfs4_proc_bind_conn_to_session() |
| 6650 | * |
| 6651 | * The 4.1 client currently uses the same TCP connection for the |
| 6652 | * fore and backchannel. |
| 6653 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6654 | 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] | 6655 | { |
| 6656 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6657 | struct nfs41_bind_conn_to_session_args args = { |
| 6658 | .client = clp, |
| 6659 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6660 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6661 | struct nfs41_bind_conn_to_session_res res; |
| 6662 | struct rpc_message msg = { |
| 6663 | .rpc_proc = |
| 6664 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6665 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6666 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6667 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6668 | }; |
| 6669 | |
| 6670 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6671 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6672 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 6673 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 6674 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6675 | |
| 6676 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6677 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6678 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6679 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6680 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6681 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6682 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6683 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6684 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6685 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6686 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6687 | __func__); |
| 6688 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6689 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6690 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6691 | if (res.use_conn_in_rdma_mode != args.use_conn_in_rdma_mode) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6692 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6693 | __func__); |
| 6694 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6695 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6696 | } |
| 6697 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6698 | out: |
| 6699 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6700 | return status; |
| 6701 | } |
| 6702 | |
| 6703 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6704 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6705 | * 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] | 6706 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6707 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6708 | .how = SP4_MACH_CRED, |
| 6709 | .enforce.u.words = { |
| 6710 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6711 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6712 | 1 << (OP_CREATE_SESSION - 32) | |
| 6713 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6714 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6715 | }, |
| 6716 | .allow.u.words = { |
| 6717 | [0] = 1 << (OP_CLOSE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6718 | 1 << (OP_LOCKU) | |
| 6719 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6720 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6721 | 1 << (OP_SECINFO_NO_NAME - 32) | |
| 6722 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6723 | 1 << (OP_FREE_STATEID - 32) | |
| 6724 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6725 | } |
| 6726 | }; |
| 6727 | |
| 6728 | /* |
| 6729 | * Select the state protection mode for client `clp' given the server results |
| 6730 | * from exchange_id in `sp'. |
| 6731 | * |
| 6732 | * Returns 0 on success, negative errno otherwise. |
| 6733 | */ |
| 6734 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6735 | struct nfs41_state_protection *sp) |
| 6736 | { |
| 6737 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6738 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6739 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6740 | 1 << (OP_CREATE_SESSION - 32) | |
| 6741 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6742 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6743 | }; |
| 6744 | unsigned int i; |
| 6745 | |
| 6746 | if (sp->how == SP4_MACH_CRED) { |
| 6747 | /* Print state protect result */ |
| 6748 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6749 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6750 | if (test_bit(i, sp->enforce.u.longs)) |
| 6751 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6752 | if (test_bit(i, sp->allow.u.longs)) |
| 6753 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6754 | } |
| 6755 | |
| 6756 | /* make sure nothing is on enforce list that isn't supported */ |
| 6757 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6758 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6759 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6760 | return -EINVAL; |
| 6761 | } |
| 6762 | } |
| 6763 | |
| 6764 | /* |
| 6765 | * Minimal mode - state operations are allowed to use machine |
| 6766 | * credential. Note this already happens by default, so the |
| 6767 | * client doesn't have to do anything more than the negotiation. |
| 6768 | * |
| 6769 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6770 | * we're already using the machine cred for exchange_id |
| 6771 | * and will never use a different cred. |
| 6772 | */ |
| 6773 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6774 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6775 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6776 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6777 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6778 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6779 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 6780 | } else { |
| 6781 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6782 | return -EINVAL; |
| 6783 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6784 | |
| 6785 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
| 6786 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 6787 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 6788 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 6789 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6790 | |
| 6791 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 6792 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 6793 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 6794 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 6795 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6796 | |
| 6797 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 6798 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 6799 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 6800 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 6801 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6802 | |
| 6803 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 6804 | dfprintk(MOUNT, " write mode enabled\n"); |
| 6805 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 6806 | } |
| 6807 | |
| 6808 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 6809 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 6810 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 6811 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6812 | } |
| 6813 | |
| 6814 | return 0; |
| 6815 | } |
| 6816 | |
| 6817 | /* |
| 6818 | * _nfs4_proc_exchange_id() |
| 6819 | * |
| 6820 | * Wrapper for EXCHANGE_ID operation. |
| 6821 | */ |
| 6822 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 6823 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6824 | { |
| 6825 | nfs4_verifier verifier; |
| 6826 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6827 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6828 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6829 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6830 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6831 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 6832 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 6833 | #else |
| 6834 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 6835 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 6836 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6837 | }; |
| 6838 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6839 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6840 | }; |
| 6841 | int status; |
| 6842 | struct rpc_message msg = { |
| 6843 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 6844 | .rpc_argp = &args, |
| 6845 | .rpc_resp = &res, |
| 6846 | .rpc_cred = cred, |
| 6847 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6848 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6849 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6850 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 6851 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6852 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 6853 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6854 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6855 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6856 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6857 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6858 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6859 | status = -ENOMEM; |
| 6860 | goto out; |
| 6861 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6862 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6863 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6864 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6865 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6866 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6867 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6868 | } |
| 6869 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6870 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6871 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6872 | status = -ENOMEM; |
| 6873 | goto out_server_scope; |
| 6874 | } |
| 6875 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6876 | switch (sp4_how) { |
| 6877 | case SP4_NONE: |
| 6878 | args.state_protect.how = SP4_NONE; |
| 6879 | break; |
| 6880 | |
| 6881 | case SP4_MACH_CRED: |
| 6882 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 6883 | break; |
| 6884 | |
| 6885 | default: |
| 6886 | /* unsupported! */ |
| 6887 | WARN_ON_ONCE(1); |
| 6888 | status = -EINVAL; |
| 6889 | goto out_server_scope; |
| 6890 | } |
| 6891 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6892 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6893 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6894 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6895 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6896 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6897 | if (status == 0) |
| 6898 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 6899 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6900 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6901 | clp->cl_clientid = res.clientid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 6902 | clp->cl_exchange_flags = res.flags; |
| 6903 | /* Client ID is not confirmed */ |
| 6904 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 6905 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 6906 | &clp->cl_session->session_state); |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6907 | clp->cl_seqid = res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 6908 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6909 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6910 | kfree(clp->cl_serverowner); |
| 6911 | clp->cl_serverowner = res.server_owner; |
| 6912 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6913 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6914 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6915 | kfree(clp->cl_implid); |
| 6916 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6917 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6918 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6919 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6920 | res.server_scope)) { |
| 6921 | dprintk("%s: server_scope mismatch detected\n", |
| 6922 | __func__); |
| 6923 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6924 | kfree(clp->cl_serverscope); |
| 6925 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6926 | } |
| 6927 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6928 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6929 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6930 | goto out; |
| 6931 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6932 | } else |
| 6933 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6934 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6935 | out_server_owner: |
| 6936 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6937 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6938 | kfree(res.server_scope); |
| 6939 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6940 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6941 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6942 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6943 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6944 | clp->cl_implid->date.seconds, |
| 6945 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6946 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6947 | return status; |
| 6948 | } |
| 6949 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6950 | /* |
| 6951 | * nfs4_proc_exchange_id() |
| 6952 | * |
| 6953 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6954 | * |
| 6955 | * Since the clientid has expired, all compounds using sessions |
| 6956 | * associated with the stale clientid will be returning |
| 6957 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 6958 | * be in some phase of session reset. |
| 6959 | * |
| 6960 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 6961 | */ |
| 6962 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 6963 | { |
| 6964 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 6965 | int status; |
| 6966 | |
| 6967 | /* try SP4_MACH_CRED if krb5i/p */ |
| 6968 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 6969 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 6970 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 6971 | if (!status) |
| 6972 | return 0; |
| 6973 | } |
| 6974 | |
| 6975 | /* try SP4_NONE */ |
| 6976 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 6977 | } |
| 6978 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6979 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6980 | struct rpc_cred *cred) |
| 6981 | { |
| 6982 | struct rpc_message msg = { |
| 6983 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6984 | .rpc_argp = clp, |
| 6985 | .rpc_cred = cred, |
| 6986 | }; |
| 6987 | int status; |
| 6988 | |
| 6989 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6990 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6991 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6992 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6993 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6994 | return status; |
| 6995 | } |
| 6996 | |
| 6997 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6998 | struct rpc_cred *cred) |
| 6999 | { |
| 7000 | unsigned int loop; |
| 7001 | int ret; |
| 7002 | |
| 7003 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7004 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7005 | switch (ret) { |
| 7006 | case -NFS4ERR_DELAY: |
| 7007 | case -NFS4ERR_CLIENTID_BUSY: |
| 7008 | ssleep(1); |
| 7009 | break; |
| 7010 | default: |
| 7011 | return ret; |
| 7012 | } |
| 7013 | } |
| 7014 | return 0; |
| 7015 | } |
| 7016 | |
| 7017 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7018 | { |
| 7019 | struct rpc_cred *cred; |
| 7020 | int ret = 0; |
| 7021 | |
| 7022 | if (clp->cl_mvops->minor_version < 1) |
| 7023 | goto out; |
| 7024 | if (clp->cl_exchange_flags == 0) |
| 7025 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7026 | if (clp->cl_preserve_clid) |
| 7027 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7028 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7029 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7030 | if (cred) |
| 7031 | put_rpccred(cred); |
| 7032 | switch (ret) { |
| 7033 | case 0: |
| 7034 | case -NFS4ERR_STALE_CLIENTID: |
| 7035 | clp->cl_exchange_flags = 0; |
| 7036 | } |
| 7037 | out: |
| 7038 | return ret; |
| 7039 | } |
| 7040 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7041 | struct nfs4_get_lease_time_data { |
| 7042 | struct nfs4_get_lease_time_args *args; |
| 7043 | struct nfs4_get_lease_time_res *res; |
| 7044 | struct nfs_client *clp; |
| 7045 | }; |
| 7046 | |
| 7047 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7048 | void *calldata) |
| 7049 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7050 | struct nfs4_get_lease_time_data *data = |
| 7051 | (struct nfs4_get_lease_time_data *)calldata; |
| 7052 | |
| 7053 | dprintk("--> %s\n", __func__); |
| 7054 | /* just setup sequence, do not trigger session recovery |
| 7055 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7056 | nfs41_setup_sequence(data->clp->cl_session, |
| 7057 | &data->args->la_seq_args, |
| 7058 | &data->res->lr_seq_res, |
| 7059 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7060 | dprintk("<-- %s\n", __func__); |
| 7061 | } |
| 7062 | |
| 7063 | /* |
| 7064 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7065 | * from sequence operation or clientid errors. |
| 7066 | */ |
| 7067 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7068 | { |
| 7069 | struct nfs4_get_lease_time_data *data = |
| 7070 | (struct nfs4_get_lease_time_data *)calldata; |
| 7071 | |
| 7072 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7073 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7074 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7075 | switch (task->tk_status) { |
| 7076 | case -NFS4ERR_DELAY: |
| 7077 | case -NFS4ERR_GRACE: |
| 7078 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7079 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7080 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7081 | /* fall through */ |
| 7082 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7083 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7084 | return; |
| 7085 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7086 | dprintk("<-- %s\n", __func__); |
| 7087 | } |
| 7088 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7089 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7090 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7091 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7092 | }; |
| 7093 | |
| 7094 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7095 | { |
| 7096 | struct rpc_task *task; |
| 7097 | struct nfs4_get_lease_time_args args; |
| 7098 | struct nfs4_get_lease_time_res res = { |
| 7099 | .lr_fsinfo = fsinfo, |
| 7100 | }; |
| 7101 | struct nfs4_get_lease_time_data data = { |
| 7102 | .args = &args, |
| 7103 | .res = &res, |
| 7104 | .clp = clp, |
| 7105 | }; |
| 7106 | struct rpc_message msg = { |
| 7107 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7108 | .rpc_argp = &args, |
| 7109 | .rpc_resp = &res, |
| 7110 | }; |
| 7111 | struct rpc_task_setup task_setup = { |
| 7112 | .rpc_client = clp->cl_rpcclient, |
| 7113 | .rpc_message = &msg, |
| 7114 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7115 | .callback_data = &data, |
| 7116 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7117 | }; |
| 7118 | int status; |
| 7119 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7120 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7121 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7122 | dprintk("--> %s\n", __func__); |
| 7123 | task = rpc_run_task(&task_setup); |
| 7124 | |
| 7125 | if (IS_ERR(task)) |
| 7126 | status = PTR_ERR(task); |
| 7127 | else { |
| 7128 | status = task->tk_status; |
| 7129 | rpc_put_task(task); |
| 7130 | } |
| 7131 | dprintk("<-- %s return %d\n", __func__, status); |
| 7132 | |
| 7133 | return status; |
| 7134 | } |
| 7135 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7136 | /* |
| 7137 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7138 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7139 | * use them. |
| 7140 | * |
| 7141 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7142 | * always set csa_cachethis to FALSE because the current implementation |
| 7143 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7144 | */ |
| 7145 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 7146 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7147 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7148 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7149 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7150 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7151 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7152 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7153 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7154 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7155 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7156 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7157 | |
| 7158 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7159 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7160 | __func__, |
| 7161 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7162 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7163 | |
| 7164 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7165 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 7166 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 7167 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7168 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 7169 | args->bc_attrs.max_reqs = 1; |
| 7170 | |
| 7171 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7172 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7173 | __func__, |
| 7174 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7175 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7176 | args->bc_attrs.max_reqs); |
| 7177 | } |
| 7178 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7179 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7180 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7181 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7182 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7183 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7184 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7185 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7186 | return -EINVAL; |
| 7187 | /* |
| 7188 | * Our requested max_ops is the minimum we need; we're not |
| 7189 | * prepared to break up compounds into smaller pieces than that. |
| 7190 | * So, no point even trying to continue if the server won't |
| 7191 | * cooperate: |
| 7192 | */ |
| 7193 | if (rcvd->max_ops < sent->max_ops) |
| 7194 | return -EINVAL; |
| 7195 | if (rcvd->max_reqs == 0) |
| 7196 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7197 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7198 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7199 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7200 | } |
| 7201 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7202 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7203 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7204 | { |
| 7205 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7206 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7207 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7208 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7209 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7210 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7211 | return -EINVAL; |
| 7212 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7213 | return -EINVAL; |
| 7214 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7215 | return -EINVAL; |
| 7216 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7217 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7218 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7219 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7220 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7221 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7222 | return 0; |
| 7223 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7224 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7225 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7226 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7227 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7228 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7229 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7230 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7231 | if (ret) |
| 7232 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7233 | return nfs4_verify_back_channel_attrs(args, res); |
| 7234 | } |
| 7235 | |
| 7236 | static void nfs4_update_session(struct nfs4_session *session, |
| 7237 | struct nfs41_create_session_res *res) |
| 7238 | { |
| 7239 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7240 | /* Mark client id and session as being confirmed */ |
| 7241 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7242 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7243 | session->flags = res->flags; |
| 7244 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7245 | if (res->flags & SESSION4_BACK_CHAN) |
| 7246 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7247 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7248 | } |
| 7249 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7250 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7251 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7252 | { |
| 7253 | struct nfs4_session *session = clp->cl_session; |
| 7254 | struct nfs41_create_session_args args = { |
| 7255 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7256 | .clientid = clp->cl_clientid, |
| 7257 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7258 | .cb_program = NFS4_CALLBACK, |
| 7259 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7260 | struct nfs41_create_session_res res; |
| 7261 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7262 | struct rpc_message msg = { |
| 7263 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7264 | .rpc_argp = &args, |
| 7265 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7266 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7267 | }; |
| 7268 | int status; |
| 7269 | |
| 7270 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7271 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7272 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7273 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7274 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7275 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7276 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7277 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7278 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7279 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7280 | if (clp->cl_seqid == res.seqid) |
| 7281 | clp->cl_seqid++; |
| 7282 | if (status) |
| 7283 | goto out; |
| 7284 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7285 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7286 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7287 | return status; |
| 7288 | } |
| 7289 | |
| 7290 | /* |
| 7291 | * Issues a CREATE_SESSION operation to the server. |
| 7292 | * It is the responsibility of the caller to verify the session is |
| 7293 | * expired before calling this routine. |
| 7294 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7295 | 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] | 7296 | { |
| 7297 | int status; |
| 7298 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7299 | struct nfs4_session *session = clp->cl_session; |
| 7300 | |
| 7301 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7302 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7303 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7304 | if (status) |
| 7305 | goto out; |
| 7306 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7307 | /* Init or reset the session slot tables */ |
| 7308 | status = nfs4_setup_session_slot_tables(session); |
| 7309 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7310 | if (status) |
| 7311 | goto out; |
| 7312 | |
| 7313 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7314 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7315 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7316 | out: |
| 7317 | dprintk("<-- %s\n", __func__); |
| 7318 | return status; |
| 7319 | } |
| 7320 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7321 | /* |
| 7322 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7323 | * The caller must serialize access to this routine. |
| 7324 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7325 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7326 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7327 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7328 | struct rpc_message msg = { |
| 7329 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7330 | .rpc_argp = session, |
| 7331 | .rpc_cred = cred, |
| 7332 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7333 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7334 | |
| 7335 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7336 | |
| 7337 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7338 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7339 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7340 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7341 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7342 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7343 | |
| 7344 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7345 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7346 | "Session has been destroyed regardless...\n", status); |
| 7347 | |
| 7348 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7349 | return status; |
| 7350 | } |
| 7351 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7352 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7353 | * Renew the cl_session lease. |
| 7354 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7355 | struct nfs4_sequence_data { |
| 7356 | struct nfs_client *clp; |
| 7357 | struct nfs4_sequence_args args; |
| 7358 | struct nfs4_sequence_res res; |
| 7359 | }; |
| 7360 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7361 | static void nfs41_sequence_release(void *data) |
| 7362 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7363 | struct nfs4_sequence_data *calldata = data; |
| 7364 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7365 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7366 | if (atomic_read(&clp->cl_count) > 1) |
| 7367 | nfs4_schedule_state_renewal(clp); |
| 7368 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7369 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7370 | } |
| 7371 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7372 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7373 | { |
| 7374 | switch(task->tk_status) { |
| 7375 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7376 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7377 | return -EAGAIN; |
| 7378 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7379 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7380 | } |
| 7381 | return 0; |
| 7382 | } |
| 7383 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7384 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7385 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7386 | struct nfs4_sequence_data *calldata = data; |
| 7387 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7388 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7389 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7390 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7391 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7392 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7393 | if (task->tk_status < 0) { |
| 7394 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7395 | if (atomic_read(&clp->cl_count) == 1) |
| 7396 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7397 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7398 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7399 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7400 | return; |
| 7401 | } |
| 7402 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7403 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7404 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7405 | dprintk("<-- %s\n", __func__); |
| 7406 | } |
| 7407 | |
| 7408 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7409 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7410 | struct nfs4_sequence_data *calldata = data; |
| 7411 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7412 | struct nfs4_sequence_args *args; |
| 7413 | struct nfs4_sequence_res *res; |
| 7414 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7415 | args = task->tk_msg.rpc_argp; |
| 7416 | res = task->tk_msg.rpc_resp; |
| 7417 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7418 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7422 | .rpc_call_done = nfs41_sequence_call_done, |
| 7423 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7424 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7425 | }; |
| 7426 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7427 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7428 | struct rpc_cred *cred, |
| 7429 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7430 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7431 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7432 | struct rpc_message msg = { |
| 7433 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7434 | .rpc_cred = cred, |
| 7435 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7436 | struct rpc_task_setup task_setup_data = { |
| 7437 | .rpc_client = clp->cl_rpcclient, |
| 7438 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7439 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7440 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7441 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7442 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7443 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7444 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7445 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7446 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7447 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7448 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7449 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7450 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7451 | if (is_privileged) |
| 7452 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7453 | msg.rpc_argp = &calldata->args; |
| 7454 | msg.rpc_resp = &calldata->res; |
| 7455 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7456 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7457 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7458 | return rpc_run_task(&task_setup_data); |
| 7459 | } |
| 7460 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7461 | 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] | 7462 | { |
| 7463 | struct rpc_task *task; |
| 7464 | int ret = 0; |
| 7465 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7466 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7467 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7468 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7469 | if (IS_ERR(task)) |
| 7470 | ret = PTR_ERR(task); |
| 7471 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7472 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7473 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7474 | return ret; |
| 7475 | } |
| 7476 | |
| 7477 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7478 | { |
| 7479 | struct rpc_task *task; |
| 7480 | int ret; |
| 7481 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7482 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7483 | if (IS_ERR(task)) { |
| 7484 | ret = PTR_ERR(task); |
| 7485 | goto out; |
| 7486 | } |
| 7487 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7488 | if (!ret) { |
| 7489 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 7490 | |
| 7491 | if (task->tk_status == 0) |
| 7492 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7493 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7494 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7495 | rpc_put_task(task); |
| 7496 | out: |
| 7497 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7498 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7499 | } |
| 7500 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7501 | struct nfs4_reclaim_complete_data { |
| 7502 | struct nfs_client *clp; |
| 7503 | struct nfs41_reclaim_complete_args arg; |
| 7504 | struct nfs41_reclaim_complete_res res; |
| 7505 | }; |
| 7506 | |
| 7507 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7508 | { |
| 7509 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7510 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7511 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7512 | &calldata->arg.seq_args, |
| 7513 | &calldata->res.seq_res, |
| 7514 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7515 | } |
| 7516 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7517 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7518 | { |
| 7519 | switch(task->tk_status) { |
| 7520 | case 0: |
| 7521 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7522 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7523 | break; |
| 7524 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7525 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7526 | /* fall through */ |
| 7527 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7528 | return -EAGAIN; |
| 7529 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7530 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7531 | } |
| 7532 | return 0; |
| 7533 | } |
| 7534 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7535 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7536 | { |
| 7537 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7538 | struct nfs_client *clp = calldata->clp; |
| 7539 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7540 | |
| 7541 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7542 | if (!nfs41_sequence_done(task, res)) |
| 7543 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7544 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7545 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7546 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7547 | rpc_restart_call_prepare(task); |
| 7548 | return; |
| 7549 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7550 | dprintk("<-- %s\n", __func__); |
| 7551 | } |
| 7552 | |
| 7553 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7554 | { |
| 7555 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7556 | |
| 7557 | kfree(calldata); |
| 7558 | } |
| 7559 | |
| 7560 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7561 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7562 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7563 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7564 | }; |
| 7565 | |
| 7566 | /* |
| 7567 | * Issue a global reclaim complete. |
| 7568 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7569 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7570 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7571 | { |
| 7572 | struct nfs4_reclaim_complete_data *calldata; |
| 7573 | struct rpc_task *task; |
| 7574 | struct rpc_message msg = { |
| 7575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7576 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7577 | }; |
| 7578 | struct rpc_task_setup task_setup_data = { |
| 7579 | .rpc_client = clp->cl_rpcclient, |
| 7580 | .rpc_message = &msg, |
| 7581 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7582 | .flags = RPC_TASK_ASYNC, |
| 7583 | }; |
| 7584 | int status = -ENOMEM; |
| 7585 | |
| 7586 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7587 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7588 | if (calldata == NULL) |
| 7589 | goto out; |
| 7590 | calldata->clp = clp; |
| 7591 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7592 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7593 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7594 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7595 | msg.rpc_argp = &calldata->arg; |
| 7596 | msg.rpc_resp = &calldata->res; |
| 7597 | task_setup_data.callback_data = calldata; |
| 7598 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7599 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7600 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7601 | goto out; |
| 7602 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7603 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7604 | if (status == 0) |
| 7605 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7606 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7607 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7608 | out: |
| 7609 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7610 | return status; |
| 7611 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7612 | |
| 7613 | static void |
| 7614 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7615 | { |
| 7616 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7617 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7618 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7619 | |
| 7620 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7621 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 7622 | * right now covering the LAYOUTGET we are about to send. |
| 7623 | * However, that is not so catastrophic, and there seems |
| 7624 | * to be no way to prevent it completely. |
| 7625 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7626 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7627 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7628 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7629 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7630 | NFS_I(lgp->args.inode)->layout, |
Peng Tao | ce6ab4f | 2014-09-06 00:53:24 +0800 | [diff] [blame] | 7631 | &lgp->args.range, |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7632 | lgp->args.ctx->state)) { |
| 7633 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7634 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7635 | } |
| 7636 | |
| 7637 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7638 | { |
| 7639 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7640 | struct inode *inode = lgp->args.inode; |
| 7641 | struct nfs_server *server = NFS_SERVER(inode); |
| 7642 | struct pnfs_layout_hdr *lo; |
| 7643 | struct nfs4_state *state = NULL; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7644 | unsigned long timeo, now, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7645 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7646 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7647 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7648 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7649 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7650 | |
| 7651 | switch (task->tk_status) { |
| 7652 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7653 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7654 | /* |
| 7655 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
| 7656 | * (or clients) writing to the same RAID stripe |
| 7657 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7658 | case -NFS4ERR_LAYOUTTRYLATER: |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7659 | /* |
| 7660 | * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall |
| 7661 | * existing layout before getting a new one). |
| 7662 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7663 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7664 | timeo = rpc_get_timeout(task->tk_client); |
| 7665 | giveup = lgp->args.timestamp + timeo; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7666 | now = jiffies; |
| 7667 | if (time_after(giveup, now)) { |
| 7668 | unsigned long delay; |
| 7669 | |
| 7670 | /* Delay for: |
| 7671 | * - Not less then NFS4_POLL_RETRY_MIN. |
| 7672 | * - One last time a jiffie before we give up |
| 7673 | * - exponential backoff (time_now minus start_attempt) |
| 7674 | */ |
| 7675 | delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN, |
| 7676 | min((giveup - now - 1), |
| 7677 | now - lgp->args.timestamp)); |
| 7678 | |
| 7679 | dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n", |
| 7680 | __func__, delay); |
| 7681 | rpc_delay(task, delay); |
| 7682 | task->tk_status = 0; |
| 7683 | rpc_restart_call_prepare(task); |
| 7684 | goto out; /* Do not call nfs4_async_handle_error() */ |
| 7685 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7686 | break; |
| 7687 | case -NFS4ERR_EXPIRED: |
| 7688 | case -NFS4ERR_BAD_STATEID: |
| 7689 | spin_lock(&inode->i_lock); |
| 7690 | lo = NFS_I(inode)->layout; |
| 7691 | if (!lo || list_empty(&lo->plh_segs)) { |
| 7692 | spin_unlock(&inode->i_lock); |
| 7693 | /* If the open stateid was bad, then recover it. */ |
| 7694 | state = lgp->args.ctx->state; |
| 7695 | } else { |
| 7696 | LIST_HEAD(head); |
| 7697 | |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7698 | /* |
| 7699 | * Mark the bad layout state as invalid, then retry |
| 7700 | * with the current stateid. |
| 7701 | */ |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7702 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 7703 | spin_unlock(&inode->i_lock); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7704 | pnfs_free_lseg_list(&head); |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7705 | |
| 7706 | task->tk_status = 0; |
| 7707 | rpc_restart_call_prepare(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7708 | } |
| 7709 | } |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7710 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7711 | rpc_restart_call_prepare(task); |
| 7712 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7713 | dprintk("<-- %s\n", __func__); |
| 7714 | } |
| 7715 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7716 | static size_t max_response_pages(struct nfs_server *server) |
| 7717 | { |
| 7718 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7719 | return nfs_page_array_len(0, max_resp_sz); |
| 7720 | } |
| 7721 | |
| 7722 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7723 | { |
| 7724 | int i; |
| 7725 | |
| 7726 | if (!pages) |
| 7727 | return; |
| 7728 | |
| 7729 | for (i = 0; i < size; i++) { |
| 7730 | if (!pages[i]) |
| 7731 | break; |
| 7732 | __free_page(pages[i]); |
| 7733 | } |
| 7734 | kfree(pages); |
| 7735 | } |
| 7736 | |
| 7737 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7738 | { |
| 7739 | struct page **pages; |
| 7740 | int i; |
| 7741 | |
| 7742 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7743 | if (!pages) { |
| 7744 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7745 | return NULL; |
| 7746 | } |
| 7747 | |
| 7748 | for (i = 0; i < size; i++) { |
| 7749 | pages[i] = alloc_page(gfp_flags); |
| 7750 | if (!pages[i]) { |
| 7751 | dprintk("%s: failed to allocate page\n", __func__); |
| 7752 | nfs4_free_pages(pages, size); |
| 7753 | return NULL; |
| 7754 | } |
| 7755 | } |
| 7756 | |
| 7757 | return pages; |
| 7758 | } |
| 7759 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7760 | static void nfs4_layoutget_release(void *calldata) |
| 7761 | { |
| 7762 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7763 | struct inode *inode = lgp->args.inode; |
| 7764 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7765 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7766 | |
| 7767 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7768 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7769 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7770 | put_nfs_open_context(lgp->args.ctx); |
| 7771 | kfree(calldata); |
| 7772 | dprintk("<-- %s\n", __func__); |
| 7773 | } |
| 7774 | |
| 7775 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 7776 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 7777 | .rpc_call_done = nfs4_layoutget_done, |
| 7778 | .rpc_release = nfs4_layoutget_release, |
| 7779 | }; |
| 7780 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7781 | struct pnfs_layout_segment * |
| 7782 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7783 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7784 | struct inode *inode = lgp->args.inode; |
| 7785 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7786 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7787 | struct rpc_task *task; |
| 7788 | struct rpc_message msg = { |
| 7789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 7790 | .rpc_argp = &lgp->args, |
| 7791 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7792 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7793 | }; |
| 7794 | struct rpc_task_setup task_setup_data = { |
| 7795 | .rpc_client = server->client, |
| 7796 | .rpc_message = &msg, |
| 7797 | .callback_ops = &nfs4_layoutget_call_ops, |
| 7798 | .callback_data = lgp, |
| 7799 | .flags = RPC_TASK_ASYNC, |
| 7800 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7801 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7802 | int status = 0; |
| 7803 | |
| 7804 | dprintk("--> %s\n", __func__); |
| 7805 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 7806 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 7807 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 7808 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7809 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 7810 | if (!lgp->args.layout.pages) { |
| 7811 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7812 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7813 | } |
| 7814 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7815 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7816 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 7817 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7818 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7819 | 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] | 7820 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7821 | task = rpc_run_task(&task_setup_data); |
| 7822 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7823 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7824 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7825 | if (status == 0) |
| 7826 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7827 | trace_nfs4_layoutget(lgp->args.ctx, |
| 7828 | &lgp->args.range, |
| 7829 | &lgp->res.range, |
| 7830 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 7831 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 7832 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7833 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7834 | rpc_put_task(task); |
| 7835 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7836 | if (status) |
| 7837 | return ERR_PTR(status); |
| 7838 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7839 | } |
| 7840 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7841 | static void |
| 7842 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 7843 | { |
| 7844 | struct nfs4_layoutreturn *lrp = calldata; |
| 7845 | |
| 7846 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7847 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 7848 | &lrp->args.seq_args, |
| 7849 | &lrp->res.seq_res, |
| 7850 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7851 | } |
| 7852 | |
| 7853 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 7854 | { |
| 7855 | struct nfs4_layoutreturn *lrp = calldata; |
| 7856 | struct nfs_server *server; |
| 7857 | |
| 7858 | dprintk("--> %s\n", __func__); |
| 7859 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7860 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7861 | return; |
| 7862 | |
| 7863 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7864 | switch (task->tk_status) { |
| 7865 | default: |
| 7866 | task->tk_status = 0; |
| 7867 | case 0: |
| 7868 | break; |
| 7869 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7870 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7871 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7872 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7873 | return; |
| 7874 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7875 | dprintk("<-- %s\n", __func__); |
| 7876 | } |
| 7877 | |
| 7878 | static void nfs4_layoutreturn_release(void *calldata) |
| 7879 | { |
| 7880 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7881 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7882 | |
| 7883 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7884 | spin_lock(&lo->plh_inode->i_lock); |
| 7885 | if (lrp->res.lrs_present) |
| 7886 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 7887 | pnfs_clear_layoutreturn_waitbit(lo); |
Peng Tao | 193e3aa | 2014-11-17 09:30:41 +0800 | [diff] [blame] | 7888 | clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, &lo->plh_flags); |
| 7889 | rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7890 | lo->plh_block_lgets--; |
| 7891 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 7892 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 7893 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7894 | kfree(calldata); |
| 7895 | dprintk("<-- %s\n", __func__); |
| 7896 | } |
| 7897 | |
| 7898 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 7899 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 7900 | .rpc_call_done = nfs4_layoutreturn_done, |
| 7901 | .rpc_release = nfs4_layoutreturn_release, |
| 7902 | }; |
| 7903 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 7904 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7905 | { |
| 7906 | struct rpc_task *task; |
| 7907 | struct rpc_message msg = { |
| 7908 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 7909 | .rpc_argp = &lrp->args, |
| 7910 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 7911 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7912 | }; |
| 7913 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 7914 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7915 | .rpc_message = &msg, |
| 7916 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 7917 | .callback_data = lrp, |
| 7918 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 7919 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7920 | |
| 7921 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 7922 | if (!sync) { |
| 7923 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 7924 | if (!lrp->inode) { |
| 7925 | nfs4_layoutreturn_release(lrp); |
| 7926 | return -EAGAIN; |
| 7927 | } |
| 7928 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 7929 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7930 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7931 | task = rpc_run_task(&task_setup_data); |
| 7932 | if (IS_ERR(task)) |
| 7933 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 7934 | if (sync) |
| 7935 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7936 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7937 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7938 | rpc_put_task(task); |
| 7939 | return status; |
| 7940 | } |
| 7941 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7942 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7943 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7944 | struct pnfs_device *pdev, |
| 7945 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7946 | { |
| 7947 | struct nfs4_getdeviceinfo_args args = { |
| 7948 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 7949 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 7950 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7951 | }; |
| 7952 | struct nfs4_getdeviceinfo_res res = { |
| 7953 | .pdev = pdev, |
| 7954 | }; |
| 7955 | struct rpc_message msg = { |
| 7956 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7957 | .rpc_argp = &args, |
| 7958 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7959 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7960 | }; |
| 7961 | int status; |
| 7962 | |
| 7963 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7964 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 7965 | if (res.notification & ~args.notify_types) |
| 7966 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 7967 | if (res.notification != args.notify_types) |
| 7968 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 7969 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7970 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7971 | |
| 7972 | return status; |
| 7973 | } |
| 7974 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7975 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7976 | struct pnfs_device *pdev, |
| 7977 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7978 | { |
| 7979 | struct nfs4_exception exception = { }; |
| 7980 | int err; |
| 7981 | |
| 7982 | do { |
| 7983 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7984 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7985 | &exception); |
| 7986 | } while (exception.retry); |
| 7987 | return err; |
| 7988 | } |
| 7989 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7990 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7991 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7992 | { |
| 7993 | struct nfs4_layoutcommit_data *data = calldata; |
| 7994 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7995 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7996 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7997 | nfs41_setup_sequence(session, |
| 7998 | &data->args.seq_args, |
| 7999 | &data->res.seq_res, |
| 8000 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8001 | } |
| 8002 | |
| 8003 | static void |
| 8004 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8005 | { |
| 8006 | struct nfs4_layoutcommit_data *data = calldata; |
| 8007 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8008 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8009 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8010 | return; |
| 8011 | |
| 8012 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8013 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8014 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8015 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8016 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8017 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8018 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8019 | break; |
| 8020 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8021 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8022 | rpc_restart_call_prepare(task); |
| 8023 | return; |
| 8024 | } |
| 8025 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8026 | } |
| 8027 | |
| 8028 | static void nfs4_layoutcommit_release(void *calldata) |
| 8029 | { |
| 8030 | struct nfs4_layoutcommit_data *data = calldata; |
| 8031 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8032 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8033 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8034 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8035 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8036 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8037 | kfree(data); |
| 8038 | } |
| 8039 | |
| 8040 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8041 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8042 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8043 | .rpc_release = nfs4_layoutcommit_release, |
| 8044 | }; |
| 8045 | |
| 8046 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8047 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8048 | { |
| 8049 | struct rpc_message msg = { |
| 8050 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8051 | .rpc_argp = &data->args, |
| 8052 | .rpc_resp = &data->res, |
| 8053 | .rpc_cred = data->cred, |
| 8054 | }; |
| 8055 | struct rpc_task_setup task_setup_data = { |
| 8056 | .task = &data->task, |
| 8057 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8058 | .rpc_message = &msg, |
| 8059 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8060 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8061 | }; |
| 8062 | struct rpc_task *task; |
| 8063 | int status = 0; |
| 8064 | |
| 8065 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 8066 | "lbw: %llu inode %lu\n", |
| 8067 | data->task.tk_pid, sync, |
| 8068 | data->args.lastbytewritten, |
| 8069 | data->args.inode->i_ino); |
| 8070 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8071 | if (!sync) { |
| 8072 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8073 | if (data->inode == NULL) { |
| 8074 | nfs4_layoutcommit_release(data); |
| 8075 | return -EAGAIN; |
| 8076 | } |
| 8077 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8078 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8079 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8080 | task = rpc_run_task(&task_setup_data); |
| 8081 | if (IS_ERR(task)) |
| 8082 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8083 | if (sync) |
| 8084 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8085 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8086 | dprintk("%s: status %d\n", __func__, status); |
| 8087 | rpc_put_task(task); |
| 8088 | return status; |
| 8089 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8090 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8091 | /** |
| 8092 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8093 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8094 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8095 | static int |
| 8096 | _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] | 8097 | struct nfs_fsinfo *info, |
| 8098 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8099 | { |
| 8100 | struct nfs41_secinfo_no_name_args args = { |
| 8101 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8102 | }; |
| 8103 | struct nfs4_secinfo_res res = { |
| 8104 | .flavors = flavors, |
| 8105 | }; |
| 8106 | struct rpc_message msg = { |
| 8107 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8108 | .rpc_argp = &args, |
| 8109 | .rpc_resp = &res, |
| 8110 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8111 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8112 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8113 | int status; |
| 8114 | |
| 8115 | if (use_integrity) { |
| 8116 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8117 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8118 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8119 | } |
| 8120 | |
| 8121 | dprintk("--> %s\n", __func__); |
| 8122 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8123 | &res.seq_res, 0); |
| 8124 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8125 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8126 | if (cred) |
| 8127 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8128 | |
| 8129 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8130 | } |
| 8131 | |
| 8132 | static int |
| 8133 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8134 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8135 | { |
| 8136 | struct nfs4_exception exception = { }; |
| 8137 | int err; |
| 8138 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8139 | /* first try using integrity protection */ |
| 8140 | err = -NFS4ERR_WRONGSEC; |
| 8141 | |
| 8142 | /* try to use integrity protection with machine cred */ |
| 8143 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8144 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8145 | flavors, true); |
| 8146 | |
| 8147 | /* |
| 8148 | * if unable to use integrity protection, or SECINFO with |
| 8149 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8150 | * disallowed by spec, but exists in deployed servers) use |
| 8151 | * the current filesystem's rpc_client and the user cred. |
| 8152 | */ |
| 8153 | if (err == -NFS4ERR_WRONGSEC) |
| 8154 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8155 | flavors, false); |
| 8156 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8157 | switch (err) { |
| 8158 | case 0: |
| 8159 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8160 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8161 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8162 | default: |
| 8163 | err = nfs4_handle_exception(server, err, &exception); |
| 8164 | } |
| 8165 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8166 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8167 | return err; |
| 8168 | } |
| 8169 | |
| 8170 | static int |
| 8171 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8172 | struct nfs_fsinfo *info) |
| 8173 | { |
| 8174 | int err; |
| 8175 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8176 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8177 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8178 | struct nfs4_secinfo4 *secinfo; |
| 8179 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8180 | |
| 8181 | page = alloc_page(GFP_KERNEL); |
| 8182 | if (!page) { |
| 8183 | err = -ENOMEM; |
| 8184 | goto out; |
| 8185 | } |
| 8186 | |
| 8187 | flavors = page_address(page); |
| 8188 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8189 | |
| 8190 | /* |
| 8191 | * Fall back on "guess and check" method if |
| 8192 | * the server doesn't support SECINFO_NO_NAME |
| 8193 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8194 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8195 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8196 | goto out_freepage; |
| 8197 | } |
| 8198 | if (err) |
| 8199 | goto out_freepage; |
| 8200 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8201 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8202 | secinfo = &flavors->flavors[i]; |
| 8203 | |
| 8204 | switch (secinfo->flavor) { |
| 8205 | case RPC_AUTH_NULL: |
| 8206 | case RPC_AUTH_UNIX: |
| 8207 | case RPC_AUTH_GSS: |
| 8208 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8209 | &secinfo->flavor_info); |
| 8210 | break; |
| 8211 | default: |
| 8212 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8213 | break; |
| 8214 | } |
| 8215 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8216 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8217 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8218 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8219 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8220 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8221 | info, flavor); |
| 8222 | if (!err) |
| 8223 | break; |
| 8224 | } |
| 8225 | } |
| 8226 | |
| 8227 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8228 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8229 | |
| 8230 | out_freepage: |
| 8231 | put_page(page); |
| 8232 | if (err == -EACCES) |
| 8233 | return -EPERM; |
| 8234 | out: |
| 8235 | return err; |
| 8236 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8237 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8238 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8239 | nfs4_stateid *stateid, |
| 8240 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8241 | { |
| 8242 | int status; |
| 8243 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8244 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8245 | }; |
| 8246 | struct nfs41_test_stateid_res res; |
| 8247 | struct rpc_message msg = { |
| 8248 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8249 | .rpc_argp = &args, |
| 8250 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8251 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8252 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8253 | struct rpc_clnt *rpc_client = server->client; |
| 8254 | |
| 8255 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8256 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8257 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8258 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8259 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8260 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8261 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8262 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8263 | if (status != NFS_OK) { |
| 8264 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8265 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8266 | } |
| 8267 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8268 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8269 | } |
| 8270 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8271 | /** |
| 8272 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8273 | * |
| 8274 | * @server: server / transport on which to perform the operation |
| 8275 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8276 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8277 | * |
| 8278 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8279 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8280 | * failed or the state ID is not currently valid. |
| 8281 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8282 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8283 | nfs4_stateid *stateid, |
| 8284 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8285 | { |
| 8286 | struct nfs4_exception exception = { }; |
| 8287 | int err; |
| 8288 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8289 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8290 | if (err != -NFS4ERR_DELAY) |
| 8291 | break; |
| 8292 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8293 | } while (exception.retry); |
| 8294 | return err; |
| 8295 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8296 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8297 | struct nfs_free_stateid_data { |
| 8298 | struct nfs_server *server; |
| 8299 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8300 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8301 | }; |
| 8302 | |
| 8303 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8304 | { |
| 8305 | struct nfs_free_stateid_data *data = calldata; |
| 8306 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8307 | &data->args.seq_args, |
| 8308 | &data->res.seq_res, |
| 8309 | task); |
| 8310 | } |
| 8311 | |
| 8312 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8313 | { |
| 8314 | struct nfs_free_stateid_data *data = calldata; |
| 8315 | |
| 8316 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8317 | |
| 8318 | switch (task->tk_status) { |
| 8319 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8320 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8321 | rpc_restart_call_prepare(task); |
| 8322 | } |
| 8323 | } |
| 8324 | |
| 8325 | static void nfs41_free_stateid_release(void *calldata) |
| 8326 | { |
| 8327 | kfree(calldata); |
| 8328 | } |
| 8329 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8330 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8331 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8332 | .rpc_call_done = nfs41_free_stateid_done, |
| 8333 | .rpc_release = nfs41_free_stateid_release, |
| 8334 | }; |
| 8335 | |
| 8336 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8337 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8338 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8339 | bool privileged) |
| 8340 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8341 | struct rpc_message msg = { |
| 8342 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8343 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8344 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8345 | struct rpc_task_setup task_setup = { |
| 8346 | .rpc_client = server->client, |
| 8347 | .rpc_message = &msg, |
| 8348 | .callback_ops = &nfs41_free_stateid_ops, |
| 8349 | .flags = RPC_TASK_ASYNC, |
| 8350 | }; |
| 8351 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8352 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8353 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8354 | &task_setup.rpc_client, &msg); |
| 8355 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8356 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8357 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8358 | if (!data) |
| 8359 | return ERR_PTR(-ENOMEM); |
| 8360 | data->server = server; |
| 8361 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8362 | |
| 8363 | task_setup.callback_data = data; |
| 8364 | |
| 8365 | msg.rpc_argp = &data->args; |
| 8366 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8367 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8368 | if (privileged) |
| 8369 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8370 | |
| 8371 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8372 | } |
| 8373 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8374 | /** |
| 8375 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8376 | * |
| 8377 | * @server: server / transport on which to perform the operation |
| 8378 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8379 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8380 | * |
| 8381 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8382 | * negative NFS4ERR value is returned. |
| 8383 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8384 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8385 | nfs4_stateid *stateid, |
| 8386 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8387 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8388 | struct rpc_task *task; |
| 8389 | int ret; |
| 8390 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8391 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8392 | if (IS_ERR(task)) |
| 8393 | return PTR_ERR(task); |
| 8394 | ret = rpc_wait_for_completion_task(task); |
| 8395 | if (!ret) |
| 8396 | ret = task->tk_status; |
| 8397 | rpc_put_task(task); |
| 8398 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8399 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8400 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8401 | static void |
| 8402 | 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] | 8403 | { |
| 8404 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8405 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8406 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8407 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8408 | nfs4_free_lock_state(server, lsp); |
| 8409 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8410 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8411 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8412 | } |
| 8413 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8414 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8415 | const nfs4_stateid *s2) |
| 8416 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8417 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8418 | return false; |
| 8419 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8420 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8421 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8422 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8423 | return true; |
| 8424 | |
| 8425 | return false; |
| 8426 | } |
| 8427 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8428 | #endif /* CONFIG_NFS_V4_1 */ |
| 8429 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8430 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8431 | const nfs4_stateid *s2) |
| 8432 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8433 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8434 | } |
| 8435 | |
| 8436 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8437 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8438 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8439 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8440 | .recover_open = nfs4_open_reclaim, |
| 8441 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8442 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8443 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8444 | }; |
| 8445 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8446 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8447 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8448 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8449 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8450 | .recover_open = nfs4_open_reclaim, |
| 8451 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8452 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8453 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8454 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8455 | }; |
| 8456 | #endif /* CONFIG_NFS_V4_1 */ |
| 8457 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8458 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8459 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8460 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 8461 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8462 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8463 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8464 | }; |
| 8465 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8466 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8467 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8468 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8469 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8470 | .recover_open = nfs41_open_expired, |
| 8471 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8472 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8473 | }; |
| 8474 | #endif /* CONFIG_NFS_V4_1 */ |
| 8475 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8476 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8477 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8478 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8479 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8480 | }; |
| 8481 | |
| 8482 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8483 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8484 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8485 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8486 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8487 | }; |
| 8488 | #endif |
| 8489 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8490 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8491 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8492 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8493 | }; |
| 8494 | |
| 8495 | #if defined(CONFIG_NFS_V4_1) |
| 8496 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8497 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8498 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8499 | }; |
| 8500 | #endif /* CONFIG_NFS_V4_1 */ |
| 8501 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8502 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8503 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8504 | .init_caps = NFS_CAP_READDIRPLUS |
| 8505 | | NFS_CAP_ATOMIC_OPEN |
| 8506 | | NFS_CAP_CHANGE_ATTR |
| 8507 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8508 | .init_client = nfs40_init_client, |
| 8509 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8510 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8511 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8512 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8513 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8514 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8515 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8516 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8517 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8518 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8519 | }; |
| 8520 | |
| 8521 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8522 | static struct nfs_seqid * |
| 8523 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 8524 | { |
| 8525 | return NULL; |
| 8526 | } |
| 8527 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8528 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8529 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8530 | .init_caps = NFS_CAP_READDIRPLUS |
| 8531 | | NFS_CAP_ATOMIC_OPEN |
| 8532 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8533 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8534 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8535 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8536 | .init_client = nfs41_init_client, |
| 8537 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8538 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8539 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8540 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8541 | .alloc_seqid = nfs_alloc_no_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8542 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8543 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8544 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8545 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8546 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8547 | }; |
| 8548 | #endif |
| 8549 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8550 | #if defined(CONFIG_NFS_V4_2) |
| 8551 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8552 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8553 | .init_caps = NFS_CAP_READDIRPLUS |
| 8554 | | NFS_CAP_ATOMIC_OPEN |
| 8555 | | NFS_CAP_CHANGE_ATTR |
| 8556 | | NFS_CAP_POSIX_LOCK |
| 8557 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8558 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 8559 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 8560 | | NFS_CAP_DEALLOCATE |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8561 | | NFS_CAP_SEEK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8562 | .init_client = nfs41_init_client, |
| 8563 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8564 | .match_stateid = nfs41_match_stateid, |
| 8565 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8566 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8567 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8568 | .alloc_seqid = nfs_alloc_no_seqid, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8569 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8570 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8571 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 8572 | }; |
| 8573 | #endif |
| 8574 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8575 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8576 | [0] = &nfs_v4_0_minor_ops, |
| 8577 | #if defined(CONFIG_NFS_V4_1) |
| 8578 | [1] = &nfs_v4_1_minor_ops, |
| 8579 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8580 | #if defined(CONFIG_NFS_V4_2) |
| 8581 | [2] = &nfs_v4_2_minor_ops, |
| 8582 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8583 | }; |
| 8584 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8585 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8586 | .create = nfs_create, |
| 8587 | .lookup = nfs_lookup, |
| 8588 | .atomic_open = nfs_atomic_open, |
| 8589 | .link = nfs_link, |
| 8590 | .unlink = nfs_unlink, |
| 8591 | .symlink = nfs_symlink, |
| 8592 | .mkdir = nfs_mkdir, |
| 8593 | .rmdir = nfs_rmdir, |
| 8594 | .mknod = nfs_mknod, |
| 8595 | .rename = nfs_rename, |
| 8596 | .permission = nfs_permission, |
| 8597 | .getattr = nfs_getattr, |
| 8598 | .setattr = nfs_setattr, |
| 8599 | .getxattr = generic_getxattr, |
| 8600 | .setxattr = generic_setxattr, |
| 8601 | .listxattr = generic_listxattr, |
| 8602 | .removexattr = generic_removexattr, |
| 8603 | }; |
| 8604 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8605 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8606 | .permission = nfs_permission, |
| 8607 | .getattr = nfs_getattr, |
| 8608 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8609 | .getxattr = generic_getxattr, |
| 8610 | .setxattr = generic_setxattr, |
| 8611 | .listxattr = generic_listxattr, |
| 8612 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8613 | }; |
| 8614 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8615 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8616 | .version = 4, /* protocol version */ |
| 8617 | .dentry_ops = &nfs4_dentry_operations, |
| 8618 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8619 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8620 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8621 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8622 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8623 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8624 | .getattr = nfs4_proc_getattr, |
| 8625 | .setattr = nfs4_proc_setattr, |
| 8626 | .lookup = nfs4_proc_lookup, |
| 8627 | .access = nfs4_proc_access, |
| 8628 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8629 | .create = nfs4_proc_create, |
| 8630 | .remove = nfs4_proc_remove, |
| 8631 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8632 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8633 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8634 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8635 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8636 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8637 | .link = nfs4_proc_link, |
| 8638 | .symlink = nfs4_proc_symlink, |
| 8639 | .mkdir = nfs4_proc_mkdir, |
| 8640 | .rmdir = nfs4_proc_remove, |
| 8641 | .readdir = nfs4_proc_readdir, |
| 8642 | .mknod = nfs4_proc_mknod, |
| 8643 | .statfs = nfs4_proc_statfs, |
| 8644 | .fsinfo = nfs4_proc_fsinfo, |
| 8645 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8646 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8647 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8648 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8649 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8650 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8651 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8652 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8653 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8654 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8655 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8656 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8657 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8658 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8659 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8660 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8661 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8662 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8663 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8664 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8665 | .create_server = nfs4_create_server, |
| 8666 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8667 | }; |
| 8668 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8669 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 8670 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 8671 | .list = nfs4_xattr_list_nfs4_acl, |
| 8672 | .get = nfs4_xattr_get_nfs4_acl, |
| 8673 | .set = nfs4_xattr_set_nfs4_acl, |
| 8674 | }; |
| 8675 | |
| 8676 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8677 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8678 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8679 | &nfs4_xattr_nfs4_label_handler, |
| 8680 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8681 | NULL |
| 8682 | }; |
| 8683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8684 | /* |
| 8685 | * Local variables: |
| 8686 | * c-basic-offset: 8 |
| 8687 | * End: |
| 8688 | */ |